:root {
    color-scheme: dark;
    --bg: #07090b;
    --surface: #0d1115;
    --surface-2: #12171c;
    --surface-3: #171d23;
    --line: rgba(255, 255, 255, .09);
    --line-strong: rgba(255, 255, 255, .15);
    --text: #edf3fa;
    --muted: #91a0b3;
    --accent: #b8de18;
    --accent-strong: #d9ff45;
    --danger: #ff536c;
    --warning: #ffcb5b;
    --radius: 16px;
    --shadow: 0 20px 60px rgba(0, 0, 0, .34);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 14% -10%, rgba(184, 222, 24, .08), transparent 32%),
        var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    color: inherit;
}

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

[hidden] {
    display: none !important;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 72px;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr);
    align-items: center;
    gap: 24px;
    padding: 12px clamp(18px, 3vw, 46px);
    border-bottom: 1px solid var(--line);
    background: rgba(7, 9, 11, .88);
    backdrop-filter: blur(18px);
}

.brand,
.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    justify-self: start;
}

.brand > span:last-child,
.user-menu span {
    display: grid;
    gap: 3px;
}

.brand strong {
    font-size: 14px;
    letter-spacing: .02em;
}

.brand small,
.user-menu small {
    color: var(--muted);
    font-size: 10px;
}

.brand-mark {
    position: relative;
    width: 34px;
    height: 34px;
    display: inline-block;
    flex: 0 0 auto;
}

.brand-mark span {
    position: absolute;
    top: 5px;
    width: 13px;
    height: 24px;
    border-radius: 2px;
    background: var(--accent);
    transform: skewY(-32deg);
    box-shadow: 0 0 18px rgba(184, 222, 24, .22);
}

.brand-mark span:first-child {
    left: 2px;
}

.brand-mark span:last-child {
    right: 2px;
}

.main-tabs,
.server-switch {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .025);
}

.tab-button,
.server-switch button {
    min-height: 36px;
    padding: 8px 14px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: background .2s ease, color .2s ease;
}

.tab-button:hover,
.server-switch button:hover {
    color: var(--text);
}

.tab-button.active,
.server-switch button.active {
    background: var(--accent);
    color: #101500;
}

.user-menu {
    justify-self: end;
}

.user-menu img {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: 50%;
    object-fit: cover;
}

.user-menu strong {
    max-width: 150px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu > a {
    margin-left: 6px;
    color: var(--muted);
    font-size: 11px;
}

.user-menu > a:hover {
    color: var(--danger);
}

.app-main {
    width: min(1560px, 100%);
    margin: 0 auto;
    padding: clamp(28px, 4vw, 58px) clamp(16px, 3vw, 46px) 80px;
}

.page-pane {
    display: grid;
    gap: 22px;
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    padding: 8px 2px;
}

.page-head h1 {
    max-width: 820px;
    margin: 6px 0 8px;
    font-size: clamp(32px, 4vw, 58px);
    letter-spacing: -.055em;
    line-height: .98;
}

.page-head p:not(.eyebrow),
.panel-head p,
.login-card > p {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
}

.eyebrow {
    margin: 0;
    color: var(--accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .2em;
    text-transform: uppercase;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid rgba(184, 222, 24, .16);
    border-radius: 999px;
    color: #afbdcf;
    font-size: 11px;
    white-space: nowrap;
}

.status-pill i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px rgba(184, 222, 24, .7);
}

.panel {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(13, 17, 21, .9);
    box-shadow: var(--shadow);
}

.query-panel,
.sweep-panel {
    padding: clamp(20px, 3vw, 34px);
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.panel-head h2 {
    margin: 5px 0 0;
    font-size: clamp(19px, 2vw, 28px);
    letter-spacing: -.035em;
}

.panel-head p:not(.eyebrow) {
    margin-top: 7px;
    font-size: 13px;
}

.query-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

label {
    min-width: 0;
    display: grid;
    gap: 8px;
}

label > span {
    color: #aebac9;
    font-size: 11px;
    font-weight: 700;
}

label.wide {
    grid-column: span 2;
}

input,
select,
textarea {
    width: 100%;
    min-height: 43px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    outline: none;
    background: #090c0f;
    color: var(--text);
    transition: border-color .2s ease, box-shadow .2s ease;
}

textarea {
    min-height: 118px;
    resize: vertical;
    line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
    color: #566273;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(184, 222, 24, .62);
    box-shadow: 0 0 0 3px rgba(184, 222, 24, .08);
}

.actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 15px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--surface-3);
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
    transition: border-color .2s ease, background .2s ease, transform .2s ease;
}

.button:hover {
    border-color: rgba(184, 222, 24, .42);
    transform: translateY(-1px);
}

.button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #111700;
}

.button.danger {
    border-color: rgba(255, 83, 108, .32);
    background: rgba(255, 83, 108, .1);
    color: #ff8b9c;
}

.button.small {
    min-height: 34px;
    padding: 7px 11px;
}

