/* Font: DM Sans — link in layout/login head */
:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface2: #243044;
    --border: #2d3a4f;
    --text: #e8edf4;
    --muted: #8b9cb3;
    --accent: #22d3ee;
    --accent-dim: rgba(34, 211, 238, 0.15);
    --danger: #f87171;
    --warn: #fbbf24;
    --success: #4ade80;
    --radius: 10px;
    --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

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

a:hover {
    text-decoration: underline;
}

code {
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.88em;
    background: var(--surface2);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 80% 60% at 50% -20%, rgba(34, 211, 238, 0.25), transparent),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
    text-align: center;
}

.login-brand-text .muted {
    font-size: 0.875rem;
    color: var(--muted);
}

.brand-logo {
    display: block;
    height: auto;
    object-fit: contain;
}

.brand-logo--login {
    max-height: 64px;
    max-width: 100%;
    width: auto;
}

.brand-logo--sidebar {
    max-height: 40px;
    max-width: 100%;
    width: auto;
    object-fit: contain;
    object-position: left center;
}

.login-card label {
    display: block;
    margin-bottom: 1rem;
}

.login-card label span {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
}

/* App shell */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 0.75rem;
    flex: 1;
}

.nav a {
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.92rem;
    transition: background 0.15s, color 0.15s;
}

.nav a:hover {
    background: var(--surface2);
    color: var(--text);
}

.nav a.active {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 500;
}

.sidebar-footer {
    padding: 1rem 1.25rem 0;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.main-header {
    padding: 1.5rem 2rem 0;
}

.main-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.main-body {
    padding: 1.25rem 2rem 2rem;
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

/* Stats */
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
}

.stat-card.accent {
    border-color: rgba(34, 211, 238, 0.35);
    background: linear-gradient(145deg, var(--surface), var(--accent-dim));
}

.stat-card.warn {
    border-color: rgba(251, 191, 36, 0.35);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Panel */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}

.panel h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.panel-actions {
    margin: 1rem 0 0;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.filter-form select,
.filter-form input[type="text"],
.filter-form input[type="search"],
.filter-form input[type="date"] {
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    min-width: 140px;
}

.filter-form select {
    min-width: 200px;
}

.toolbar-stack {
    flex-direction: column;
    align-items: stretch;
}

.filter-form-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem 1.25rem;
}

.filter-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.filter-form-grid label.checkbox {
    flex-direction: row;
    align-items: center;
    align-self: flex-end;
    gap: 0.5rem;
    padding-bottom: 0.45rem;
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.15rem;
}

.th-sort {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}

.th-sort:hover {
    text-decoration: underline;
}

.data-table thead th {
    vertical-align: bottom;
}

.checkbox {
    cursor: pointer;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    margin: 0 -0.25rem;
}

.table-scroll {
    max-width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.data-table .click-row {
    cursor: pointer;
}

.row-error {
    background: rgba(248, 113, 113, 0.06);
}

.nowrap {
    white-space: nowrap;
}

.cell-truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.token-preview {
    font-size: 0.8rem;
}

.cell-thumb {
    min-width: 100px;
}

.img-thumb {
    display: block;
    max-height: 72px;
    max-width: 120px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.thumb-link {
    display: inline-block;
    line-height: 0;
}

.thumb-link:hover .img-thumb {
    border-color: var(--accent);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: capitalize;
}

.sev-info { background: rgba(96, 165, 250, 0.2); color: #93c5fd; }
.sev-warning { background: rgba(251, 191, 36, 0.2); color: #fcd34d; }
.sev-error { background: rgba(248, 113, 113, 0.2); color: #fca5a5; }
.sev-critical { background: rgba(220, 38, 38, 0.35); color: #fecaca; }

.status-active { background: rgba(74, 222, 128, 0.2); color: #86efac; }
.status-maintenance { background: rgba(251, 191, 36, 0.2); color: #fcd34d; }
.status-inactive { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }

.sess-initiated { background: rgba(148, 163, 184, 0.2); color: #e2e8f0; }
.sess-analyzing { background: rgba(96, 165, 250, 0.2); color: #93c5fd; }
.sess-waiting_payment { background: rgba(251, 191, 36, 0.2); color: #fcd34d; }
.sess-paid { background: rgba(74, 222, 128, 0.2); color: #86efac; }
.sess-completed { background: rgba(34, 211, 238, 0.15); color: #67e8f9; }
.sess-cancelled,
.sess-error { background: rgba(248, 113, 113, 0.2); color: #fca5a5; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #22d3ee, #06b6d4);
    color: #0f172a;
    border: none;
}

.btn-primary:hover {
    filter: brightness(1.05);
    text-decoration: none;
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--border);
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.btn-block {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.75rem;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Detail */
.detail-panel h3 {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 1.25rem 0 0.5rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}

.detail-grid dt {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.detail-grid dd {
    margin: 0;
}

.json-block {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    font-size: 0.78rem;
    line-height: 1.45;
    max-height: 280px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

@media (max-width: 900px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 0.75rem 1rem;
    }

    .sidebar-brand {
        border: none;
        margin: 0;
        padding: 0;
    }

    .nav {
        flex-direction: row;
        flex-wrap: wrap;
        flex: 1;
        padding: 0;
    }

    .sidebar-footer {
        flex-direction: row;
        border: none;
        padding: 0;
        width: 100%;
        justify-content: space-between;
    }

    .main-header,
    .main-body {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}
