/* ── Design Tokens ────────────────────────────────────────────────────────── */
:root {
    --bg: #070d1a;
    --surface: #0d1526;
    --surface-2: #111e35;
    --border: rgba(34, 211, 238, 0.12);
    --border-hover: rgba(34, 211, 238, 0.28);
    --primary: #22d3ee;
    --primary-dim: rgba(34, 211, 238, 0.15);
    --primary-dark: #0891b2;
    --text: #f0f6ff;
    --text-dim: #64748b;
    --text-mid: #94a3b8;
    --green: #34d399;
    --amber: #fbbf24;
    --purple: #a78bfa;
    --blue: #60a5fa;
    --red: #f87171;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 4px 32px rgba(0, 0, 0, 0.45);
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Ambient glow */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 20% 10%, rgba(34, 211, 238, 0.05) 0%, transparent 60%),
        radial-gradient(ellipse 60% 40% at 80% 80%, rgba(99, 102, 241, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.hidden {
    display: none !important;
}

/* ── Auth Screens ─────────────────────────────────────────────────────────── */
.auth-overlay {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow), 0 0 60px rgba(34, 211, 238, 0.05);
    animation: fadeUp 0.4s ease;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
}

.logo-icon.sm {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    border-radius: 8px;
}

.auth-card h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
    letter-spacing: -0.02em;
}

.auth-card p {
    color: var(--text-mid);
    margin-bottom: 2rem;
    font-size: 0.9375rem;
}

/* ── Fields ───────────────────────────────────────────────────────────────── */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1.1rem;
}

.field-group label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-mid);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.field-group small {
    font-size: 0.8125rem;
    color: var(--text-dim);
    line-height: 1.4;
}

.field-group small code {
    background: rgba(34, 211, 238, 0.1);
    color: var(--primary);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.8em;
}

input,
select,
textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
}

input::placeholder {
    color: var(--text-dim);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
    color: #fff;
    font-weight: 600;
    font-size: 0.9375rem;
    border: none;
    padding: 0.85rem 2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    width: 100%;
    letter-spacing: 0.01em;
}

.btn-primary.narrow {
    width: auto;
    min-width: 200px;
}

