:root {
    color-scheme: light;
    --bg: #f7f8f9;
    --panel: #ffffff;
    --panel-soft: #fbfcfd;
    --text: #282828;
    --muted: #7a8291;
    --line: #edf0f4;
    --line-strong: #dfe4ea;
    --accent: #e50914;
    --accent-hot: #ff711f;
    --green: #178a64;
    --warning: #a26000;
    --danger: #b42335;
    --shadow: 0 2.75px 2.21px rgba(0,0,0,.01), 0 6.65px 5.32px rgba(0,0,0,.02), 0 22px 18px rgba(0,0,0,.03), 0 0 1px rgba(0,0,0,.10);
    --shadow-drop: 0 10px 70px rgba(0,0,0,.12), 0 0 1px rgba(0,0,0,.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(180deg, #fff 0, var(--bg) 260px);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        linear-gradient(90deg, rgba(229,9,20,.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255,113,31,.03) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: linear-gradient(180deg, rgba(0,0,0,.8), transparent 62%);
    pointer-events: none;
}

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

button {
    min-height: 38px;
    border: 0;
    border-radius: var(--radius);
    padding: 0 14px;
    background: linear-gradient(90deg, var(--accent-hot), var(--accent));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(229, 9, 20, .16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
}

button:hover {
    filter: brightness(.98);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

button.secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line-strong);
    box-shadow: none;
}

button.danger {
    background: var(--danger);
    box-shadow: 0 8px 18px rgba(180, 35, 53, .14);
}

button.ghost {
    background: #fff;
    color: var(--accent);
    border: 1px solid rgba(229, 9, 20, .22);
    box-shadow: none;
}

button:disabled {
    opacity: .52;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    display: inline-flex;
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
    align-items: center;
    justify-content: center;
}

.btn-icon svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

button span:not(.btn-icon) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(229, 9, 20, .45);
    box-shadow: 0 0 0 3px rgba(229, 9, 20, .08);
}

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

label {
    display: grid;
    gap: 6px;
    color: #3c4450;
    font-size: 13px;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 13px;
}

th {
    color: #6d7480;
    font-weight: 700;
    background: #fafbfc;
}

td small,
.brand small,
.metric small,
.section-head p,
.mini-row small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

code {
    display: inline-block;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 6px;
    background: #fafbfc;
    color: #475467;
    word-break: break-word;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}

.auth-panel {
    width: min(460px, 100%);
    display: grid;
    gap: 24px;
    padding: 30px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.94);
    box-shadow: var(--shadow-drop);
}

.auth-brand {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-bottom: 2px;
}

.auth-brand strong {
    font-size: 15px;
}

.auth-panel h1 {
    margin: 0 0 8px;
    font-size: 28px;
    line-height: 1.22;
}

.stack {
    display: grid;
    gap: 14px;
}

.eyebrow {
    margin: 0 0 8px;
    color: transparent;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
    background: linear-gradient(90deg, var(--accent-hot), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
}

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

.form-message,
.toast {
    min-height: 20px;
    color: var(--warning);
}

.toast {
    min-width: min(320px, 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: #fff;
    box-shadow: var(--shadow);
    display: flex;
    gap: 8px;
    align-items: center;
}

.toast.is-ok {
    color: var(--green);
}

.toast.is-warn {
    color: var(--warning);
}

.toast-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: currentColor;
    box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 12%, transparent);
}

.busy-layer {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: start center;
    padding-top: 22px;
    pointer-events: none;
    background: rgba(255,255,255,.18);
    backdrop-filter: blur(1.5px);
}

.busy-layer[hidden] {
    display: none;
}

.busy-card {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 14px;
    background: rgba(255,255,255,.96);
    box-shadow: var(--shadow-drop);
    color: #3a414b;
}

.spinner {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 2px solid #f0c2bd;
    border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(30, 34, 40, .34);
    backdrop-filter: blur(8px);
}

.confirm-dialog {
    width: min(420px, 100%);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    background: #fff;
    box-shadow: var(--shadow-drop);
    animation: modalIn .16s ease-out;
}

.confirm-dialog h2 {
    margin: 0 0 6px;
    font-size: 18px;
}

.confirm-dialog p {
    margin: 0;
    color: var(--muted);
    line-height: 1.7;
}

.confirm-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    background: #fff4f1;
    color: var(--danger);
}

.confirm-mark .btn-icon,
.confirm-mark svg {
    width: 20px;
    height: 20px;
}

.dialog-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    gap: 18px;
    padding: 18px;
}

.sidebar {
    position: sticky;
    top: 18px;
    height: calc(100vh - 36px);
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 18px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.96);
    box-shadow: var(--shadow);
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: 0;
}

.brand strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent-hot), var(--accent));
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    box-shadow: 0 10px 24px rgba(229, 9, 20, .18);
}

.nav {
    display: grid;
    align-content: start;
    gap: 6px;
}

.nav button {
    justify-content: flex-start;
    width: 100%;
    min-height: 40px;
    background: transparent;
    color: #3a414b;
    text-align: left;
    box-shadow: none;
}

.nav button.active,
.nav button:hover {
    background: #fff4f1;
    color: var(--accent);
}

.nav button.active {
    font-weight: 800;
}

.main {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 18px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    min-height: 70px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255,255,255,.92);
    box-shadow: var(--shadow);
}

