/* ============================================
   XML Creator - BillBlend Routing Tool
   ============================================ */

:root {
    --primary: #1a4a7a;
    --primary-dark: #123456;
    --success: #2f6b4f;
    --warning: #9a6b1f;
    --danger: #a33b3b;
    --info: #2a5f73;
    --secondary: #5c6570;
    --bg: #f3f4f6;
    --bg-white: #ffffff;
    --border: #dde1e6;
    --border-strong: #c4cad2;
    --text: #1c232b;
    --text-muted: #5c6570;
    --shadow-sm: none;
    --shadow: none;
    --shadow-md: 0 1px 2px rgba(28, 35, 43, 0.06);
    --radius: 3px;
    --radius-lg: 4px;
    --font: 'IBM Plex Sans', 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

code, pre, .mono {
    font-family: var(--font-mono);
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Navbar */
.navbar {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
}

.nav-brand {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
    color: var(--text);
    text-decoration: none;
}

.nav-brand:hover {
    color: var(--primary);
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 2px;
    align-items: center;
}

.nav-menu a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    padding: 8px 10px;
    border-radius: var(--radius);
}

.nav-menu a:hover {
    background: transparent;
    color: var(--text);
}

/* Dropdown menu */
.nav-dropdown {
    position: relative;
}

.nav-dropdown .dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 8px 0;
    min-width: 180px;
    list-style: none;
    margin: 4px 0 0 0;
    z-index: 1000;
}

.nav-dropdown:hover .dropdown-menu {
    display: block;
}

.nav-dropdown .dropdown-menu li {
    margin: 0;
}

.nav-dropdown .dropdown-menu a {
    display: block;
    padding: 8px 16px;
    border-radius: 0;
}

.nav-dropdown .dropdown-menu a:hover {
    background: var(--bg);
}

/* Main */
main {
    padding: 30px 0;
    min-height: calc(100vh - 150px);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    border-left: 4px solid;
    font-weight: 500;
}

.alert-success {
    background: #f0fdf4;
    border-color: var(--success);
    color: #166534;
}

.alert-error, .alert-danger {
    background: #fef2f2;
    border-color: var(--danger);
    color: #991b1b;
}

.alert-warning {
    background: #fffbeb;
    border-color: var(--warning);
    color: #92400e;
}

.alert-info {
    background: #ecfeff;
    border-color: var(--info);
    color: #0e7490;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    background: var(--bg-white);
    color: var(--text);
    border: 1px solid var(--border-strong);
    line-height: 1.35;
}