.btn-primary:hover {
    opacity: 0.88;
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-mid);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.btn-logout:hover {
    border-color: var(--red);
    color: var(--red);
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
.msg {
    font-size: 0.875rem;
    margin-top: 0.75rem;
    min-height: 1.2em;
}

.msg-error {
    color: var(--red);
}

.msg-success {
    color: var(--green);
}

/* ── Top Nav ──────────────────────────────────────────────────────────────── */
.topnav {
    background: rgba(7, 13, 26, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 2rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 700;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
}

.brand-tag {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--primary);
    background: var(--primary-dim);
    padding: 0.2em 0.6em;
    border-radius: 20px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.nav-tabs {
    display: flex;
    gap: 0.25rem;
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
    width: auto;
}

.tab:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
    transform: none;
}

.tab.active {
    color: var(--primary);
    background: var(--primary-dim);
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
    position: relative;
    z-index: 1;
}

/* ── Section Header ───────────────────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.section-header p {
    color: var(--text-mid);
    font-size: 0.9375rem;
}

.live-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--green);
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    flex-shrink: 0;
    margin-top: 0.25rem;
}

.pulse-dot {
    width: 7px;
    height: 7px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 1.8s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.75);
    }
}

/* ── Stats Grid ───────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.icon-green {
    background: rgba(52, 211, 153, 0.12);
}

.icon-blue {
    background: rgba(96, 165, 250, 0.12);
}

.icon-amber {
    background: rgba(251, 191, 36, 0.12);
}

.icon-purple {
    background: rgba(167, 139, 250, 0.12);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-mid);
    margin-top: 0.3rem;
    font-weight: 500;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.table-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

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

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

thead th {
    padding: 0.75rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

tbody tr {
    transition: background 0.15s;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

tbody td {
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-mid);
}

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

.app-row td {
    background: rgba(34, 211, 238, 0.05);
    color: var(--primary);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.user-tag {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2em 0.6em;
    font-size: 0.8rem;
    margin: 0.1rem;
    color: var(--text-mid);
}

.empty-row {
    text-align: center;
    color: var(--text-dim);
    padding: 3rem !important;
}

.text-dim {
    color: var(--text-dim);
    font-size: 0.875rem;
}

/* ── Settings Card ────────────────────────────────────────────────────────── */
.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.settings-block {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.block-title {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.block-icon {
    font-size: 1.5rem;
    line-height: 1;
    margin-top: 0.1rem;
}

.block-title h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

#settings-status {
    font-size: 0.875rem;
}

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

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

/* ── Docs Layout ──────────────────────────────────────────────────────────── */
.docs-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.docs-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: sticky;
    top: 80px;
}

.sidebar-header {
    padding: 1rem 1.25rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.docs-sidebar ul {
    list-style: none;
    padding: 0.5rem 0;
}

.docs-sidebar li {
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-mid);
    cursor: pointer;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.docs-sidebar li:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.docs-sidebar li.active {
    color: var(--primary);
    border-left-color: var(--primary);
    background: var(--primary-dim);
}

.docs-body {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    min-height: 600px;
    overflow: hidden;
}

.doc-placeholder {
    color: var(--text-dim);
    text-align: center;
    padding: 4rem 0;
    font-size: 0.9375rem;
}

/* Markdown rendering */
.docs-body h1 {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.75rem;
}

.docs-body h2 {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 2rem 0 0.75rem;
    color: var(--primary);
}

.docs-body h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
    color: var(--text);
}

.docs-body p {
    color: var(--text-mid);
    margin-bottom: 1rem;
    line-height: 1.75;
}

.docs-body li {
    color: var(--text-mid);
    margin-bottom: 0.4rem;
    margin-left: 1.5rem;
}

.docs-body ul {
    margin-bottom: 1rem;
}

.docs-body hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.docs-body pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1.25rem 1.5rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.docs-body code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.875em;
    color: var(--primary);
    background: rgba(34, 211, 238, 0.08);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

.docs-body pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
}

.docs-body strong {
    color: var(--text);
    font-weight: 600;
}

.docs-body blockquote {
    border-left: 3px solid var(--primary);
    background: var(--primary-dim);
    padding: 0.75rem 1.25rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin: 1rem 0;
    color: var(--text-mid);
}

.docs-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.docs-body thead th {
    background: var(--surface-2);
    padding: 0.6rem 1rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.docs-body td {
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    color: var(--text-mid);
    font-size: 0.9rem;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

section {
    animation: fadeUp 0.3s ease;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

@media (max-width: 768px) {
    .nav-inner {
        padding: 0 1rem;
        gap: 1rem;
    }

    .brand-tag {
        display: none;
    }

    .main-content {
        padding: 1.5rem 1rem;
    }

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

    .docs-layout {
        grid-template-columns: 1fr;
    }

    .docs-sidebar {
        position: static;
    }

    .settings-card {
        padding: 1.5rem;
    }
}

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

    .tab {
        padding: 0.45rem 0.75rem;
        font-size: 0.8rem;
    }

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

    .status-bar {
        flex-wrap: wrap;
    }
}

/* ── Dashboard Grid ───────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-top: 1.25rem;
}

/* ── Status Bar ───────────────────────────────────────────────────────────── */
.status-bar {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    overflow: hidden;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    font-size: 0.8125rem;
    color: var(--text-dim);
    border-right: 1px solid var(--border);
    flex: 1;
}

.status-item:last-child {
    border-right: none;
}

.status-item strong {
    color: var(--text);
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.green {
    background: var(--green);
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.7);
    animation: pulse 2s infinite;
}

/* ── Message Feed ─────────────────────────────────────────────────────────── */
.feed {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.feed-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.7rem 1.5rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.feed-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.feed-item:last-child {
    border-bottom: none;
}

.feed-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.feed-sender {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.8rem;
}

.feed-text {
    font-size: 0.875rem;
    color: var(--text-mid);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feed-tag {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1em 0.45em;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-dim);
}

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

    .status-bar {
        flex-wrap: wrap;
    }

    .status-item {
        flex: 1 1 45%;
    }
}