.topbar h1 {
    margin: 0;
    font-size: 26px;
    line-height: 1.2;
}

.view {
    display: none;
}

.view.active {
    display: grid;
    gap: 16px;
}

.panel {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    transition: box-shadow .16s ease, border-color .16s ease, transform .16s ease;
}

.panel:hover {
    border-color: var(--line-strong);
}

.panel h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.3;
}

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

.section-head > div:first-child {
    min-width: 0;
}

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

.metric {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.metric::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg, var(--accent-hot), var(--accent));
}

.metric span {
    color: var(--muted);
    font-size: 13px;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 31px;
    line-height: 1.1;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

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

.form-grid .full {
    grid-column: 1 / -1;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.toolbar.compact {
    justify-content: flex-end;
}

.toolbar select,
.toolbar input {
    width: auto;
    min-width: 150px;
}

.toolbar #recordKeyword {
    min-width: 210px;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

tbody tr {
    transition: background .14s ease;
}

tbody tr:hover {
    background: #fffafa;
}

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

.actions button {
    min-height: 34px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 2px 8px;
    background: #f2f4f7;
    color: #475467;
    font-size: 12px;
    font-weight: 700;
}

.badge.ok {
    background: #e7f6f0;
    color: var(--green);
}

.badge.warn {
    background: #fff4db;
    color: var(--warning);
}

.record-type {
    display: inline-flex;
    min-width: 44px;
    min-height: 26px;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: #fff4f1;
    color: var(--accent);
    font-weight: 900;
}

.json-lines {
    max-width: 360px;
    white-space: pre-wrap;
    word-break: break-word;
}

.mini-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 10px;
}

.quick-action {
    min-height: 78px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    justify-content: start;
    gap: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    box-shadow: none;
    text-align: left;
}

.quick-action:hover {
    border-color: rgba(229, 9, 20, .22);
    background: #fffafa;
    box-shadow: var(--shadow);
}

.quick-action .btn-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: #fff4f1;
    color: var(--accent);
}

.quick-action .btn-icon svg {
    width: 18px;
    height: 18px;
}

.quick-action strong,
.quick-action small {
    display: block;
}

.quick-action small {
    margin-top: 2px;
    color: var(--muted);
}

.mini-row {
    width: 100%;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    box-shadow: none;
    text-align: left;
}

.mini-row:hover {
    border-color: rgba(229, 9, 20, .22);
    box-shadow: var(--shadow);
}

.mini-row strong {
    display: block;
}

.empty-state,
.empty-row td {
    padding: 22px;
    color: var(--muted);
    text-align: center;
    background: linear-gradient(180deg, #fff, #fbfcfd);
}

.context-panel {
    border-color: rgba(229, 9, 20, .18);
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 220px minmax(0, 1fr);
        gap: 14px;
        padding: 14px;
    }

    .form-grid {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }
}

@media (max-width: 820px) {
    .app-shell {
        display: block;
        padding: 0;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 20;
        height: auto;
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 10px;
        padding: 10px 12px;
        border-width: 0 0 1px;
        border-radius: 0;
        background: rgba(255,255,255,.97);
        backdrop-filter: blur(12px);
    }

    .brand {
        grid-column: 1 / -1;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
        font-size: 12px;
    }

    .brand small {
        display: none;
    }

    .nav {
        grid-column: 1 / -1;
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav button {
        flex: 0 0 auto;
        width: auto;
        min-height: 36px;
        padding: 0 12px;
        border: 1px solid var(--line);
        background: #fff;
        white-space: nowrap;
    }

    .nav button.active {
        border-color: rgba(229, 9, 20, .22);
        background: #fff4f1;
    }

    #logoutBtn {
        position: absolute;
        top: 10px;
        right: 12px;
        min-height: 34px;
        padding: 0 10px;
    }

    .main {
        padding: 12px;
        gap: 12px;
    }

    .topbar {
        min-height: auto;
        padding: 14px;
        display: grid;
    }

    .topbar h1 {
        font-size: 22px;
    }

    .toast {
        width: 100%;
        min-width: 0;
    }

    .metric-grid,
    .quick-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-grid .wide,
    .form-grid .full {
        grid-column: auto;
    }

    .section-head {
        display: grid;
    }

    .toolbar,
    .toolbar.compact {
        justify-content: stretch;
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .toolbar select,
    .toolbar input,
    .toolbar #recordKeyword {
        width: 100%;
        min-width: 0;
    }

    .panel {
        padding: 14px;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        background: transparent;
    }

    table,
    thead,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    thead {
        display: none;
    }

    tr {
        margin-bottom: 10px;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: #fff;
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    td {
        min-height: 38px;
        display: grid;
        grid-template-columns: 88px minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        border-bottom: 1px solid var(--line);
        padding: 9px 10px;
        word-break: break-word;
    }

    td:last-child {
        border-bottom: 0;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 700;
    }

    td[colspan] {
        display: block;
    }

    td[colspan]::before {
        display: none;
    }

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

    .actions button {
        width: 100%;
    }

    .auth-panel {
        padding: 22px;
    }
}

@media (max-width: 460px) {
    .main {
        padding: 10px;
    }

    .auth-shell {
        padding: 14px;
    }

    .auth-panel h1 {
        font-size: 24px;
    }

    .metric strong {
        font-size: 27px;
    }

    .actions {
        grid-template-columns: 1fr;
    }
}