.button:disabled {
    opacity: .55;
    cursor: wait;
    transform: none;
}

.inline-status {
    margin-left: 6px;
    color: var(--muted);
    font-size: 12px;
}

.grafana-panel .panel-head {
    margin: 0;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.grafana-panel iframe {
    width: 100%;
    height: min(590px, 65vh);
    display: block;
    border: 0;
    background: #080a0d;
}

.grafana-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 22px;
}

.grafana-card .panel-head {
    min-height: 112px;
    margin: 0;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.grafana-card .panel-head h2 {
    font-size: 20px;
}

.grafana-card iframe {
    width: 100%;
    height: min(500px, 58vh);
    display: block;
    border: 0;
    background: #080a0d;
}

.grafana-card .frame-placeholder {
    min-height: 210px;
}

.frame-placeholder {
    min-height: 260px;
    display: grid;
    place-content: center;
    gap: 8px;
    padding: 30px;
    color: var(--muted);
    text-align: center;
}

.frame-placeholder strong {
    color: var(--text);
}

.capture-preview {
    border-top: 1px solid var(--line);
}

.preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 16px 22px;
}

.preview-head span,
.preview-empty {
    color: var(--muted);
    font-size: 12px;
}

.preview-empty {
    padding: 20px 22px;
}

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

.mini-table th,
.mini-table td {
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    font-size: 11px;
    text-align: left;
}

.mini-table th {
    color: var(--muted);
}

.mini-table td:last-child {
    max-width: 500px;
    overflow: hidden;
    color: #69778a;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-all-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
    gap: clamp(22px, 4vw, 44px);
    padding: clamp(20px, 3vw, 30px);
    border: 1px solid rgba(184, 222, 24, .34);
    border-radius: 16px;
    background:
        radial-gradient(circle at 90% 10%, rgba(184, 222, 24, .13), transparent 42%),
        rgba(184, 222, 24, .035);
}

.sync-all-copy h3,
.sweep-manual-head h3 {
    margin: 9px 0 0;
    font-size: clamp(18px, 2vw, 24px);
}

.sync-all-copy > p,
.sweep-manual-head > p:not(.eyebrow) {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.65;
}

.sync-mode-badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--accent);
    color: #111700;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .16em;
}

.sync-all-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
}

.sync-all-list li {
    padding: 7px 10px;
    border: 1px solid rgba(184, 222, 24, .18);
    border-radius: 999px;
    background: rgba(0, 0, 0, .2);
    color: #cbd6e3;
    font-size: 11px;
}

.sync-all-list li::before {
    content: "✓";
    margin-right: 6px;
    color: var(--accent);
    font-weight: 900;
}

.sync-all-list code {
    color: var(--accent);
    font-size: 10px;
}

.sync-all-actions {
    display: grid;
    align-content: center;
    gap: 12px;
}

.loose-chest-config {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(220px, .8fr) minmax(280px, 1.2fr);
    gap: 16px 24px;
    padding-top: 22px;
    border-top: 1px solid rgba(184, 222, 24, .18);
}

.loose-chest-config h4 {
    margin: 7px 0 0;
    font-size: 18px;
}

.loose-chest-config p:not(.eyebrow) {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.65;
}

.loose-chest-config code {
    color: var(--accent);
}