.btn:hover {
    background: var(--bg);
    transform: none;
    box-shadow: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-success:hover {
    background: #245540;
    color: white;
}

.btn-danger {
    background: var(--bg-white);
    color: var(--danger);
    border-color: var(--border-strong);
}

.btn-danger:hover {
    background: #faf2f2;
    border-color: var(--danger);
}

.btn-warning {
    background: var(--bg-white);
    color: var(--warning);
    border-color: var(--border-strong);
}

.btn-warning:hover {
    background: #faf6ef;
    border-color: var(--warning);
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-info {
    background: var(--bg-white);
    color: var(--info);
    border-color: var(--border-strong);
}

.btn-info:hover {
    background: #eef5f7;
    border-color: var(--info);
}

.btn-purple {
    background: var(--bg-white);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-purple:hover {
    background: var(--bg);
}

.btn-quiet {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn-quiet:hover {
    color: var(--text);
    background: var(--bg);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 11px;
}

/* Page header */
.page-header {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.page-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-header p {
    margin: 0;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.project-id {
    color: var(--text-muted);
    font-size: 14px;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

.stat-sub {
    color: var(--success);
    font-size: 12px;
    margin-top: 2px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin: 1px 2px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-primary { background: #dbeafe; color: var(--primary); }
.badge-success { background: #dcfce7; color: var(--success); }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-warning { background: #fef3c7; color: var(--warning); }
.badge-info { background: #cffafe; color: var(--info); }
.badge-secondary { background: #e2e8f0; color: var(--text-muted); }
.badge-value { background: #e9d5ff; color: #6b21a8; }
.badge-amount { background: #ccfbf1; color: #0f766e; }

/* Loyalty badges */
.badge-loyalty-new { background: #dbeafe; color: #1e40af; }
.badge-loyalty-ret { background: #f3e8ff; color: #7c3aed; }
.badge-loyalty-trust { background: #dcfce7; color: #166534; }
.badge-loyalty-notrust { background: #fee2e2; color: #991b1b; }
.badge-loyalty { background: #e2e8f0; color: #64748b; }

/* Loyalty section in balancing (hidden) */
.bnode-loyalty-section {
    padding: 6px 8px; background: #f0fdf4; border-bottom: 1px dashed var(--border);
}
.bnode-loyability-title {
    font-size: 11px; font-weight: 600; color: #166534; margin-bottom: 4px;
}
.bnode-loyalty-row {
    display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 11px;
}
.bnode-loyalty-name { font-weight: 500; }

/* Loyalty info box in balancing tab */
.loyalty-info-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
}

.mini-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    margin: 1px;
    background: #f1f5f9;
    color: var(--text-muted);
}

.mb-3d { background: #dcfce7; color: var(--success); }
.mb-no3d { background: #e2e8f0; color: var(--text-muted); }
.mb-rate { background: #fef3c7; color: var(--warning); }
.mb-direct { background: #cffafe; color: var(--info); }
.mb-on { background: #dcfce7; color: var(--success); }
.mb-off { background: #fee2e2; color: var(--danger); }
.mb-channel { background: #e0e7ff; color: #4338ca; }

/* Cards */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 16px;
}

.card-header {
    padding: 14px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    margin: 0;
    font-size: 16px;
}

.card-body {
    padding: 16px 20px;
}

.card-footer {
    padding: 12px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

/* Channel card specifics */
.channel-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px dashed var(--border);
}

.meta-row:last-child { border-bottom: none; }

.meta-label {
    color: var(--text-muted);
    font-size: 12px;
}

.meta-value {
    font-size: 13px;
}

/* Node cards (routing/balancing list) */
.node-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.node-card.root-node {
    border-color: var(--primary);
    border-width: 2px;
}

.node-card.node-disabled {
    opacity: 0.6;
}

.node-header {
    padding: 14px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.node-header h3 {
    margin: 0;
    font-size: 16px;
}

.node-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.meta-item {
    font-size: 12px;
    color: var(--text-muted);
}

.node-body {
    padding: 16px 20px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--bg);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table tr:hover {
    background: #f8fafc;
}

.data-table tr.row-disabled-tr {
    opacity: 0.5;
}

/* Forms */
.form-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.form-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px dashed var(--border);
}

.form-section:last-child {
    border-bottom: none;
}

.form-section h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    color: var(--text);
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    font-size: 13px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border 0.2s;
    background: var(--bg-white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Country grid */
.geo-paste-box {
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-white);
}
.geo-paste-box label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}
.geo-paste-box textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
}
.geo-paste-result {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}
.geo-paste-result.is-ok { color: #166534; }
.geo-paste-result.is-warn { color: #9a3412; }
.geo-paste-result.is-err { color: #991b1b; }

.country-search {
    margin-bottom: 12px;
}

.country-search input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 14px;
}

.country-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.selected-count {
    margin-left: auto;
    font-size: 13px;
    color: var(--text-muted);
}

.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
    max-height: 500px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

.country-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius);
    background: var(--bg-white);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

.country-checkbox-label:hover {
    border-color: var(--primary);
    background: #f0f9ff;
}

.country-checkbox-label.checked {
    background: #dbeafe;
    border-color: var(--primary);
}

.country-checkbox-label input[type="checkbox"] {
    margin: 0;
}

.country-code {
    font-weight: 700;
    font-family: monospace;
    color: var(--primary);
    font-size: 12px;
}

.country-name {
    color: var(--text);
}

.country-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.country-tag {
    display: inline-block;
    padding: 3px 8px;
    background: #dbeafe;
    color: var(--primary);
    border-radius: 3px;
    font-family: monospace;
    font-size: 12px;
    font-weight: 600;
}

/* Info box */
.info-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: 16px 20px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--border);
}

/* Filter info */
.filter-info {
    padding: 12px 16px;
    background: #fef3c7;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Tree visualization */
.tree-legend {
    background: var(--bg-white);
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-title {
    font-size: 16px;
    margin: 20px 0 12px;
    color: var(--text);
}

/* Tree toolbar + modes */
.tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.tree-mode-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-white);
}
.tree-mode-btn {
    border: 0;
    background: transparent;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}
.tree-mode-btn + .tree-mode-btn {
    border-left: 1px solid var(--border);
}
.tree-mode-btn:hover {
    background: var(--bg);
    color: var(--text);
}
.tree-mode-btn.active {
    background: #1e293b;
    color: #fff;
}
.tree-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tree-canvas {
    background: var(--bg-white);
    padding: 16px 18px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    max-width: 100%;
}

/* Shared tree chrome */
.rtree-node {
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    margin: 8px 0;
    background: var(--bg-white);
    word-wrap: break-word;
    min-width: 0;
}
.rtree-node.depth-0 { border-color: var(--primary); }
.rtree-node.depth-1 { border-color: #0d9488; }
.rtree-node.depth-2 { border-color: #9333ea; }
.rtree-node.depth-3 { border-color: #db2777; }
.rtree-node.depth-4,
.rtree-node.depth-5,
.rtree-node.depth-6,
.rtree-node.depth-7,
.rtree-node.depth-8,
.rtree-node.depth-9 { border-color: #ea580c; }
.rtree-node.rtree-root {
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.rtree-node.rtree-disabled { opacity: 0.6; }

.rtree-nodehead {
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.rtree-head-main {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}
.rtree-head-meta {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}
.rtree-depth {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    font-family: monospace;
    letter-spacing: 0.02em;
    color: #fff;
    background: #64748b;
}
.rtree-node.depth-0 > .rtree-nodehead .rtree-depth { background: #2563eb; }
.rtree-node.depth-1 > .rtree-nodehead .rtree-depth { background: #0d9488; }
.rtree-node.depth-2 > .rtree-nodehead .rtree-depth { background: #9333ea; }
.rtree-node.depth-3 > .rtree-nodehead .rtree-depth { background: #db2777; }
.rtree-node.depth-4 > .rtree-nodehead .rtree-depth,
.rtree-node.depth-5 > .rtree-nodehead .rtree-depth,
.rtree-node.depth-6 > .rtree-nodehead .rtree-depth { background: #ea580c; }
.rtree-icon { font-size: 15px; }
.rtree-id { font-weight: 700; font-family: monospace; font-size: 13px; }
.rtree-type { color: var(--text-muted); font-size: 12px; }

.rtree-routes {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.rtree-route {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius);
    border-left: 3px solid var(--border-strong);
    min-width: 0;
}
.rtree-route:hover {
    background: #f0f9ff;
    border-left-color: var(--primary);
}
.rtree-route.rtree-route-off {
    opacity: 0.55;
    background: #fef2f2;
}
.rtree-route-left { min-width: 0; }
.rtree-route-top {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.route-order {
    font-weight: 700;
    font-family: monospace;
    color: var(--primary);
    background: #dbeafe;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
}
.route-criteria {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    min-width: 0;
}
.rtree-route-arrow {
    flex: 0 0 auto;
    align-self: center;
    font-size: 16px;
    color: var(--text-muted);
    padding: 0 2px;
}
.rtree-route-target { min-width: 0; flex: 1 1 auto; }
.target-none {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 10px;
    font-size: 12px;
}
.target-none-icon { font-size: 16px; }
.rtree-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.bnode-block {
    border: 2px solid var(--success);
    border-radius: var(--radius);
    background: var(--bg-white);
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.bnode-block.bnode-disabled { opacity: 0.6; }
.bnode-block.bnode-compact { margin: 0; }
.bnode-header {
    padding: 6px 10px;
    background: #f0fdf4;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    border-radius: var(--radius) var(--radius) 0 0;
}
.bnode-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 13px;
    flex-wrap: wrap;
}
.bnode-type { font-size: 11px; color: var(--text-muted); }
.bnode-rows {
    padding: 6px;
    max-height: 400px;
    overflow: auto;
    flex: 1;
    min-width: 0;
}
.row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    margin: 2px 0;
    background: var(--bg);
    border-radius: var(--radius);
    border-left: 3px solid var(--success);
    font-size: 12px;
    min-width: 0;
}
.row-item.row-disabled {
    opacity: 0.5;
    border-left-color: var(--danger);
}
.row-main {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}
.row-pos {
    font-family: monospace;
    font-size: 10px;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.row-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(280px, 45vw);
}
.row-gate-id {
    font-family: monospace;
    font-size: 10px;
    color: var(--text-muted);
}
.row-meta {
    display: flex;
    gap: 3px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.row-weight {
    font-family: monospace;
    background: #fef3c7;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    color: var(--warning);
    font-weight: 600;
}
.row-actions { flex: 0 0 auto; }
.row-empty {
    padding: 10px;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
}

/* Pane visibility by mode */
.tree-diagram-pane { display: none; }
#tree-tab[data-tree-mode="classic"] .tree-classic-pane { display: block; }
#tree-tab[data-tree-mode="classic"] .tree-diagram-pane { display: none; }
#tree-tab[data-tree-mode="tree"] .tree-classic-pane,
#tree-tab[data-tree-mode="blocks"] .tree-classic-pane { display: none; }
#tree-tab[data-tree-mode="tree"] .tree-diagram-pane,
#tree-tab[data-tree-mode="blocks"] .tree-diagram-pane { display: block; }

/* Classic nested layout (старое) */
#tree-tab[data-tree-mode="classic"] .tree-canvas {
    overflow-x: auto;
    padding: 20px;
}
#tree-tab[data-tree-mode="classic"] .rtree-routes {
    overflow-x: auto;
    gap: 4px;
}
#tree-tab[data-tree-mode="classic"] .rtree-route {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
}
#tree-tab[data-tree-mode="classic"] .rtree-route-left {
    flex: 0 0 260px;
    min-width: 220px;
    max-width: 400px;
}
#tree-tab[data-tree-mode="classic"] .rtree-route-arrow { display: block; }
#tree-tab[data-tree-mode="classic"] .rtree-route-target {
    flex: 1 1 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
}
#tree-tab[data-tree-mode="classic"] .bnode-block {
    min-width: 340px;
    max-width: 100%;
}
#tree-tab[data-tree-mode="classic"] .row-item {
    flex-wrap: nowrap;
    white-space: nowrap;
    min-width: 320px;
}
#tree-tab[data-tree-mode="classic"] .row-main {
    flex-wrap: nowrap;
    overflow: hidden;
}
#tree-tab[data-tree-mode="classic"] .row-meta {
    flex-wrap: nowrap;
    flex-shrink: 0;
}

/* Logical diagram (Tree ↓ / Blocks →) */
.routing-diagram {
    overflow: auto;
    max-width: 100%;
    max-height: min(78vh, 920px);
    padding: 16px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-height: 200px;
    -webkit-overflow-scrolling: touch;
    position: relative;
}
.diag-node.is-stuck .diag-node-shape,
.diag-edge-label.is-stuck .diag-edge-bg {
    filter: drop-shadow(0 2px 5px rgba(15, 23, 42, 0.18));
}
.diag-svg {
    display: block;
    max-width: none;
    min-width: 100%;
}
.diag-link {
    stroke: #475569;
    stroke-width: 1.75;
}
.diag-link.is-off {
    stroke: #94a3b8;
    stroke-dasharray: 5 4;
}
.diag-arrow-head {
    fill: #475569;
}
.diag-edge-bg {
    fill: #ffffff;
    stroke: #cbd5e1;
    stroke-width: 1;
}
.diag-edge-text {
    font-size: 11px;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    fill: #1e293b;
    font-weight: 600;
}
.diag-edge-text.is-off { fill: #94a3b8; }
@media (max-width: 700px) {
    .routing-diagram {
        padding: 10px;
        max-height: min(70vh, 640px);
    }
    .diag-edge-text { font-size: 10px; }
    .diag-node-title { font-size: 11.5px; }
    .diag-gate-line { font-size: 10px; }
}

.diag-node-shape {
    stroke-width: 2;
    filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.06));
}
.diag-node.kind-routing .diag-node-shape {
    fill: #eff6ff;
    stroke: #2563eb;
}
.diag-node.kind-routing.is-root .diag-node-shape {
    fill: #dbeafe;
    stroke: #1d4ed8;
    stroke-width: 2.5;
}
.diag-node.kind-balancing .diag-node-shape {
    fill: #f0fdf4;
    stroke: #16a34a;
}
.diag-node.kind-empty .diag-node-shape {
    fill: #f8fafc;
    stroke: #94a3b8;
    stroke-dasharray: 4 3;
}
.diag-node.is-off {
    opacity: 0.55;
}
.diag-node-title {
    font-size: 12.5px;
    font-weight: 700;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    fill: #0f172a;
}
.diag-node-sub {
    font-size: 10px;
    font-family: ui-sans-serif, system-ui, sans-serif;
    fill: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.diag-gate-line {
    font-size: 11px;
    font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
    fill: #14532d;
    font-weight: 500;
}
.diag-gate-line.is-off {
    fill: #94a3b8;
}
.diag-gate-line.muted {
    fill: #94a3b8;
    font-style: italic;
}
.diag-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid;
    vertical-align: -1px;
}
.diag-swatch-rn { background: #eff6ff; border-color: #2563eb; }
.diag-swatch-bn { background: #f0fdf4; border-color: #16a34a; border-radius: 3px; }

/* Add form in balancing */
.bnode-add-form {
    padding: 8px 10px;
    background: #ecfeff;
    border-top: 1px dashed var(--border);
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.bnode-add-form select {
    flex: 1;
    min-width: 160px;
    padding: 5px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 12px;
}

.bnode-add-form input[type="number"] {
    padding: 5px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 12px;
}

.inline-form {
    display: flex;
    gap: 6px;
    align-items: center;
    flex: 1;
    flex-wrap: wrap;
}

.validation-hint {
    width: 100%;
    font-size: 11px;
    margin-top: 4px;
}

.validation-msg.info { color: var(--info); }
.validation-msg.warning { color: var(--warning); }
.validation-msg.error { color: var(--danger); }

/* Orphan balancing wrap */
.orphan-balancing-wrap {
    max-width: 100%;
    margin-bottom: 12px;
}

/* View page: шире контейнер, меньше пустоты */
.view-page .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}
.view-page .stat-card {
    padding: 12px 14px;
}
.view-page .tree-legend {
    gap: 10px;
    padding: 0;
    margin: 0;
}
.view-page .page-header {
    margin-bottom: 12px;
}
.view-page .page-header h1 {
    font-size: 22px;
    margin-bottom: 4px;
}
@media (max-width: 900px) {
    .view-page .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .row-item {
        grid-template-columns: 1fr;
    }
    .row-meta {
        justify-content: flex-start;
    }
}

/* View tabs: compact routing / balancing cards */
.view-tab-hint {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--text-muted);
}
.vcard {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}
.vcard-off {
    opacity: 0.55;
}
.vcard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.vcard-title {
    font-weight: 600;
    font-size: 14px;
}
.vcard-id {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 6px;
}
.vcard-meta {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.vcard-from {
    padding: 6px 12px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    line-height: 1.4;
}
.vcard-from.muted {
    font-style: italic;
}
.vtag {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.vtag-root {
    background: #dbeafe;
    color: #1d4ed8;
}
.vtag-off {
    background: #fee2e2;
    color: #b91c1c;
}
.vtag-3d {
    background: #e0e7ff;
    color: #4338ca;
}
.vrows {
    display: flex;
    flex-direction: column;
}
.vrow {
    display: grid;
    grid-template-columns: 28px minmax(100px, 1fr) 16px minmax(140px, 1.4fr);
    gap: 8px;
    align-items: baseline;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.vrow:last-child {
    border-bottom: none;
}
.vrow-off {
    opacity: 0.45;
}
.vrow-pos {
    color: var(--text-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.vrow-if {
    font-weight: 500;
    word-break: break-word;
}
.vrow-arrow {
    color: var(--text-muted);
    text-align: center;
}
.vrow-to {
    color: var(--text);
    min-width: 0;
}
.vrow-to strong {
    font-weight: 600;
}
.vrow-cascade {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.35;
}
.vcascade {
    list-style: none;
    margin: 0;
    padding: 0;
}
.vcascade li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.vcascade li:last-child {
    border-bottom: none;
}
.vcascade li.off {
    opacity: 0.45;
}
.vcascade-pos {
    flex: 0 0 22px;
    height: 22px;
    line-height: 22px;
    text-align: center;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.vcascade-name {
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.vcascade-id {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
@media (max-width: 700px) {
    .vrow {
        grid-template-columns: 24px 1fr;
        grid-template-rows: auto auto;
    }
    .vrow-arrow {
        display: none;
    }
    .vrow-to {
        grid-column: 2;
    }
}

/* Edit layout */
.edit-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 24px;
    align-items: start;
}

.edit-main {
    min-width: 0;
}

.edit-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 80px;
}

.sidebar-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    max-height: 600px;
    overflow-y: auto;
}

.sidebar-card h3 {
    margin: 0 0 10px 0;
    font-size: 15px;
}

.gates-list-small {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gate-item {
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 12px;
}

.gate-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.gate-item-meta {
    margin-top: 3px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.versions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.version-item {
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.version-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.version-comment {
    font-size: 11px;
    color: var(--text-muted);
    margin: 3px 0;
}

/* Validation panel */
.validation-panel {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 20px;
}

.validation-panel h3 {
    margin: 0 0 12px 0;
    font-size: 15px;
}

.validation-item {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 4px solid;
}

.validation-item.error {
    background: #fef2f2;
    border-color: var(--danger);
    color: #991b1b;
}

.validation-item.warning {
    background: #fffbeb;
    border-color: var(--warning);
    color: #92400e;
}

.validation-item.info {
    background: #ecfeff;
    border-color: var(--info);
    color: #0e7490;
}

/* Text helpers */
.text-muted {
    color: var(--text-muted);
}

/* Validation page */
.validation-channels {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.validate-channel-card .card-body h4 {
    font-size: 14px;
    color: var(--text);
    border-bottom: 1px dashed var(--border);
    padding-bottom: 6px;
}

.validate-channel-card .data-table {
    font-size: 12px;
}

.validate-channel-card .data-table th {
    font-size: 10px;
}

/* Footer */
.footer {
    padding: 16px 0;
    background: transparent;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

/* Responsive */
@media (max-width: 900px) {
    .edit-layout {
        grid-template-columns: 1fr;
    }

    .edit-sidebar {
        position: static;
    }

    .nav-menu {
        gap: 12px;
    }

    .nav-menu a {
        font-size: 13px;
        padding: 4px 6px;
    }
}

/* Upload page */
.upload-area {
    background: var(--bg-white);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 60px 40px;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.upload-area:hover {
    border-color: var(--primary);
}

.upload-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.upload-area h2 {
    margin: 0 0 8px 0;
}

.upload-area p {
    color: var(--text-muted);
    margin: 0 0 24px 0;
}

.upload-area input[type="file"] {
    margin-bottom: 16px;
}

/* === Transaction category badges (FTD/STD) === */
.tx-cat {
    display: inline-block; padding: 1px 6px; border-radius: 3px;
    font-size: 9px; font-weight: 700; letter-spacing: 0.3px;
    margin-left: 4px; vertical-align: middle; font-family: monospace;
}
.tx-cat-ftd { background: #dbeafe; color: #1e40af; }
.tx-cat-std { background: #f3e8ff; color: #7c3aed; }
.tx-cat-both { background: #e2e8f0; color: #64748b; }

/* === Balancing loyalty hint === */
.bn-loyalty-hint,
.bnode-loyalty-hint {
    display: inline-flex; gap: 2px; margin-left: 6px;
}

/* === Loyalty summary in routing node header === */
.loyalty-summary {
    display: inline-flex; gap: 3px; margin-left: 8px;
    padding: 2px 6px; border-radius: 4px;
    background: rgba(139, 92, 246, 0.08);
    font-size: 10px; font-weight: 600;
}
.loyalty-mini {
    display: inline-block; padding: 1px 5px; border-radius: 3px;
    font-size: 9px; font-weight: 700; letter-spacing: 0.3px;
    font-family: monospace;
}
.loyalty-mini-ftd { background: #dbeafe; color: #1e40af; }
.loyalty-mini-std { background: #f3e8ff; color: #7c3aed; }
.loyalty-mini-trust { background: #d1fae5; color: #065f46; }
.loyalty-mini-nottrust { background: #fee2e2; color: #991b1b; }
.loyalty-mini-others { background: #e2e8f0; color: #64748b; }

/* === Other criteria (not country/loyalty/card) === */
.route-other-criteria {
    display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px;
}
.other-criterion-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600;
    background: #fef3c7; color: #92400e;
    border: 1px solid #fbbf24;
}

/* === Transaction type badges (sale, payout, capture) === */
.tx-type-badge {
    display: inline-block; padding: 2px 8px; border-radius: 3px;
    font-size: 11px; font-weight: 600; background: #fef3c7; color: #92400e;
    letter-spacing: 0.3px;
}

/* === Edit page: loyalty badges === */
.loyalty-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600; margin: 1px 2px;
}
.loyalty-new { background: #dbeafe; color: #1e40af; }
.loyalty-returning { background: #f3e8ff; color: #7c3aed; }
.loyalty-trust { background: #dcfce7; color: #166534; }
.loyalty-notrust { background: #fee2e2; color: #991b1b; }
.loyalty-others { background: #e2e8f0; color: #64748b; }
.loyalty-other { background: #fef3c7; color: #92400e; }

/* === Card type badges === */
.card-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 700; margin: 1px 2px;
    background: #f1f5f9; color: #475569;
    font-family: monospace; letter-spacing: 0.5px;
}
.card-visa { background: #1a1f71; color: white; }
.card-mc { background: #eb001b; color: white; }

/* === Country badge (edit mode) === */
.c-badge {
    display: inline-block; padding: 2px 6px; border-radius: 3px;
    font-size: 11px; font-weight: 600; font-family: monospace;
    background: #dbeafe; color: #1e40af; margin: 1px;
}
.c-badge-editable {
    padding-right: 2px;
}
.c-badge-remove {
    display: inline-block; width: 16px; height: 16px;
    line-height: 14px; text-align: center;
    border: none; background: #ef4444; color: white;
    border-radius: 50%; cursor: pointer; font-size: 10px;
    margin-left: 3px; padding: 0;
    transition: background 0.2s;
}
.c-badge-remove:hover { background: #dc2626; }
.c-badge-unknown { background: #fee2e2; color: #991b1b; }

/* === Edit page: routing node styles === */
.rn {
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    margin: 8px 0;
    background: var(--bg-white);
}
.rn.rn-root { border-color: var(--primary); border-width: 3px; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2); }
.rn.rn-off { opacity: 0.6; }
.rn.depth-0 { border-color: var(--primary); }
.rn.depth-1 { border-color: #0d9488; }
.rn.depth-2 { border-color: #9333ea; }
.rn.depth-3 { border-color: #db2777; }
.rn.depth-4 { border-color: #ea580c; }
.rn.depth-5 { border-color: #0891b2; }
.rn.depth-6, .rn.depth-7, .rn.depth-8, .rn.depth-9 { border-color: #64748b; }

.rn-head {
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    cursor: pointer;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.rn-head-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.rn-head-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rn-icon { font-size: 16px; }
.rn-title { font-weight: 700; font-family: monospace; }
.rn-type { color: var(--text-muted); font-size: 12px; }
.rn-depth-badge {
    font-size: 10px; padding: 1px 6px; border-radius: 3px;
    background: #f1f5f9; color: #64748b; font-family: monospace;
}
.rn-stat { font-size: 11px; color: var(--text-muted); background: var(--bg); padding: 2px 8px; border-radius: 3px; }

.rn-body {
    padding: 10px;
    overflow-x: auto;
    min-width: 0;
}
.rn-empty { padding: 16px; text-align: center; color: var(--text-muted); font-style: italic; }

/* Edit page: route row */
.route-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px;
    margin: 4px 0;
    background: var(--bg);
    border-radius: var(--radius);
    border-left: 3px solid var(--border-strong);
    transition: all 0.2s;
    flex-wrap: nowrap;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.route-row:hover { background: #f0f9ff; border-left-color: var(--primary); }
.route-row.route-off { opacity: 0.55; background: #fef2f2; }

.route-left {
    flex: 0 1 240px;
    min-width: 160px;
    max-width: 320px;
    overflow-wrap: break-word;
    word-break: break-word;
}

.route-header {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.route-countries-wrap {
    margin: 4px 0;
}
.route-countries {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-bottom: 4px;
}

.route-loyalty {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin: 4px 0;
    align-items: center;
}
.loyalty-remove {
    display: inline-block; width: 16px; height: 16px;
    line-height: 14px; text-align: center;
    border: none; background: #ef4444; color: white;
    border-radius: 50%; cursor: pointer; font-size: 10px;
    padding: 0; margin-left: -2px;
}
.loyalty-remove:hover { background: #dc2626; }

.route-cards {
    display: flex; flex-wrap: wrap; gap: 3px; margin: 4px 0;
}
.route-tx-types {
    display: flex; flex-wrap: wrap; gap: 3px; margin: 4px 0;
}
.route-amount {
    font-size: 12px; color: var(--info); margin: 4px 0;
    background: #ccfbf1; padding: 2px 8px; border-radius: 3px;
    display: inline-block;
}
.route-empty-criteria {
    color: var(--text-muted); font-style: italic; font-size: 12px;
}

.route-arrow {
    flex: 0 0 auto;
    align-self: center;
    font-size: 18px;
    color: var(--text-muted);
    padding: 0 4px;
}

.route-target {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
}

/* Deep nesting: vertical stack inside nested routing nodes */
.route-target > .rn > .rn-body > .route-row,
.rn[data-depth]:not([data-depth="0"]) > .rn-body > .route-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}
.route-target > .rn > .rn-body > .route-row > .route-left,
.rn[data-depth]:not([data-depth="0"]) > .rn-body > .route-row > .route-left {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    width: 100%;
}
.route-target > .rn > .rn-body > .route-row > .route-arrow,
.rn[data-depth]:not([data-depth="0"]) > .rn-body > .route-row > .route-arrow {
    align-self: flex-start;
    transform: rotate(90deg);
    padding: 2px 0;
    margin-left: 4px;
}
.route-target > .rn > .rn-body > .route-row > .route-target,
.rn[data-depth]:not([data-depth="0"]) > .rn-body > .route-row > .route-target {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
}
.route-target > .rn {
    margin: 4px 0 4px 8px;
    border-width: 1.5px;
}
.route-target .bn,
.rn .bn {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
}

.target-empty {
    display: flex; align-items: center; gap: 6px;
    color: var(--text-muted); font-style: italic; padding: 8px;
}

/* Edit page: balancing node */
.bn {
    border: 2px solid var(--success);
    border-radius: var(--radius);
    background: var(--bg-white);
    min-width: 0;
    max-width: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
.bn.bn-off { opacity: 0.6; }
.bn.bn-compact { margin: 0; }

.bn-head {
    padding: 8px 12px;
    background: #f0fdf4;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
}
.bn-head-left { display: flex; align-items: center; gap: 6px; }
.bn-head-right { display: flex; gap: 6px; align-items: center; }
.bn-icon { font-size: 14px; }
.bn-title { font-weight: 600; font-size: 13px; }
.bn-type { font-size: 11px; color: var(--text-muted); }
.bn-stat { font-size: 11px; color: var(--text-muted); background: var(--bg); padding: 2px 6px; border-radius: 3px; }

.bn-body {
    padding: 6px;
    display: flex;
    flex-direction: column;
    max-height: 500px;
    overflow-y: auto;
    flex: 1;
}

.bn-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 400px;
    flex: 1;
    min-width: 0;
}

.gate-tbl {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.gate-tbl th {
    background: var(--bg);
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.gate-tbl td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.gate-tbl tr:hover { background: #f8fafc; }
.gate-tbl tr.gate-off { opacity: 0.5; }

.gt-col-name { min-width: 140px; }
.gt-col-channel { min-width: 120px; }
.gt-col-weight { width: 70px; }
.gt-col-tags { width: 120px; }
.gt-col-act { width: 40px; text-align: center; }

.gate-name { font-weight: 600; }
.gate-id { font-family: monospace; font-size: 10px; color: var(--text-muted); }
.gate-warn { color: var(--warning); font-size: 10px; }

.ch-name { font-size: 12px; }
.ch-geo { font-size: 10px; color: var(--text-muted); }

.weight-badge {
    display: inline-block; padding: 1px 6px; border-radius: 3px;
    font-size: 11px; font-weight: 600; font-family: monospace;
    background: #fef3c7; color: var(--warning);
}

.tags-row {
    display: flex; flex-wrap: wrap; gap: 2px;
}
.tag {
    display: inline-block; padding: 1px 5px; border-radius: 3px;
    font-size: 9px; font-weight: 600;
}
.tag-green { background: #dcfce7; color: #166534; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-gray { background: #e2e8f0; color: #64748b; }
.tag-amber { background: #fef3c7; color: #92400e; }
.tag-cyan { background: #cffafe; color: #0e7490; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-purple { background: #f3e8ff; color: #7c3aed; }

/* Add gate form in balancing */
.add-gate-row {
    display: flex; gap: 6px; align-items: center;
    padding: 8px; background: #ecfeff; border-top: 1px dashed var(--border);
    margin-top: 6px; border-radius: 0 0 var(--radius) var(--radius);
}
.add-label { font-size: 14px; }
.add-select {
    flex: 1; min-width: 140px; padding: 5px 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 12px;
}
.add-weight {
    width: 70px; padding: 5px 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 12px;
}

/* Button icon (delete) */
.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px;
    border: none; border-radius: 50%;
    cursor: pointer; font-size: 14px;
    background: #fee2e2; color: #991b1b;
    transition: all 0.2s;
}
.btn-icon:hover { background: #fecaca; transform: scale(1.1); }
.btn-icon-red { background: #fee2e2; color: #991b1b; }

.inline { display: inline; }

/* Toggle icon */
.toggle-icon {
    display: inline-block; width: 16px; text-align: center;
    font-size: 10px; color: var(--text-muted);
    transition: transform 0.2s;
}
.collapsed .toggle-icon { transform: rotate(-90deg); }
.collapsed .rn-body,
.collapsed .bn-body { display: none; }

/* Country picker inline */
.country-add-wrap { display: inline-block; margin-top: 4px; }

.country-picker-inline {
    display: flex; flex-direction: column;
    background: var(--bg-white);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 8px;
    margin-top: 6px;
    max-width: 320px;
    max-height: 350px;
    z-index: 50;
    position: relative;
}
.cp-inline-header {
    display: flex; gap: 6px; margin-bottom: 6px; align-items: center;
}
.cp-inline-search {
    flex: 1; padding: 5px 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 12px;
}
.cp-inline-list {
    max-height: 250px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 2px;
}
.cp-loading {
    text-align: center; padding: 8px; color: var(--text-muted);
    font-size: 12px;
}
.cp-item {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 8px; border-radius: var(--radius);
    cursor: pointer; transition: background 0.2s;
    font-size: 12px;
}
.cp-item:hover { background: #f0f9ff; }
.cp-item-code {
    font-weight: 700; font-family: monospace;
    color: var(--primary); font-size: 12px;
    min-width: 30px;
}
.cp-item-name {
    flex: 1; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; color: var(--text);
}
.cp-item-dup {
    font-size: 9px; color: var(--warning); font-weight: 600;
    white-space: nowrap;
}

/* Loyalty picker inline */
.loyalty-picker-inline {
    display: flex; flex-direction: column;
    background: var(--bg-white);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 8px;
    margin-top: 6px;
    max-width: 280px;
    z-index: 50;
    position: relative;
}
.lp-inline-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px;
}
.lp-title { font-size: 12px; font-weight: 600; }
.lp-inline-list {
    display: flex; flex-direction: column; gap: 2px;
}
.lp-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; border-radius: var(--radius);
    cursor: pointer; transition: all 0.2s;
    font-size: 12px;
}
.lp-item:hover { filter: brightness(0.95); }
.lp-item-code {
    font-weight: 700; font-family: monospace;
    min-width: 40px;
}
.lp-item-name { flex: 1; }

/* Orphan section */
.orphan-section {
    margin-top: 24px;
}
.orphan-section h3 {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 12px;
}
.orphan-wrap {
    max-width: 500px;
    margin-bottom: 12px;
}

/* Edit page toolbar */
.toolbar {
    display: flex; gap: 8px; margin-bottom: 12px; align-items: center;
}
.toolbar-search {
    flex: 1; padding: 8px 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 14px;
}

/* Stats row */
.stats-row {
    display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.stat-chip {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 20px;
    background: var(--bg-white); border: 1px solid var(--border);
    font-size: 13px;
}
.stat-chip-val { font-weight: 700; color: var(--primary); }
.stat-chip-lbl { color: var(--text-muted); }

/* Validation messages */
.val-panel {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 12px 16px;
    margin-bottom: 16px;
}
.val-item {
    padding: 6px 10px; margin: 3px 0; border-radius: var(--radius);
    font-size: 13px; border-left: 3px solid;
}
.val-error { background: #fef2f2; border-color: var(--danger); color: #991b1b; }
.val-warning { background: #fffbeb; border-color: var(--warning); color: #92400e; }
.val-info { background: #ecfeff; border-color: var(--info); color: #0e7490; }
.val-more { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-align: center; }

/* Edit page: sidebar */
.sb-card {
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 14px;
    box-shadow: var(--shadow-sm);
}
.sb-card h3 { margin: 0 0 10px 0; font-size: 14px; }
.sb-search {
    width: 100%; padding: 6px 10px; margin-bottom: 8px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 12px;
}
.sb-gates {
    max-height: 300px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 4px;
}
.sb-gate {
    padding: 6px 8px; background: var(--bg);
    border-radius: var(--radius); border: 1px solid var(--border);
    font-size: 11px;
}
.sb-gate-main { display: flex; justify-content: space-between; gap: 4px; }
.sb-gate-meta { display: flex; gap: 3px; margin-top: 2px; }
.mini-tag {
    display: inline-block; padding: 1px 4px; border-radius: 2px;
    font-size: 9px; font-weight: 600; background: #f1f5f9; color: var(--text-muted);
}
.mini-ch { background: #e0e7ff; color: #4338ca; }

.sb-versions {
    display: flex; flex-direction: column; gap: 6px;
    max-height: 300px; overflow-y: auto;
}
.sb-version { padding: 6px 8px; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border); }
.sb-ver-main { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.sb-ver-comment { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* Page header top */
.page-hdr { margin-bottom: 16px; }
.page-hdr-top {
    display: flex; justify-content: space-between;
    align-items: flex-start; gap: 16px; flex-wrap: wrap;
}
.page-hdr h1 { margin: 0; font-size: 24px; }
.hdr-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.muted { color: var(--text-muted); }

/* Modal overlay */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-box {
    background: var(--bg-white); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md); max-width: 700px; width: 100%;
    max-height: 80vh; display: flex; flex-direction: column;
}
.modal-box.modal-sm { max-width: 450px; }
.modal-hdr {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.modal-hdr h2 { margin: 0; font-size: 18px; }
.modal-close {
    background: none; border: none; font-size: 20px; cursor: pointer;
    color: var(--text-muted); padding: 4px 8px;
}
.modal-body {
    padding: 20px; overflow-y: auto; flex: 1;
}
.modal-ftr {
    padding: 12px 20px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end;
}
.modal-loading {
    display: flex; flex-direction: column; align-items: center;
    padding: 40px; gap: 12px;
}
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Analysis stats */
.analysis-stats {
    display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.an-stat {
    display: flex; flex-direction: column; align-items: center;
    padding: 8px 16px; border-radius: var(--radius);
    background: var(--bg); border: 1px solid var(--border);
    min-width: 80px;
}
.an-stat .val { font-size: 24px; font-weight: 700; color: var(--primary); }
.an-stat .lbl { font-size: 11px; color: var(--text-muted); }
.an-stat.err .val { color: var(--danger); }
.an-stat.warn .val { color: var(--warning); }

/* Optimization options */
.opt-section { margin: 16px 0; }
.opt-section h3 { font-size: 15px; margin-bottom: 10px; }
.opt-item {
    display: flex; gap: 10px; padding: 8px; margin: 4px 0;
    border-radius: var(--radius); background: var(--bg);
    border: 1px solid var(--border); align-items: flex-start;
}
.opt-item input[type="checkbox"] { margin-top: 2px; }
.opt-label { font-weight: 600; font-size: 13px; }
.opt-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Issue list */
.issue-list { display: flex; flex-direction: column; gap: 6px; }
.issue-item {
    padding: 8px 12px; border-radius: var(--radius);
    border-left: 3px solid; font-size: 12px;
}
.issue-error { background: #fef2f2; border-color: var(--danger); }
.issue-warning { background: #fffbeb; border-color: var(--warning); }
.issue-info { background: #ecfeff; border-color: var(--info); }

/* Button group */
.btn-group { display: flex; gap: 8px; margin-top: 12px; }

.btn-purple { background: var(--bg-white); color: var(--text); border-color: var(--border-strong); }
.btn-purple:hover { background: var(--bg); }

/* Branch dialog */
.branch-countries-input {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    font-size: 14px; margin-top: 8px;
}

/* Country picker in branch dialog */
#country-picker {
    max-height: 300px; overflow-y: auto;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 4px; margin-top: 12px; padding: 8px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg);
}
#country-picker .cp-item {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 8px; border-radius: var(--radius);
    background: var(--bg-white); border: 1px solid var(--border);
    font-size: 12px; cursor: pointer;
}
#country-picker .cp-item:hover { border-color: var(--primary); }
#country-picker .cp-item input { margin: 0; }

/* ============================================================ */
/* Weight column (ISSUE-002)                                      */
/* ============================================================ */
.gt-col-weight { width: 110px; text-align: center; }
.weight-input {
    width: 80px; padding: 4px 6px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-white); color: var(--text);
    font-size: 13px; text-align: right;
    font-family: 'SF Mono', 'Consolas', monospace;
    transition: border-color 0.2s;
}
.weight-input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.weight-input:hover {
    border-color: var(--border-strong);
}
.weight-pct {
    font-size: 11px; color: var(--text-muted);
    margin-top: 2px;
    font-family: 'SF Mono', 'Consolas', monospace;
}

.rate-tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding-right: 4px;
}
.rate-input {
    width: 64px; border: 1px solid transparent; background: transparent;
    font: inherit; color: inherit; padding: 1px 4px; border-radius: 3px;
}
.rate-input:hover, .rate-input:focus {
    border-color: var(--border-strong); background: var(--bg-white);
    outline: none;
}
.dialog-form .btn-group {
    display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px;
}

/* ============================================================ */
/* Floating Action Button (ISSUE-003)                            */
/* ============================================================ */
.fab-container {
    position: fixed; bottom: 24px; right: 24px;
    z-index: 9500;
    display: flex; flex-direction: column-reverse;
    align-items: center; gap: 12px;
}
.fab-btn {
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    box-shadow: none;
    transition: background 0.12s;
    font-size: 14px;
    font-family: inherit;
}
.fab-btn:hover {
    box-shadow: none;
    transform: none;
    background: var(--bg);
}
.fab-btn-primary {
    width: 48px; height: 48px;
    background: var(--primary); color: white;
    border-color: var(--primary);
    border-radius: var(--radius);
}
.fab-btn-primary:hover { background: var(--primary-dark); }
.fab-btn-primary .fab-icon {
    font-size: 24px; font-weight: 400;
    transition: transform 0.2s;
    line-height: 1;
}
.fab-btn-small {
    width: auto; min-width: 44px; height: 36px; padding: 0 10px;
    background: var(--bg-white); color: var(--text);
    border: 1px solid var(--border-strong);
    font-size: 12px;
    position: relative; gap: 6px;
}
.fab-btn-small:hover { background: var(--bg); }
.fab-btn-small .fab-label {
    position: static;
    background: transparent; color: inherit;
    white-space: nowrap; font-size: 12px;
}
.fab-menu {
    display: flex; flex-direction: column-reverse;
    gap: 8px; align-items: flex-end;
}

/* Dialog form */
.dialog-form {
    padding: 24px; min-width: 300px;
}
.dialog-form h3 {
    margin: 0 0 16px; font-size: 18px;
}
.dialog-form label {
    display: block; font-size: 13px;
    color: var(--text-muted); margin-bottom: 4px;
}

/* Auth */
.login-page {
    display: flex;
    justify-content: center;
    padding: 3rem 0 4rem;
}
.login-card {
    max-width: 420px;
    width: 100%;
    text-align: center;
}
.login-card h1 {
    margin: 0 0 0.5rem;
}
.login-lead {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
    line-height: 1.45;
}
.login-widget {
    display: flex;
    justify-content: center;
    min-height: 44px;
}
.login-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
.btn-telegram {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    text-decoration: none;
}
.login-widget-fallback {
    margin-top: 1.25rem;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.login-widget-fallback summary {
    cursor: pointer;
    text-align: center;
    margin-bottom: 0.75rem;
}
.nav-user {
    margin-left: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.nav-user-name {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

