/* ============================================================
   GPIC — shared stylesheet for all pages
   Layout is chosen per page with a body class:
     <body class="app-sidebar">  → config.html, dashboard.html (left nav rail)
     <body class="app-page">      → all header-style pages
   ============================================================ */

:root {
    --bg: #eef2f8;
    --rail: #0f1f3d;
    --surface: #ffffff;
    --surface-2: #f5f8fd;
    --surface-3: #eaf1fb;
    --border: #e3e9f2;
    --border-strong: #d3ddec;
    --ink: #0f2039;
    --ink-2: #526484;
    --ink-3: #8ea0bd;
    --brand: #1e63d6;
    --brand-600: #164fb0;
    --brand-tint: #1e63d614;
    --brand-grad: linear-gradient(135deg,#2f7bff,#164fb0);
    --blue: #2f6bff;
    --amber: #c2740a;
    --amber-tint: #c2740a14;
    --green: #0f9d58;
    --green-tint: #0f9d5814;
    --red: #e5484d;
    --red-tint: #e5484d14;
    --r: 12px;
    --f-ui: 'Inter',system-ui,sans-serif;
    --f-mono: 'JetBrains Mono','SF Mono',monospace;
    --shadow: 0 1px 2px #0f20390a,0 4px 16px #0f203908;
    --rail-ink: #eaf1fb;
    --rail-ink-2: #a9bcdd;
    --rail-ink-3: #6f83a8;
    --rail-border: #1c3157;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
}

body {
    font-family: var(--f-ui);
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ---- Layout variants ---- */
body.app-sidebar {
    display: grid;
    grid-template-columns: 248px 1fr;
}

body.app-page {
    padding: 26px 34px 48px;
}

    body.app-page.center {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

.wrap {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* 2-column page body: main content + right info panel */
.page-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: start;
}

@media (max-width:1024px) {
    .page-grid {
        grid-template-columns: 1fr;
    }
}

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

.side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 20px;
}

.side-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    overflow: hidden;
}

    .side-card .sc-head {
        display: flex;
        align-items: center;
        gap: 9px;
        padding: 13px 16px;
        border-bottom: 1px solid var(--border);
        background: linear-gradient(180deg,var(--brand-tint),transparent);
        font-size: 12.5px;
        font-weight: 700;
        letter-spacing: -.01em;
    }

        .side-card .sc-head .ic {
            width: 22px;
            height: 22px;
            border-radius: 6px;
            background: var(--brand-grad);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
        }

    .side-card .sc-body {
        padding: 14px 16px;
    }

.side-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

    .side-stat:last-child {
        border-bottom: none;
    }

    .side-stat .k {
        font-size: 12px;
        color: var(--ink-2);
    }

    .side-stat .v {
        font-family: var(--f-mono);
        font-size: 13px;
        font-weight: 600;
        color: var(--ink);
    }

        .side-stat .v.ok {
            color: var(--green);
        }

        .side-stat .v.brand {
            color: var(--brand-600);
        }

.side-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

    .side-pill .d {
        width: 7px;
        height: 7px;
        border-radius: 50%;
    }

    .side-pill.online {
        background: var(--green-tint);
        color: var(--green);
    }

        .side-pill.online .d {
            background: var(--green);
            animation: pulse 2s infinite;
        }

.side-note {
    font-size: 11.5px;
    color: var(--ink-3);
    line-height: 1.5;
    margin-top: 4px;
}

.wrap.narrow {
    max-width: 960px;
}

.wrap.wide {
    max-width: 1680px;
}

::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 5px;
}

/* ============================================================
   Sidebar (app-sidebar layout)
   ============================================================ */
.rail {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--rail);
    border-right: 1px solid var(--rail-border);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    overflow-y: auto;
}

.rail-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 20px;
    border-bottom: 1px solid var(--rail-border);
    margin-bottom: 16px;
}

    .rail-brand .bt {
        text-align: center;
    }

    .rail-brand .t {
        font-size: 16px;
        font-weight: 800;
        letter-spacing: -.01em;
        line-height: 1.1;
        color: var(--rail-ink);
    }

    .rail-brand .s {
        font-family: var(--f-mono);
        font-size: 10px;
        letter-spacing: .12em;
        color: var(--rail-ink-3);
        text-transform: uppercase;
        margin-top: 3px;
    }

