:root {
    --admin-font: "Space Grotesk", system-ui, sans-serif;
    --admin-size: 14px;
    --color-bg: #f4f6f9;
    --color-surface: #fff;
    --color-border: #dee2e6;
    --color-text: #212529;
    --color-muted: #6c757d;
    --color-primary: #0d6efd;
    --color-primary-hover: #0b5ed7;
    --color-danger: #842029;
    --color-danger-bg: #f8d7da;
    --color-danger-border: #f5c2c7;
    --color-topbar: #212529;
    --radius: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --topbar-h: 52px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--admin-font);
    font-size: var(--admin-size);
    line-height: 1.4;
    color: var(--color-text);
    background: var(--color-bg);
}

#app {
    font-family: var(--admin-font);
    font-size: var(--admin-size);
}

.admin-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: var(--topbar-h);
    padding: 0 1rem;
    background: var(--color-topbar);
    color: #fff;
}

.topbar-brand {
    font-weight: 600;
    font-size: var(--admin-size);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.topbar-user {
    color: rgba(255, 255, 255, 0.85);
}

.topbar-link {
    font-size: 0.875rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
}

.topbar-link:hover {
    color: #fff;
    text-decoration: underline;
}

/* Layout */
.main {
    flex: 1;
    padding: 1rem;
    max-width: 100%;
}

.layout-grid {
    display: grid;
    gap: 1rem;
}

@media (min-width: 992px) {
    .layout-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    }
}

.sign-in-wrap {
    display: flex;
    justify-content: center;
    margin-top: 3rem;
}

.sign-in-wrap .card {
    width: 100%;
    max-width: 420px;
}

.card-unauthorized {
    border-color: #ced4da;
}

.unauthorized-title {
    margin: 0 0 0.75rem;
    font-size: 1.35rem;
    font-weight: 600;
}

.card-unauthorized code {
    font-size: 0.85em;
    padding: 0.1em 0.35em;
    background: var(--color-bg);
    border-radius: 4px;
}

.unauthorized-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.25rem;
}

.btn-secondary {
    color: var(--color-text);
    background: var(--color-surface);
    border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg);
}

/* Typography */
.muted {
    color: var(--color-muted);
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    font-family: inherit;
    font-size: var(--admin-size);
    line-height: 1.4;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    background: transparent;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    color: #fff;
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-ghost {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.6);
}

.btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.btn-sm {
    padding: 0.25rem 0.6rem;
    font-size: 13px;
}

/* Form */
.input {
    display: block;
    width: 100%;
    padding: 0.4rem 0.6rem;
    font-family: inherit;
    font-size: var(--admin-size);
    line-height: 1.4;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 0;
    border-color: var(--color-primary);
}

.sidebar-filters {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--admin-size);
    cursor: pointer;
    user-select: none;
}

.filter-row input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary);
}

.input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.badge-live {
    color: #c0392b;
    font-weight: 600;
}

/* Alert */
.alert {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.alert-error {
    color: var(--color-danger);
    background: var(--color-danger-bg);
    border-color: var(--color-danger-border);
}

.alert-dismiss {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    opacity: 0.6;
    font-size: 1.1rem;
    line-height: 1;
}

.alert-dismiss::before {
    content: "×";
}

.alert-dismiss:hover {
    opacity: 1;
}

/* Card */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card + .card {
    margin-top: 1rem;
}

.card-header {
    padding: 0.6rem 1rem;
    font-weight: 600;
    background: #f8f9fa;
    border-bottom: 1px solid var(--color-border);
}

.card-body {
    padding: 1rem;
}

.card-body--center {
    text-align: center;
    padding: 2.5rem 1.5rem;
}

.card-body--center p {
    margin: 0 0 1rem;
}

.card-body--center p:last-of-type {
    margin-bottom: 1.5rem;
}

/* Definition list */
.meta-list {
    display: grid;
    grid-template-columns: minmax(0, 28%) minmax(0, 1fr);
    gap: 0.35rem 1rem;
    margin: 0;
}

.meta-list dt {
    font-weight: 600;
    margin: 0;
}

.meta-list dd {
    margin: 0;
}

/* Lists */
.list {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    overflow: hidden;
}

.list-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: var(--admin-size);
    text-align: left;
    color: inherit;
    background: var(--color-surface);
    border: none;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: #f8f9fa;
}

.list-item.active {
    color: #fff;
    background: var(--color-primary);
}

.list-item.active:hover {
    background: var(--color-primary-hover);
}

.list-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    opacity: 0.85;
}

