/* DiagnoStack shared design system — dashboard + admin.
   Direction: a precision financial-data console, not a generic SaaS
   dashboard. Dark surface, one restrained accent, monospace reserved for
   actual data (keys, figures, timestamps) so it reads as functional, not
   decorative. */

:root {
    --bg: #0B1420;
    --surface: #111E2E;
    --surface-2: #16283C;
    --border: #223349;
    --text: #E8EEF5;
    --text-muted: #8FA3B8;
    --accent: #F0A94E;
    --accent-ink: #14110A;
    --success: #34C77B;
    --danger: #EF5A5A;
    --warning: #F0A94E;
    --radius: 8px;
    --sidebar-width: 220px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    margin: 0;
    padding: 0;
}

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

.shell { max-width: 780px; margin: 0 auto; padding: 32px 24px 80px; }
.shell-wide { max-width: 1040px; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.wordmark { font-size: 16px; font-weight: 600; letter-spacing: 0.01em; }
.wordmark .dim { color: var(--text-muted); font-weight: 400; }
.nav-links a { color: var(--text-muted); margin-right: 18px; font-size: 13px; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 26px;
    margin-bottom: 18px;
}
.panel h3 {
    margin: 0 0 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.panel p { margin: 6px 0; color: var(--text-muted); }
.panel .row-label { color: var(--text-muted); }
.panel .row-value { color: var(--text); font-weight: 500; }

.field-row { margin: 10px 0; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: rgba(63,191,127,.13); color: var(--success); }
.badge-muted   { background: rgba(139,147,161,.13); color: var(--text-muted); }
.badge-warning { background: rgba(224,166,74,.13); color: var(--warning); }
.badge-danger  { background: rgba(229,72,77,.13); color: var(--danger); }

.mono {
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: -0.01em;
}
.key-display {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: var(--font-mono);
    font-size: 13px;
    overflow-x: auto;
    color: var(--text);
}

.btn {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(229,72,77,.08); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-muted); padding: 8px 10px; }
.btn-quiet:hover { color: var(--text); border-color: var(--border); }

input, select {
    font: inherit;
    font-size: 13px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 9px 12px;
}
input::placeholder { color: var(--text-muted); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

form.inline { display: inline; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.cluster { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

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

/* Correct way to make a table scroll on narrow screens: wrap it in a
   container that scrolls, and leave the table's own display mode
   (table/table-row/table-cell) completely untouched. Setting
   display:block directly on <table> -- a mistake in an earlier pass --
   breaks the browser's row/column alignment entirely, which is what
   caused cells to visually overlap instead of just needing a scrollbar. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* width:auto overrides the base "table{width:100%}" rule above --
   without this, the table keeps being forced to fit the narrow mobile
   viewport regardless of min-width, so it never actually needs to
   scroll and just squeezes/overlaps columns instead. white-space:nowrap
   on cells stops wrapped text from visually overlapping the row below. */
.table-scroll table { width: auto; min-width: 560px; }
.table-scroll th, .table-scroll td { white-space: nowrap; }
th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
tr:last-child td { border-bottom: none; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.stat-card .stat-value { font-size: 24px; font-weight: 600; font-family: var(--font-mono); }
.stat-card .stat-label { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.plan-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.plan-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px 16px;
    min-width: 140px;
}
.plan-card .plan-name { font-weight: 600; font-size: 13px; }
.plan-card .plan-price { font-family: var(--font-mono); color: var(--accent); font-size: 15px; margin-top: 4px; }

.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.list-plain li:last-child { border-bottom: none; }

.help-text { color: var(--text-muted); font-size: 12.5px; margin-top: 8px; }

.auth-shell { max-width: 380px; margin: 90px auto; padding: 0 24px; }
.auth-shell h2 { font-size: 20px; margin-bottom: 22px; }
.auth-shell input { width: 100%; margin-bottom: 12px; }
.auth-shell .btn { width: 100%; }
.auth-shell .switch-link { text-align: center; margin-top: 16px; color: var(--text-muted); font-size: 13px; }

.value-block { }
.gauge-track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; margin: 14px 0; }
.gauge-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.sentiment-word { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 2px; }
.component-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; }
.component-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; }
.component-tile .comp-label { font-size: 12px; color: var(--text-muted); }
.component-tile .comp-value { font-family: var(--font-mono); font-size: 17px; margin-top: 4px; }

.error-text { color: var(--danger); font-size: 13px; margin-bottom: 14px; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-btn {
    font: inherit; font-size: 13px; font-weight: 600; color: var(--text-muted);
    background: none; border: none; border-bottom: 2px solid transparent;
    padding: 10px 4px; margin-right: 20px; cursor: pointer;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-content.hidden { display: none; }

/* Copy-to-clipboard */
.key-row { display: flex; align-items: center; gap: 8px; }
.key-row .key-display { flex: 1; margin: 0; }
.copy-btn {
    font: inherit; font-size: 12px; font-weight: 600; padding: 8px 12px;
    border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2);
    color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

/* Locked/teaser panel for free-tier upsell */
.locked-panel { position: relative; }
.locked-panel .locked-content { filter: blur(5px); opacity: 0.5; pointer-events: none; user-select: none; }
.locked-overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 20px;
}
.locked-overlay .lock-title { font-size: 15px; font-weight: 600; color: var(--text); }
.locked-overlay .lock-sub { font-size: 13px; color: var(--text-muted); max-width: 280px; }

/* ---------------- Mobile responsiveness ---------------- */
@media (max-width: 640px) {
    .shell, .shell-wide { padding: 16px 14px 60px; }

    .topbar { flex-wrap: wrap; gap: 10px; }
    .wordmark { font-size: 14px; }

    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; flex-wrap: nowrap; }
    .tab-btn { flex-shrink: 0; margin-right: 14px; }

    .panel { padding: 16px 16px; }

    /* Tables don't reflow well on narrow screens -- let them scroll
       horizontally inside their own box rather than squeezing/wrapping
       every cell illegibly. */
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    thead, tbody, tr { display: table; width: 100%; table-layout: fixed; }

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

    .plan-grid { flex-direction: column; }
    .plan-card { width: 100%; }

    .cluster { gap: 8px; }

    .key-row { flex-direction: column; align-items: stretch; }
    .key-display { word-break: break-all; white-space: normal; }
    .copy-btn { width: 100%; }

    .list-plain li { flex-direction: column; align-items: flex-start; gap: 8px; }

    .auth-shell { margin: 40px auto; padding: 0 16px; }
}

@media (max-width: 400px) {
    .stat-grid { grid-template-columns: 1fr; }
    .sentiment-word { font-size: 24px; }
}

/* ---- Sidebar app shell (dashboard + admin) ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-width); flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
    padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 8px; padding: 0 8px 20px; font-weight: 700; font-size: 15px; }
.sidebar-brand .accent-dot { color: var(--accent); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a, .sidebar-nav button.tab-btn {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 7px;
    color: var(--text-muted); font-size: 13px; font-weight: 500; text-decoration: none;
    border: none; background: none; font-family: inherit; cursor: pointer; text-align: left; width: 100%;
}
.sidebar-nav a:hover, .sidebar-nav button.tab-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-nav a.active, .sidebar-nav button.tab-btn.active { background: var(--surface-2); color: var(--text); font-weight: 700; }
.sidebar-nav a.active::before, .sidebar-nav button.tab-btn.active::before { content: ''; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; position: relative; }
.sidebar-user-btn {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 7px;
    background: none; border: none; cursor: pointer; color: var(--text); font-family: inherit; text-align: left;
}
.sidebar-user-btn:hover { background: var(--surface-2); }
.sidebar-user-avatar {
    width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar-user-email { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-menu {
    display: none; position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 8px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.sidebar-user-menu.open { display: block; }
.sidebar-user-menu a, .sidebar-user-menu button {
    display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; border: none;
    background: none; color: var(--text); font-size: 13px; font-family: inherit; cursor: pointer;
}
.sidebar-user-menu a:hover, .sidebar-user-menu button:hover { background: var(--surface); text-decoration: none; }

.main-content { flex: 1; min-width: 0; padding: 28px 32px; max-width: 1100px; }

/* ---- Mobile: hamburger + slide-out drawer, not horizontal scroll ----
   Squeezing the sidebar into a horizontally-scrolling top bar hid the
   logout option entirely on mobile (it got pushed past the visible
   edge with no indication more content existed). A drawer guarantees
   every nav item and the logout button are always fully visible and
   tappable, full-width, no truncation. */
.mobile-topbar {
    display: none; align-items: center; justify-content: space-between;
    padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 0; z-index: 20;
}
.mobile-topbar .sidebar-brand { padding: 0; }
.hamburger-btn {
    width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.drawer-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 29;
}
.drawer-backdrop.visible { display: block; }

@media (max-width: 780px) {
    .app-shell { flex-direction: column; }
    .mobile-topbar { display: flex; }

    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; width: 78%; max-width: 320px;
        transform: translateX(-100%); transition: transform 0.2s ease; z-index: 30;
        flex-direction: column; overflow-y: auto; overflow-x: hidden;
        box-shadow: 8px 0 24px rgba(0,0,0,0.4);
    }
    .sidebar.drawer-open { transform: translateX(0); }
    .sidebar .sidebar-brand { display: none; } /* already shown in .mobile-topbar, avoid duplicating */

    .sidebar-nav { flex-direction: column; }
    .sidebar-footer { border-top: 1px solid var(--border); border-left: none; padding: 12px 0 0; margin-left: 0; }

    .main-content { padding: 20px 16px; }
}

/* ---- Google sign-in button ---- */
.btn-google {
    display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
    padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
    color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-google:hover { border-color: var(--accent); text-decoration: none; color: var(--text); }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 12px; margin: 16px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---- Stat cards (premium overview grid) ---- */
.stat-card-v2 { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.stat-card-v2 .stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.stat-card-v2 .stat-value { font-size: 22px; font-weight: 700; font-family: var(--font-mono); }