.nav-label {
    font-family: var(--f-mono);
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--rail-ink-3);
    padding: 0 10px;
    margin: 14px 0 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--rail-ink-2);
    cursor: pointer;
    transition: .14s;
}

    .nav-link .dot {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--rail-ink-3);
        flex: 0 0 auto;
        transition: .14s;
    }

    .nav-link:hover {
        background: #ffffff12;
        color: var(--rail-ink);
    }

    .nav-link.active {
        background: var(--brand-grad);
        color: #fff;
        font-weight: 600;
        box-shadow: 0 4px 12px #164fb040;
    }

        .nav-link.active .dot {
            background: #fff;
        }

.rail-status {
    margin-top: auto;
    padding: 12px;
    background: #ffffff10;
    border: 1px solid var(--rail-border);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--rail-ink);
}

    .rail-status .sub {
        font-family: var(--f-mono);
        font-size: 10.5px;
        color: var(--rail-ink-3);
        margin-top: 2px;
    }

/* ---- Sidebar logo frame (large) ---- */
.rail .logo-frame {
    width: 100%;
    max-width: 180px;
    height: auto;
    min-height: 70px;
    border-radius: 16px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px;
    position: relative;
    box-shadow: 0 8px 24px #00000030, inset 0 0 0 1px #ffffff40;
}

    .rail .logo-frame::after {
        content: "";
        position: absolute;
        inset: -2px;
        border-radius: 18px;
        background: var(--brand-grad);
        z-index: -1;
        opacity: .9;
    }

    .rail .logo-frame img {
        max-width: 100%;
        max-height: 80px;
        object-fit: contain;
        display: block;
    }

.rail .logo-fallback {
    font-family: var(--f-ui);
    font-weight: 800;
    font-size: 24px;
    color: var(--brand);
    letter-spacing: -.02em;
}

/* ============================================================
   Main content (app-sidebar)
   ============================================================ */
.main {
    padding: 26px 40px 60px;
    width: 100%;
    max-width: 1680px;
}

.topline {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

    .topline h1 {
        font-size: 23px;
        font-weight: 800;
        letter-spacing: -.02em;
        margin: 0;
        background: var(--brand-grad);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    .topline p {
        margin: 5px 0 0;
        font-size: 13px;
        color: var(--ink-2);
    }

/* ============================================================
   Header bar (app-page layout)
   ============================================================ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

    .brand .t {
        font-size: 18px;
        font-weight: 700;
        letter-spacing: -.02em;
        line-height: 1.1;
    }

    .brand .s {
        font-family: var(--f-mono);
        font-size: 10px;
        letter-spacing: .12em;
        color: var(--ink-3);
        text-transform: uppercase;
        margin-top: 3px;
    }

.top-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ---- Header logo frame (compact, landscape) ---- */
.brand .logo-frame {
    width: auto;
    height: 48px;
    max-width: 150px;
    border-radius: 12px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    position: relative;
    box-shadow: 0 4px 14px #0f203922;
}

    .brand .logo-frame::after {
        content: "";
        position: absolute;
        inset: -2px;
        border-radius: 14px;
        background: var(--brand-grad);
        z-index: -1;
        opacity: .9;
    }

    .brand .logo-frame img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
        display: block;
    }

.brand .logo-fallback {
    font-family: var(--f-ui);
    font-weight: 800;
    font-size: 15px;
    color: var(--brand);
    letter-spacing: -.02em;
}

/* ============================================================
   Connection pill + LED
   ============================================================ */
.conn {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 12.5px;
    font-weight: 500;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: 8px 14px;
    box-shadow: var(--shadow);
}

.led {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ink-3);
    flex: 0 0 auto;
}

    .led.ok {
        background: var(--green);
        box-shadow: 0 0 0 3px #0f9d5822;
        animation: pulse 2s infinite;
    }

    .led.bad {
        background: var(--red);
        box-shadow: 0 0 0 3px var(--red-tint);
    }

    .led.busy {
        background: var(--amber);
        box-shadow: 0 0 0 3px var(--amber-tint);
        animation: pulse 1s infinite;
    }

