:root {
    --bg:           #09090b;
    --surface:      #18181b;
    --surface-2:    #27272a;
    --border:       #3f3f46;
    --text:         #fafafa;
    --text-muted:   #71717a;
    --accent:       #3b82f6;
    --accent-hover: #2563eb;
    --green:        #22c55e;
    --red:          #ef4444;
    --radius:       8px;
    --radius-sm:    5px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 15px; }
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Geist Mono", monospace;
    margin-bottom: 70px;
    -webkit-font-smoothing: antialiased;
}

/* ── NAVBAR META ─────────────────────────────────────────── */

.nav-meta-group {
    flex-direction: row;
    align-items: center;
    gap: 20px;
}
.nav-ip-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}
.nav-router-ip {
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.03em;
}
.nav-router-uptime {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}
.nav-meta-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.nav-router-uptime .uptime {
    display: inline;
    color: var(--text);
    font-size: 13px;
}

/* ── LAYOUT ──────────────────────────────────────────────── */

.flex-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
}

.flex-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
}

.flex-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    gap: 10px;
}

/* ── HEADINGS ────────────────────────────────────────────── */

h4 {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 2px 0;
}

/* ── DATA FIELDS ─────────────────────────────────────────── */

.data-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

div.data-field {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    overflow: hidden;
}

div.data-field-key {
    padding: 7px 10px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    min-width: 88px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
}

div.data-field-value {
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    line-height: 1.5;
}

/* Stacks repeated rows (e.g. PPPoE interfaces) vertically beside the key
   instead of letting them flow across the row and wrap on narrow screens. */
.data-field-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.data-field-list > .data-field-value + .data-field-value {
    border-top: 1px solid var(--border);
}

/* ── MONOSPACE ───────────────────────────────────────────── */

.monospace {
    font-family: "Geist Mono", monospace;
    font-optical-sizing: auto;
    font-style: normal;
}

/* ── UPTIME ──────────────────────────────────────────────── */

span.uptime {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.03em;
    margin: 0;
}

/* ── STATUS DOT ──────────────────────────────────────────── */

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    flex-shrink: 0;
}

.status-dot.offline {
    background: var(--red);
    box-shadow: 0 0 6px var(--red);
}

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

.ping-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 2px 5px;
    border-radius: 3px;
    border: 1px solid;
    flex-shrink: 0;
}
.ping-badge.online    { color: var(--green);      border-color: var(--green); }
.ping-badge.offline   { color: var(--red);        border-color: var(--red); }
.ping-badge.checking  { color: var(--text-muted); border-color: var(--border); }

/* ── CONTROLS ────────────────────────────────────────────── */

.controls {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ── BUTTONS ─────────────────────────────────────────────── */

.btn {
    font-family: "Geist Mono", monospace;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    border: 1px solid;
    line-height: 1.5;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--text-muted);
}

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

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

/* ── TOAST ───────────────────────────────────────────────── */

#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    font-size: 12px;
    font-family: "Geist Mono", monospace;
    color: var(--text);
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 9999;
    max-width: 320px;
    word-break: break-word;
}

#toast.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ── TABS ────────────────────────────────────────────────── */

.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}

.tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: "Geist Mono", monospace;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 8px 16px;
    cursor: pointer;
    margin-bottom: -1px;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: color 0.15s ease, border-color 0.15s ease;
}

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

.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 6px;
    min-width: 18px;
    line-height: 1.4;
}

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

.tab-maintenance { margin-left: auto; }

/* ── VPN ─────────────────────────────────────────────────── */