.loose-chest-actions {
    grid-column: 2;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.sync-all-actions small {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.5;
    text-align: center;
}

.sync-all-button {
    width: 100%;
    min-height: 48px;
    font-weight: 900;
    letter-spacing: .03em;
}

.sweep-manual {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.sweep-manual-head {
    margin-bottom: 16px;
}

.sweep-grid {
    display: grid;
    grid-template-columns: minmax(250px, 1.5fr) repeat(2, minmax(110px, .6fr)) auto;
    align-items: end;
    gap: 12px;
}

.sweep-stop {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.progress-shell {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(0, 0, 0, .18);
}

.progress-shell > div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    color: var(--muted);
    font-size: 12px;
}

.progress-shell strong {
    color: var(--accent);
}

.progress-track {
    height: 4px;
    margin-top: 12px;
    overflow: hidden;
    border-radius: 99px;
    background: rgba(255, 255, 255, .08);
}

.progress-track span {
    width: 0;
    height: 100%;
    display: block;
    border-radius: inherit;
    background: linear-gradient(90deg, #78910d, var(--accent-strong));
    box-shadow: 0 0 14px rgba(184, 222, 24, .45);
    transition: width .25s ease;
}

.progress-shell pre {
    max-height: 190px;
    margin: 14px 0 0;
    overflow: auto;
    color: #8290a3;
    font: 11px/1.6 "Cascadia Code", Consolas, monospace;
    white-space: pre-wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.stats-grid article {
    min-height: 115px;
    display: grid;
    align-content: center;
    gap: 10px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}

.stats-grid span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.stats-grid strong {
    font-size: clamp(26px, 3vw, 40px);
    letter-spacing: -.05em;
}

.table-toolbar {
    display: grid;
    grid-template-columns: auto minmax(260px, 1fr) minmax(170px, auto) minmax(140px, auto);
    gap: 10px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.table-wrap {
    overflow-x: auto;
}

.table-wrap table {
    width: 100%;
    min-width: 860px;
    border-collapse: collapse;
}

.table-wrap th,
.table-wrap td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.table-wrap th {
    background: rgba(255, 255, 255, .015);
}

.table-wrap th button {
    padding: 0;
    border: 0;
    background: transparent;
    color: #7f8c9e;
    cursor: pointer;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.table-wrap th button.active {
    color: var(--accent);
}

.table-wrap td {
    color: #b8c3d2;
    font-size: 13px;
}

.table-wrap td:first-child strong {
    display: block;
    color: var(--text);
    font-size: 14px;
}

code {
    color: #a8c9de;
    font: 11px "Cascadia Code", Consolas, monospace;
}

.location-cell {
    display: flex;
    align-items: center;
    gap: 9px;
}

.location-cell button {
    padding: 5px 8px;
    border: 1px solid rgba(184, 222, 24, .2);
    border-radius: 7px;
    background: rgba(184, 222, 24, .06);
    color: var(--accent);
    cursor: pointer;
    font-size: 10px;
    font-weight: 800;
}

.distribution-row td {
    padding: 0 16px 16px;
    background: rgba(0, 0, 0, .15);
}

.distribution-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.location-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, .025);
    color: var(--muted);
    font-size: 10px;
}

.location-chip b {
    color: var(--text);
}

.location-chip strong {
    color: var(--accent);
}

.empty-cell {
    padding: 40px !important;
    color: var(--muted) !important;
    text-align: center !important;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
}

.table-footer > span {
    color: var(--muted);
    font-size: 11px;
}

.table-footer > div {
    display: flex;
    gap: 6px;
}

.table-footer button {
    min-width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
}

.table-footer button.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #111700;
}

.table-footer button:disabled {
    opacity: .35;
    cursor: default;
}

.busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(3, 4, 5, .76);
    backdrop-filter: blur(7px);
}

.busy-overlay > div {
    min-width: min(360px, 100%);
    display: grid;
    justify-items: center;
    gap: 11px;
    padding: 28px;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.busy-overlay small {
    color: var(--muted);
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255, 255, 255, .08);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(1turn); }
}

.toast-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 120;
    display: grid;
    gap: 8px;
}

.toast {
    max-width: min(410px, calc(100vw - 40px));
    padding: 13px 15px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: #151b21;
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: 12px;
    animation: toast-in .22s ease both;
}

.toast.error {
    border-color: rgba(255, 83, 108, .4);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(480px, 100%);
    display: grid;
    justify-items: start;
    gap: 14px;
    padding: clamp(28px, 6vw, 52px);
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(13, 17, 21, .94);
    box-shadow: var(--shadow);
}

.login-card .brand-mark {
    margin-bottom: 6px;
}

.login-card h1 {
    margin: 0;
    font-size: clamp(36px, 8vw, 58px);
    letter-spacing: -.06em;
}

.login-card small {
    color: var(--muted);
}

.login-button {
    width: 100%;
    margin-top: 8px;
}

.alert {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 9px;
    font-size: 12px;
}

.alert.danger {
    border-color: rgba(255, 83, 108, .34);
    background: rgba(255, 83, 108, .08);
    color: #ff9aaa;
}

@media (max-width: 980px) {
    .app-header {
        grid-template-columns: 1fr auto;
    }

    .main-tabs {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-self: stretch;
    }

    .tab-button {
        flex: 1;
    }

    .query-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grafana-gallery {
        grid-template-columns: 1fr;
    }

    .sync-all-card {
        grid-template-columns: 1fr;
    }

    .loose-chest-config {
        grid-template-columns: 1fr;
    }

    .loose-chest-actions {
        grid-column: auto;
    }

    .sweep-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sweep-grid .button {
        width: 100%;
    }

    .table-toolbar {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .app-header {
        gap: 10px;
        padding: 10px 14px;
    }

    .brand small,
    .user-menu span,
    .user-menu img {
        display: none;
    }

    .page-head,
    .panel-head {
        align-items: stretch;
        flex-direction: column;
    }

    .status-pill {
        white-space: normal;
    }

    .query-grid,
    .sync-all-card,
    .sweep-grid,
    .stats-grid,
    .table-toolbar {
        grid-template-columns: 1fr;
    }

    label.wide {
        grid-column: auto;
    }

    .server-switch {
        width: 100%;
    }

    .server-switch button {
        flex: 1;
    }

    .actions .button {
        flex: 1;
    }

    .inline-status {
        width: 100%;
        margin: 5px 0 0;
    }

    .grafana-panel iframe {
        height: 480px;
    }

    .grafana-card iframe {
        height: 420px;
    }

    .table-footer {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}