@keyframes pulse {
    0%,100% {
        opacity: 1;
    }

    50% {
        opacity: .4;
    }
}

/* ============================================================
   Buttons
   ============================================================ */
.home-btn {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--brand-grad);
    border: none;
    border-radius: 9px;
    padding: 10px 18px;
    cursor: pointer;
    box-shadow: 0 4px 12px #164fb033;
}

    .home-btn:hover {
        filter: brightness(1.06);
    }

    .home-btn.ghost {
        background: var(--surface);
        color: var(--ink-2);
        border: 1px solid var(--border-strong);
        box-shadow: var(--shadow);
    }

        .home-btn.ghost:hover {
            color: var(--ink);
            border-color: var(--brand);
            filter: none;
        }

.refresh-btn {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--brand-grad);
    border: none;
    border-radius: 9px;
    padding: 10px 18px;
    cursor: pointer;
    box-shadow: 0 4px 12px #164fb033;
}

    .refresh-btn:hover {
        filter: brightness(1.06);
    }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-bottom: 16px;
}

    .toolbar button {
        font-family: var(--f-ui);
        font-size: 13px;
        font-weight: 500;
        color: var(--ink);
        background: var(--surface);
        border: 1px solid var(--border-strong);
        border-radius: 9px;
        padding: 9px 15px;
        cursor: pointer;
        transition: .14s;
        box-shadow: var(--shadow);
    }

        .toolbar button:hover {
            border-color: var(--brand);
            color: var(--brand-600);
            background: var(--brand-tint);
        }

        .toolbar button.warn:hover {
            border-color: var(--amber);
            color: var(--amber);
            background: var(--amber-tint);
        }

.btn {
    font-family: var(--f-ui);
    font-size: 13px;
    font-weight: 600;
    border-radius: 9px;
    padding: 9px 16px;
    cursor: pointer;
    transition: .14s;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--brand-600);
}

    .btn:hover {
        border-color: var(--brand);
        background: var(--brand-tint);
    }

    .btn.danger {
        color: var(--red);
    }

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

    .btn.auto-on {
        background: var(--red-tint);
        border-color: var(--red);
        color: var(--red);
    }

.btn-primary {
    font-family: var(--f-ui);
    font-size: 14px;
    font-weight: 600;
    background: var(--brand-grad);
    color: #fff;
    border: none;
    border-radius: 9px;
    padding: 13px;
    cursor: pointer;
    transition: .14s;
}

    .btn-primary:hover {
        filter: brightness(1.06);
    }

    .btn-primary:disabled {
        background: var(--ink-3);
        cursor: not-allowed;
    }

.btn-ghost {
    font-family: var(--f-ui);
    font-size: 13px;
    font-weight: 600;
    background: var(--surface);
    color: var(--brand-600);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 9px 16px;
    cursor: pointer;
}

    .btn-ghost:hover {
        border-color: var(--brand);
        background: var(--brand-tint);
    }

/* ============================================================
   Persistent page tabs — underline strip (navigation)
   ============================================================ */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

.pagetabs {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    margin: 0;
}

    .pagetabs .tab {
        position: relative;
        font-family: var(--f-ui);
        font-size: 13.5px;
        font-weight: 600;
        color: var(--ink-3);
        text-decoration: none;
        padding: 12px 14px 14px;
        white-space: nowrap;
        transition: .14s;
        line-height: 1;
        border-bottom: 2px solid transparent;
        margin-bottom: -1px;
    }

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

        .pagetabs .tab.active {
            color: var(--brand-600);
            border-bottom-color: var(--brand);
            background: transparent;
            box-shadow: none;
        }

@media (max-width:900px) {
    .navbar {
        flex-direction: column;
        align-items: stretch;
    }

    .pagetabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}

/* action buttons that share the navbar row */
.navbar .toolbar {
    margin: 0;
    padding: 6px 0;
    gap: 8px;
}

    .navbar .toolbar button {
        padding: 8px 13px;
        font-size: 12.5px;
    }

/* ============================================================
   Status line
   ============================================================ */