.list-item-link {
    flex-shrink: 0;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.list-item-link:hover {
    text-decoration: underline;
}

.list-item.active .list-item-link {
    color: #fff;
}

.list-item.active .list-item-link:hover {
    color: rgba(255, 255, 255, 0.9);
}

.meta-link {
    /* margin-left: 0.5rem; */
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-primary);
    text-decoration: none;
}

.meta-link:hover {
    text-decoration: underline;
}

.panel-label {
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: #495057;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}

.panel-header .panel-label {
    margin-bottom: 0;
}

.sidebar-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: calc(100vh - var(--topbar-h) - 2rem);
}

.sidebar-panel {
    display: flex;
    flex-direction: column;
}

.sidebar-panel.markets-panel {
    flex: 1;
    min-height: 0;
}

.list-panel {
    overflow-y: auto;
    min-height: 0;
}

.list-panel.sports-list {
    max-height: 140px;
}

.list-panel.markets-list {
    flex: 1;
    max-height: none;
}

.detail-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - var(--topbar-h) - 2rem);
}

.layout-grid > section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100vh - var(--topbar-h) - 2rem);
}

.admin-tabs-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.topbar-role {
    color: var(--color-muted, #6c757d);
    font-weight: 400;
}

.admin-tab-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    background: #f8f9fa;
}

.tab-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    padding: 0.35rem 0.65rem;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--color-text);
}

.tab-item:hover {
    background: var(--color-bg);
}

.tab-item.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.admin-tab-panel {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.admin-tab-empty {
    padding: 1rem 0.75rem;
    margin: 0;
}

.analysis-panel {
    padding: 0.75rem;
}

.analysis-empty,
.analysis-note {
    padding: 0.5rem 0;
    margin: 0;
}

.analysis-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.analysis-subtabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.tab-item-sm {
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    text-transform: capitalize;
}

.analysis-section {
    min-height: 8rem;
}

.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.analysis-stat {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: 0.35rem;
    background: var(--color-bg);
    font-size: 0.85rem;
}

.analysis-stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-muted);
}

.analysis-gap-warn {
    border-color: #c2410c;
    background: #fff7ed;
}

.analysis-mono {
    font-family: ui-monospace, monospace;
    font-size: 0.78rem;
    word-break: break-all;
}

.analysis-log-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

.analysis-log-filters .input {
    flex: 1 1 10rem;
    min-width: 8rem;
}

.analysis-log-mc {
    max-width: 48rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.72rem;
    line-height: 1.35;
}

.analysis-more {
    margin-top: 0.75rem;
}

.auth-users-panel {
    padding: 0.75rem;
}

.auth-users-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

.auth-users-form .input {
    flex: 1 1 10rem;
    min-width: 8rem;
}

.auth-users-notes {
    flex: 2 1 12rem;
}

.auth-users-table .input-compact {
    padding: 0.2rem 0.35rem;
    font-size: 0.85rem;
    min-width: 6rem;
}

.auth-users-notes-cell {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.auth-users-meta {
    font-size: 0.75rem;
    white-space: nowrap;
}

.auth-users-table tr.row-inactive {
    opacity: 0.55;
}

.live-badge {
    margin-left: 0.5rem;
    padding: 0.1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #198754;
    background: #d1e7dd;
    border-radius: 999px;
    vertical-align: middle;
}

.memory-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 1rem;
    background: rgba(33, 37, 41, 0.55);
}

.memory-panel {
    display: flex;
    flex-direction: column;
    width: min(1200px, 100%);
    max-height: calc(100vh - 2rem);
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.memory-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    background: #f8f9fa;
}

.memory-panel-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.memory-panel-meta {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
}

.memory-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.memory-panel-body {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 1rem;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--color-surface);
}

.access-panel {
    display: flex;
    flex-direction: column;
    width: min(960px, 100%);
    max-height: calc(100vh - 2rem);
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.access-panel-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
    background: #f8f9fa;
}

.access-panel-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 1rem;
}

.access-hint {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
}

.alert-key-reveal {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.65rem 0.75rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.alert-key-reveal code {
    word-break: break-all;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* margin-bottom: 0.5rem; */
}

/* Table */
.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--admin-size);
}

.table th,
.table td {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--color-border);
    vertical-align: middle;
}

.table thead th {
    background: #f8f9fa;
    font-weight: 600;
    border-bottom-width: 2px;
}

.table-striped tbody tr:nth-child(even) {
    background: #f8f9fa;
}

.table .border-end {
    border-right: 2px solid var(--color-border);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-muted);
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