.vpn-list {
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* display:contents makes each row's children become direct grid items,
   so columns align across all rows without a wrapping element. */
.vpn-client { display: contents; }

.vpn-client > * {
    padding: 7px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vpn-client:nth-child(even) > * { background: var(--surface); }
.vpn-client:last-child       > * { border-bottom: none; }

.vpn-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid;
    flex-shrink: 0;
}

.vpn-badge.local { color: #22c55e; border-color: #22c55e; }
.vpn-badge.l2tp  { color: #f97316; border-color: #f97316; }
.vpn-badge.sstp  { color: #3b82f6; border-color: #3b82f6; }
.vpn-badge.ipsec { color: #a78bfa; border-color: #a78bfa; }
.vpn-badge.pptp  { color: #71717a; border-color: #71717a; }

.vpn-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex-shrink: 0;
}

.vpn-ips {
    font-size: 12px;
    color: var(--text-muted);
    flex: 1;
}

.vpn-arrow {
    color: var(--border);
    margin: 0 4px;
}

.vpn-empty {
    font-size: 12px;
    padding: 4px 0;
}

/* ── VPN COLLAPSIBLE SECTION ─────────────────────────────── */

.vpn-section { margin-top: 12px; }

.vpn-section-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: "Geist Mono", monospace;
    text-align: left;
}
.vpn-section-toggle:hover { color: var(--text); border-color: var(--text-muted); }

.vpn-section.open .vpn-section-toggle {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
}

.vpn-caret {
    font-size: 9px;
    line-height: 1;
    transition: transform 0.15s ease;
}
.vpn-section.open .vpn-caret { transform: rotate(90deg); }

.vpn-section-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.vpn-section-body .vpn-list {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.vpn-type-cell {
    justify-content: center;
    padding: 7px 10px;
}

.vpn-rate {
    display: flex;
    flex-direction: column;
    align-items: stretch;   /* both lines share the column width, so arrows line up */
    justify-content: center;
    gap: 1px;
    white-space: nowrap;
    min-width: 64px;
}

/* Arrow pinned left, value pushed right — vertically aligned across tx/rx. */
.vpn-rate-tx, .vpn-rate-rx {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-size: 11px;
}
.vpn-rate-tx { color: var(--green); }
.vpn-rate-rx { color: var(--accent); }

.vpn-rate-arrow { flex-shrink: 0; }

/* Number right-aligned against a fixed-width unit cell, so the
   B / KB / MB / GB suffixes start on the same column across rows. */
.vpn-rate-val {
    display: inline-flex;
    align-items: baseline;
    font-variant-numeric: tabular-nums;
}
.vpn-rate-num {
    text-align: right;
}
.vpn-rate-unit {
    width: 2ch;
    margin-left: 3px;
    text-align: left;
    flex-shrink: 0;
}

.vpn-client > .uptime {
    min-width: 100px;
    font-family: "Geist Mono", monospace;
    font-size: 11px;
    color: var(--text-muted);
    justify-content: flex-end;
}

/* ── ROUTES ──────────────────────────────────────────────── */

.route-table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.route-table {
    width: 100%;
    border-collapse: collapse;
}

.route-table td {
    padding: 7px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    font-size: 13px;
}

.route-table tr:last-child td { border-bottom: none; }

/* Stronger divider between gateway groups */
.route-group-start td { border-top: 2px solid var(--border); }

.route-gateway {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    border-right: 1px solid var(--border);
    white-space: nowrap;
    text-align: center;
    min-width: 0;
    width: 1px;        /* shrink-wrap to content */
    vertical-align: middle;
}

.route-via {
    display: block;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: none;
    color: var(--text-muted);
    margin-top: 2px;
}

.route-type-cell {
    text-align: center;
    width: 1px;       /* shrink-wrap to badge */
    white-space: nowrap;
}

.route-name {
    font-weight: 500;
    white-space: nowrap;
}

/* Absorbs the table's free width and right-aligns the chip, so it lands just
   before the action button while every chip shares the same right edge (aligned). */
.route-rule-cell {
    width: 100%;
    white-space: nowrap;
    text-align: right;
}

/* Chip marking a client whose route was altered by a mangle rule. */
.route-rule-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
    max-width: 220px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.08);
    border: 1px solid rgba(167, 139, 250, 0.4);
    border-radius: 3px;
    padding: 1px 6px;
}
.route-rule-chip svg { flex-shrink: 0; }
.route-rule-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-action-cell {
    text-align: center;
    width: 1px;        /* shrink-wrap to the button */
    white-space: nowrap;
}

.route-edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.route-edit-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--surface);
}
.route-edit-btn svg { display: block; }

/* ── MODAL ───────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 10000;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7);
    padding: 20px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.modal-client {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.modal-client-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.modal-client-ip {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.modal-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 -6px 0;
}

.modal-select {
    font-family: "Geist Mono", monospace;
    font-size: 13px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    cursor: pointer;
}
.modal-select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 2px;
}

.maint-row { justify-content: space-between; }

.maint-passcode {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.maint-code-input {
    flex: 1;
    max-width: 320px;
    font-family: "Geist Mono", monospace;
    font-size: 12px;
    letter-spacing: 0.15em;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
}
.maint-code-input:focus {
    outline: none;
    border-color: var(--accent);
}
.maint-code-input::placeholder {
    color: var(--text-muted);
    letter-spacing: normal;
}
.maint-lock {
    font-family: "Geist Mono", monospace;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 3px;
    border: 1px solid;
    flex-shrink: 0;
}
.maint-lock.locked   { color: var(--text-muted); border-color: var(--border); }
.maint-lock.unlocked { color: var(--green);      border-color: var(--green); }

.btn.maint-action:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.btn-danger.maint-action:disabled:hover  { background: transparent; color: var(--red); }
.btn-primary.maint-action:disabled:hover { background: transparent; color: var(--accent); }

.pppoe-disabled { opacity: 0.4; }
.pppoe-disabled-label { font-size: 11px; }

/* PPPoE interfaces rendered as an aligned column grid, like the VPN list.
   display:contents on each row promotes its cells to direct grid items so
   the dot / name / address / uptime / ping columns line up across rows. */
.data-field-key-standalone {
    border-right: none;
    padding: 0 2px 2px;
    min-width: 0;
}
.ppp-list {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.ppp-client { display: contents; }
.ppp-client > * {
    padding: 7px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ppp-client:nth-child(even) > * { background: var(--surface); }
.ppp-client:last-child       > * { border-bottom: none; }

.ppp-dot-cell { gap: 7px; }
.ppp-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    flex-shrink: 0;
}
.ppp-addr {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 0;
}
.ppp-client > .uptime {
    min-width: 100px;
    font-size: 11px;
    justify-content: flex-end;
}

/* ── TOPOLOGY ────────────────────────────────────────────── */

.topo-heading {
    margin-top: 16px;
}

.topo-wrap {
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 16px;
    overflow-x: auto;
}

#topo-svg svg { display: block; }

/* Higher specificity than `.route-table td` so the smaller font actually applies. */
.route-table td.route-ip {
    font-family: "Geist Mono", monospace;
    font-size: 11px;
    color: var(--text-muted);
    text-align: left;   /* sit right next to the client name */
    white-space: nowrap;
}

/* ── LOADING ─────────────────────────────────────────────── */

#loading {
    display: none;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 40px 0;
    text-align: center;
}

#loading.visible { display: block; }

/* ── FOOTER / LINKS ──────────────────────────────────────── */

div.footer {
    color: var(--text-muted);
    font-size: 10px;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}