#status {
    font-family: var(--f-mono);
    font-size: 12.5px;
    color: var(--brand-600);
    min-height: 18px;
    margin-bottom: 20px;
    padding-left: 2px;
}

    #status.err {
        color: var(--red);
    }

    #status.warn {
        color: var(--amber);
    }

    #status.muted {
        color: var(--ink-3);
    }

/* ============================================================
   Panels
   ============================================================ */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    margin-bottom: 18px;
    overflow: hidden;
    box-shadow: var(--shadow);
    scroll-margin-top: 20px;
}

.panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg,var(--brand-tint),transparent);
}

    .panel-head.split {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .panel-head .left {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .panel-head .idx {
        font-family: var(--f-mono);
        font-size: 12px;
        font-weight: 700;
        color: #fff;
        background: var(--brand-grad);
        border-radius: 6px;
        padding: 3px 9px;
    }

    .panel-head h1 {
        font-size: 14.5px;
        margin: 0;
        font-weight: 700;
        letter-spacing: -.01em;
    }

    .panel-head h2 {
        font-size: 14px;
        margin: 0;
        font-weight: 600;
        letter-spacing: -.01em;
    }

.panel-body {
    padding: 18px 20px;
}

.panel-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-family: var(--f-mono);
    font-size: 12px;
    color: var(--ink-2);
}

    .panel-foot .status {
        color: var(--brand-600);
    }

        .panel-foot .status.err {
            color: var(--red);
        }

        .panel-foot .status.warn {
            color: var(--amber);
        }

.count-badge {
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-2);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 10px;
}

/* ============================================================
   Tables
   ============================================================ */
table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

thead th {
    text-align: left;
    font-family: var(--f-mono);
    font-size: 10px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ink-3);
    font-weight: 600;
    padding: 11px 14px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0 14px;
    height: 52px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--surface-2);
}

tbody tr.sel {
    background: var(--brand-tint);
}

td.center, th.center {
    text-align: center;
}

.sno {
    font-family: var(--f-mono);
    color: var(--ink-3);
    text-align: center;
    font-weight: 500;
}

.svc-name {
    font-weight: 500;
}

.muted {
    color: var(--ink-3);
}

.code-cell {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
}

.codeBox {
    font-family: var(--f-mono);
    font-size: 12.5px;
    letter-spacing: .05em;
    padding: 5px 11px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    color: var(--brand-600);
    cursor: pointer;
    min-width: 66px;
    text-align: center;
}

    .codeBox:hover {
        border-color: var(--brand);
    }

.print-icon {
    cursor: pointer;
    font-size: 15px;
    opacity: .7;
}

    .print-icon:hover {
        opacity: 1;
    }

.showCodesBtn {
    font-family: var(--f-ui);
    font-size: 12px;
    font-weight: 600;
    background: transparent;
    color: var(--brand-600);
    border: 1px solid var(--border-strong);
    padding: 6px 13px;
    border-radius: 7px;
    cursor: pointer;
}

    .showCodesBtn:hover {
        background: var(--brand-tint);
        border-color: var(--brand);
    }

.col-sel {
    width: 64px;
    text-align: center;
}

.col-id {
    width: 100px;
    font-family: var(--f-mono);
    color: var(--ink-2);
}

.col-amt {
    width: 130px;
    font-family: var(--f-mono);
}

.table-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.empty {
    text-align: center;
    color: var(--ink-3);
    padding: 44px 20px;
    font-size: 13.5px;
}

    .empty .ic {
        font-size: 26px;
        margin-bottom: 8px;
    }

input[type=checkbox] {
    width: 17px;
    height: 17px;
    accent-color: var(--brand);
    cursor: pointer;
    vertical-align: middle;
}

/* skeleton shimmer (services loading state) */
.sk {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg,var(--surface-3) 25%,#e3e9f2 37%,var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
    0% {
        background-position: 100% 0;
    }

    100% {
        background-position: -100% 0;
    }
}

/* ============================================================
   Config grid + fields
   ============================================================ */
.config-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 18px 26px;
}

@media (max-width:1300px) {
    .config-grid {
        grid-template-columns: repeat(2,1fr);
    }
}

@media (max-width:820px) {
    .config-grid {
        grid-template-columns: 1fr;
    }
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

    .field.span-2 {
        grid-column: span 2;
    }

@media (max-width:820px) {
    .field.span-2 {
        grid-column: 1;
    }
}

.field label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    letter-spacing: .01em;
}

.field-row {
    display: flex;
    gap: 9px;
    align-items: center;
}

.field.mode-row {
    flex-direction: row;
    align-items: center;
    gap: 14px;
}

    .field.mode-row > label {
        flex: 0 0 190px;
        margin: 0;
    }

    .field.mode-row > .field-row {
        flex: 1;
        min-width: 0;
    }

@media (max-width:560px) {
    .field.mode-row {
        flex-direction: column;
        align-items: stretch;
        gap: 7px;
    }

        .field.mode-row > label {
            flex: none;
        }
}

input[type="text"], select {
    flex: 1;
    min-width: 0;
    font-family: var(--f-mono);
    font-size: 13px;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 10px 12px;
    outline: none;
    transition: .14s;
}

    input[type="text"]:focus, select:focus {
        background: #fff;
        border-color: var(--brand);
        box-shadow: 0 0 0 3px var(--brand-tint);
    }

input[readonly] {
    color: var(--ink-2);
    background: var(--surface-3);
    cursor: default;
}

select {
    cursor: pointer;
}

.field-row button {
    font-family: var(--f-ui);
    font-size: 12.5px;
    font-weight: 600;
    color: #fff;
    background: var(--brand-grad);
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    cursor: pointer;
    flex-shrink: 0;
}

    .field-row button:hover {
        filter: brightness(1.06);
    }

    .field-row button:disabled {
        display: none;
    }

.mini-label {
    font-size: 12px;
    color: var(--ink-2);
    white-space: nowrap;
    flex: 0 0 auto;
}

.mini-input {
    flex: 0 0 46px;
    min-width: 0;
    text-align: center;
    padding: 8px 4px;
    font-size: 12px;
}

/* toggle + segmented control */
.toggle-btn {
    font-family: var(--f-ui);
    font-size: 12.5px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
    min-width: 170px;
    color: #fff;
    transition: .14s;
    flex: 0 0 auto;
}

.toggle-status {
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-3);
}

.seg {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 4px;
    border-radius: 10px;
    background: #e7edf6;
    border: 1px solid var(--border-strong);
    flex: 1;
    min-width: 200px;
    max-width: 280px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px #0f203914;
}

.seg-thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 6px);
    height: calc(100% - 8px);
    background: var(--brand-grad);
    border-radius: 7px;
    transition: transform .25s ease;
    box-shadow: 0 2px 6px #164fb055;
}

.seg[data-value="2"] .seg-thumb {
    transform: translateX(calc(100% + 4px));
}

.seg .seg-option {
    position: relative;
    z-index: 1;
    flex: 1;
    padding: 9px 12px;
    border: none;
    background: transparent;
    box-shadow: none;
    color: #7c8aa3;
    font-family: var(--f-ui);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: color .2s ease;
    text-align: center;
}

    .seg .seg-option:hover:not(.active) {
        color: var(--ink);
        background: transparent;
    }

    .seg .seg-option.active {
        color: #fff;
        background: transparent;
    }

.footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 11px;
}

    .footer-actions button {
        font-family: var(--f-ui);
        font-size: 13px;
        font-weight: 500;
        color: var(--ink);
        background: var(--surface-2);
        border: 1px solid var(--border-strong);
        border-radius: 9px;
        padding: 11px 18px;
        cursor: pointer;
    }

        .footer-actions button:hover {
            border-color: var(--brand);
            color: var(--brand-600);
        }

/* ============================================================
   Stat cards (rs232, todaySum, logs, allCodes)
   ============================================================ */
.stats {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 14px;
    margin-bottom: 18px;
}

@media (max-width:560px) {
    .stats {
        grid-template-columns: 1fr;
    }
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 14px 18px;
    box-shadow: var(--shadow);
}

    .stat .k {
        font-family: var(--f-mono);
        font-size: 10px;
        letter-spacing: .12em;
        text-transform: uppercase;
        color: var(--ink-3);
        margin-bottom: 6px;
    }

    .stat .v {
        font-size: 20px;
        font-weight: 700;
        letter-spacing: -.01em;
        font-family: var(--f-mono);
        color: var(--brand-600);
    }

    .stat.accent .v {
        color: var(--brand-600);
    }

/* ============================================================
   Terminal / console (rs232History) — full-height flex layout
   ============================================================ */
#controls {
    display: flex;
    gap: 9px;
    flex-wrap: wrap;
}

/* This page fills the viewport: no page scroll, the console scrolls instead. */
body.app-terminal {
    height: 100%;
    overflow: hidden;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
}

    body.app-terminal .wrap {
        max-width: 100%;
        margin: 0 auto;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
        width: 100%;
    }

    body.app-terminal .topbar {
        margin-bottom: 12px;
        flex: 0 0 auto;
    }

    body.app-terminal .navbar {
        flex: 0 0 auto;
        margin-bottom: 12px;
    }

    body.app-terminal .top-right {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    body.app-terminal .panel {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

.term-wrap {
    padding: 14px 16px 16px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#status {
    font-family: var(--f-mono);
    font-size: 11.5px;
    color: var(--ink-3);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 6px;
    flex: 0 0 auto;
}

    #status .tag {
        padding: 2px 7px;
        border-radius: 5px;
        background: var(--surface-3);
        color: var(--ink-2);
        white-space: nowrap;
    }

    #status.err .tag {
        background: var(--red-tint);
        color: var(--red);
    }

#statusDynamic {
    display: contents;
}

.tag.fw, .tag.baud {
    color: var(--brand-600);
    font-weight: 600;
}

.tag.filtered-tx, .tag.filtered-rx {
    color: var(--amber);
}

#historyBox {
    display: block;
    width: 100%;
    flex: 1 1 auto;
    min-height: 160px;
    padding: 14px 16px;
    font-family: var(--f-mono);
    font-size: 12.5px;
    line-height: 1.55;
    color: #c8f4e8;
    background: #0e1524;
    border: 1px solid #1d2942;
    border-radius: 10px;
    box-sizing: border-box;
    white-space: pre-wrap;
    overflow: auto;
}

    #historyBox.placeholder {
        color: #5b6f8a;
    }

    #historyBox::placeholder {
        color: #5b6f8a;
    }

    #historyBox::-webkit-scrollbar {
        width: 10px;
    }

    #historyBox::-webkit-scrollbar-thumb {
        background: #2a3a58;
        border-radius: 5px;
    }

.log-tx {
    color: var(--green);
    font-weight: 700;
}

.log-rx {
    color: var(--red);
    font-weight: 700;
}

/* ============================================================
   OTA pages (drop zone, steps, specs, progress)
   ============================================================ */
.drop {
    position: relative;
    border: 1.5px dashed var(--border-strong);
    border-radius: 10px;
    background: var(--surface-2);
    padding: 34px 18px;
    text-align: center;
    transition: .15s;
    cursor: pointer;
    display: block;
    overflow: hidden;
}

    .drop:hover, .drop.drag {
        border-color: var(--brand);
        background: var(--brand-tint);
    }

    .drop input[type=file] {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        border: 0;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        overflow: hidden;
        white-space: nowrap;
        opacity: 0;
    }

    .drop .ic {
        font-size: 30px;
        margin-bottom: 10px;
    }

    .drop .big {
        font-size: 14px;
        font-weight: 600;
    }

    .drop .sm {
        font-size: 11.5px;
        color: var(--ink-3);
        margin-top: 5px;
    }

.files {
    list-style: none;
    margin: 14px 0 0;
    padding: 0;
    max-height: 230px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .files li {
        display: flex;
        align-items: center;
        gap: 10px;
        font-family: var(--f-mono);
        font-size: 12px;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 8px 12px;
    }

        .files li .n {
            font-family: var(--f-mono);
            color: var(--ink-3);
            width: 24px;
            text-align: right;
        }

        .files li .badge {
            font-family: var(--f-ui);
            font-size: 10px;
            font-weight: 700;
            padding: 2px 7px;
            border-radius: 5px;
            text-transform: uppercase;
            letter-spacing: .05em;
            background: var(--brand-tint);
            color: var(--brand-600);
        }

            .files li .badge.icl {
                background: var(--amber-tint);
                color: var(--amber);
            }

            .files li .badge.info {
                background: var(--surface-3);
                color: var(--ink-2);
            }

            .files li .badge.fw {
                background: var(--brand-tint);
                color: var(--brand-600);
            }

        .files li .sz {
            margin-left: auto;
            color: var(--ink-3);
        }

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 18px;
    font-family: var(--f-mono);
    font-size: 12px;
    color: var(--ink-2);
}

    .status-row.err {
        color: var(--red);
    }

    .status-row.ok {
        color: var(--green);
    }

.pct {
    font-weight: 600;
}

#progressBar, #progressContainer {
    width: 100%;
    height: 10px;
    background: var(--surface-3);
    border-radius: 6px;
    margin-top: 8px;
    overflow: hidden;
}

    #progressContainer #progressBar {
        margin-top: 0;
    }

    #progress, #progressBar > div {
        height: 100%;
        width: 0%;
        background: var(--brand);
        border-radius: 6px;
        transition: width .2s;
    }

        #progress.done, #progressBar.done {
            background: var(--green);
        }

#progressBar {
    height: 10px;
}

    #progressBar.bar-fill {
        background: var(--surface-3);
    }

.steps {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: s;
}

    .steps li {
        position: relative;
        padding: 0 0 16px 40px;
        counter-increment: s;
    }

        .steps li:last-child {
            padding-bottom: 0;
        }

        .steps li::before {
            content: counter(s);
            position: absolute;
            left: 0;
            top: -2px;
            width: 26px;
            height: 26px;
            border-radius: 50%;
            background: var(--brand-tint);
            color: var(--brand-600);
            font-family: var(--f-mono);
            font-size: 12px;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .steps li::after {
            content: "";
            position: absolute;
            left: 13px;
            top: 26px;
            bottom: 6px;
            width: 1.5px;
            background: var(--border);
        }

        .steps li:last-child::after {
            display: none;
        }

    .steps .st {
        font-size: 13px;
        font-weight: 600;
        margin-bottom: 2px;
    }

    .steps .sd {
        font-size: 12px;
        color: var(--ink-2);
        line-height: 1.5;
    }

.spec-block {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

    .spec-block .lbl {
        font-family: var(--f-mono);
        font-size: 10px;
        letter-spacing: .1em;
        text-transform: uppercase;
        color: var(--ink-3);
        margin-bottom: 8px;
    }

pre.code {
    margin: 0;
    font-family: var(--f-mono);
    font-size: 12px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 11px 13px;
    white-space: pre;
    overflow: auto;
}

    pre.code .k {
        color: var(--brand-600);
    }

.specs {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

    .specs li {
        display: flex;
        justify-content: space-between;
        font-size: 12.5px;
    }

        .specs li span:first-child {
            color: var(--ink-2);
        }

        .specs li span:last-child {
            font-family: var(--f-mono);
            color: var(--ink);
        }

code {
    font-family: var(--f-mono);
    font-size: 11.5px;
    background: var(--surface-3);
    padding: 1px 6px;
    border-radius: 5px;
    color: var(--brand-600);
}

.grid {
    display: grid;
    grid-template-columns: 1.45fr 1fr;
    gap: 18px;
    align-items: start;
}

@media (max-width:760px) {
    .grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   allCodes (used/all codes list + selected-service summary)
   ============================================================ */
.svc-head {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.svc-title {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.02em;
    margin-right: auto;
    background: var(--brand-grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.svc-head .stat {
    min-width: 110px;
    background: var(--surface-2);
}

.data-grid {
    display: grid;
    grid-template-rows: repeat(10,auto);
    grid-auto-flow: column;
    gap: 10px 22px;
}

@media (max-width:680px) {
    .data-grid {
        grid-template-rows: none;
        grid-auto-flow: row;
        grid-template-columns: 1fr;
    }
}

.data-item {
    display: flex;
    align-items: center;
    gap: 11px;
}

.sn {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 7px;
    background: var(--brand-tint);
    color: var(--brand-600);
    font-family: var(--f-mono);
    font-size: 11.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.data-input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    font-family: var(--f-mono);
    font-size: 13.5px;
    letter-spacing: .06em;
    color: var(--ink);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-2);
}

.foot-note {
    margin-top: 16px;
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-3);
    text-align: right;
}

/* ============================================================
   Fleet dashboard
   ============================================================ */
.summary {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 14px;
    margin-bottom: 22px;
}

@media (max-width:900px) {
    .summary {
        grid-template-columns: repeat(2,1fr);
    }
}

@media (max-width:520px) {
    .summary {
        grid-template-columns: 1fr;
    }
}

.sum {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

    .sum::before {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 4px;
        background: var(--brand-grad);
    }

    .sum.ok::before {
        background: var(--green);
    }

    .sum.warn::before {
        background: var(--amber);
    }

    .sum.bad::before {
        background: var(--red);
    }

    .sum .k {
        font-family: var(--f-mono);
        font-size: 10px;
        letter-spacing: .12em;
        text-transform: uppercase;
        color: var(--ink-3);
        margin-bottom: 8px;
    }

    .sum .v {
        font-size: 26px;
        font-weight: 800;
        letter-spacing: -.02em;
    }

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.search {
    flex: 1;
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 9px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 9px 13px;
    box-shadow: var(--shadow);
}

    .search input {
        border: none;
        outline: none;
        flex: 1;
        font-family: var(--f-ui);
        font-size: 13.5px;
        color: var(--ink);
        background: transparent;
    }

    .search .ic {
        color: var(--ink-3);
        font-size: 14px;
    }

.seg-filter {
    display: inline-flex;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: 9px;
    padding: 4px;
    gap: 2px;
}

    .seg-filter button {
        border: none;
        background: transparent;
        font-family: var(--f-ui);
        font-size: 12.5px;
        font-weight: 600;
        color: var(--ink-2);
        padding: 7px 14px;
        border-radius: 6px;
        cursor: pointer;
        transition: .14s;
    }

        .seg-filter button.active {
            background: #fff;
            color: var(--brand-600);
            box-shadow: 0 1px 3px #0f203914;
        }

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

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 18px;
    cursor: pointer;
    transition: .16s;
    position: relative;
    overflow: hidden;
}

    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 22px #0f203915;
        border-color: var(--brand);
    }

    .card .head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 10px;
        margin-bottom: 14px;
    }

    .card .name {
        font-size: 15.5px;
        font-weight: 700;
        letter-spacing: -.01em;
    }

    .card .cid {
        font-family: var(--f-mono);
        font-size: 11px;
        color: var(--ink-3);
        margin-top: 3px;
    }

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

    .status .d {
        width: 7px;
        height: 7px;
        border-radius: 50%;
    }

    .status.online {
        background: var(--green-tint);
        color: var(--green);
    }

        .status.online .d {
            background: var(--green);
            animation: pulse 2s infinite;
        }

    .status.offline {
        background: var(--red-tint);
        color: var(--red);
    }

        .status.offline .d {
            background: var(--red);
        }

    .status.idle {
        background: var(--amber-tint);
        color: var(--amber);
    }

        .status.idle .d {
            background: var(--amber);
        }

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

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
}

    .row .lab {
        color: var(--ink-3);
    }

    .row .val {
        font-family: var(--f-mono);
        color: var(--ink);
    }

.card .foot {
    margin-top: 15px;
    padding-top: 13px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.usage {
    font-size: 12px;
    color: var(--ink-2);
}

    .usage b {
        color: var(--brand-600);
        font-family: var(--f-mono);
    }

.open {
    font-size: 12px;
    font-weight: 600;
    color: var(--brand-600);
    display: flex;
    align-items: center;
    gap: 5px;
}

.card:hover .open {
    gap: 9px;
}

/* ============================================================
   Responsive: collapse sidebar on small screens
   ============================================================ */
@media (max-width:760px) {
    body.app-sidebar {
        grid-template-columns: 1fr;
    }

    .rail {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
        padding: 14px;
    }

    .rail-brand {
        border: none;
        margin: 0;
        padding: 0;
        flex: 1;
    }

    .nav-section, .nav-label {
        display: none;
    }

    .rail-status {
        margin: 0;
    }

    .main {
        padding: 20px 16px 48px;
    }
}
