/* ============================================================
   App pages — sidebar layout, dashboard, chat, etc.
   ============================================================ */

.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    border-right: 1px solid var(--line);
    background: var(--bg-elev);
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--line);
}

.sidebar .brand {
    padding: 8px 10px;
}

.sidebar .brand small {
    display: none;
}

.side-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.side-heading {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 12px 10px 6px;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-dim);
    font-size: 14px;
    transition: all 0.15s;
}

.side-link:hover {
    background: var(--bg-elev-2);
    color: var(--text);
}

.side-link.active {
    background: var(--bg-elev-2);
    color: var(--text);
    border: 1px solid var(--line);
}

.side-link .side-ico {
    width: 16px;
    height: 16px;
    color: var(--text-faint);
    flex-shrink: 0;
}

.side-link.active .side-ico {
    color: var(--accent);
}

.side-footer {
    margin-top: auto;
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-elev-2);
    border: 1px solid var(--line);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--grad-edge);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fraunces', serif;
    font-size: 15px;
    font-weight: 500;
    color: white;
    flex-shrink: 0;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-tokens {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-faint);
}

.user-tokens .accent {
    color: var(--accent);
}

/* ---------- Main area ---------- */
.main {
    padding: 28px 40px 60px;
    min-width: 0;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 32px;
    gap: 24px;
    flex-wrap: wrap;
}

.page-title {
    font-family: 'Fraunces', serif;
    font-size: 40px;
    letter-spacing: -0.025em;
    line-height: 1;
}

.page-eyebrow {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.14em;
    color: var(--text-faint);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.page-sub {
    color: var(--text-dim);
    font-size: 15px;
    margin-top: 8px;
}

/* ---------- Stat tiles (dashboard) ---------- */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.tile {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.tile .tile-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.1em;
    color: var(--text-faint);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.tile .tile-value {
    font-family: 'Fraunces', serif;
    font-size: 36px;
    letter-spacing: -0.03em;
    line-height: 1;
}

.tile .tile-value small {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    color: var(--text-dim);
    margin-left: 6px;
    font-weight: 400;
}

.tile .tile-spark {
    margin-top: 14px;
    height: 28px;
}

@media (max-width: 1100px) {
    .tile-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

[dir="rtl"] .table th,
[dir="rtl"] .table td {
    text-align: right;
}

.table th {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
}

.table tr:hover td {
    background: var(--bg-elev-2);
}

/* ---------- Empty state ---------- */
.empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
}

.empty-art {
    font-family: 'Fraunces', serif;
    font-size: 72px;
    color: var(--text-faint);
    margin-bottom: 16px;
    line-height: 1;
}

.empty h3 {
    font-family: 'Fraunces', serif;
    font-size: 24px;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

/* ---------- Mobile sidebar collapse ---------- */
@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s;
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main {
        padding: 20px 18px 40px;
    }

    .mobile-bar {
        display: flex !important;
        align-items: center;
        gap: 12px;
        padding: 14px 0;
        margin-bottom: 16px;
        border-bottom: 1px solid var(--line);
    }
}

.mobile-bar {
    display: none;
}

/* ---------- Auth page ---------- */
.auth-wrap {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}

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

.auth-art {
    background: var(--bg-elev);
    border-right: 1px solid var(--line);
    position: relative;
    overflow: hidden;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

[dir="rtl"] .auth-art {
    border-right: none;
    border-left: 1px solid var(--line);
}

.auth-art::before {
    content: '';
    position: absolute;
    inset: -10%;
    background:
        radial-gradient(circle at 30% 20%, var(--accent-glow), transparent 40%),
        radial-gradient(circle at 70% 80%, rgba(124, 92, 252, 0.3), transparent 50%);
    opacity: 0.6;
    filter: blur(40px);
}

.auth-art>* {
    position: relative;
}

.auth-quote {
    font-family: 'Fraunces', serif;
    font-size: 36px;
    line-height: 1.2;
    letter-spacing: -0.02em;
    max-width: 480px;
    margin: auto 0;
}

.auth-quote em {
    color: var(--accent);
    font-style: italic;
}

.auth-quote-by {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-faint);
    letter-spacing: 0.12em;
    margin-top: 24px;
    text-transform: uppercase;
}

@media (max-width: 900px) {
    .auth-art {
        min-height: 280px;
        padding: 32px;
    }

    .auth-quote {
        font-size: 24px;
    }
}

.auth-panel {
    padding: 60px 8%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.auth-panel-inner {
    max-width: 400px;
    width: 100%;
    margin: 0 auto;
}

.auth-panel h1 {
    font-family: 'Fraunces', serif;
    font-size: 42px;
    letter-spacing: -0.025em;
    margin-bottom: 12px;
}

.auth-panel .auth-sub {
    color: var(--text-dim);
    margin-bottom: 32px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
    color: var(--text-faint);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}

.btn-google {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 13px 20px;
    width: 100%;
    justify-content: center;
}

.btn-google:hover {
    border-color: var(--text-dim);
}

.auth-switch {
    margin-top: 24px;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
}

.auth-switch a {
    color: var(--accent);
}

/* ============================================================
   RESPONSIVE — Mobile & Tablet
   ============================================================ */

/* Hamburger button (mobile only) */
.hamburger {
    display: none;
    position: fixed;
    top: calc(14px + env(safe-area-inset-top, 0px));
    right: 14px;
    left: auto;
    z-index: 200;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-elev);
    border: 1px solid var(--line);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
}

.hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: all .2s;
}

/* Sidebar overlay on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 10000;
    backdrop-filter: blur(2px);
}

/* ── Tablet (≤ 900px) ─────────────────────────────────────── */
@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 220px 1fr;
    }

    .main {
        padding: 24px 20px;
    }

    .page-title {
        font-size: 32px !important;
    }

    .metric-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .row {
        flex-wrap: wrap;
    }
}

/* ── Mobile (≤ 640px) ─────────────────────────────────────── */
@media (max-width: 640px) {

    /* Show hamburger */
    .hamburger {
        display: flex;
    }

    /* Sidebar becomes overlay drawer */
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        z-index: 10050;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, .4);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    /* Main content full width */
    .main {
        padding: 70px 16px 24px;
        width: 100%;
    }

    /* Typography */
    .page-title {
        font-size: 26px !important;
    }

    .page-sub {
        font-size: 14px !important;
    }

    .display {
        font-size: 28px !important;
    }

    /* Page head stacks vertically */
    .page-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    /* Cards full width */
    .card {
        padding: 16px;
    }

    /* Metrics 2 columns */
    .metric-row {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .metric-card .mv {
        font-size: 26px !important;
    }

    /* Tables scroll horizontally */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Rows stack */
    .row {
        flex-direction: column;
        gap: 10px !important;
    }

    /* Selects full width */
    .field {
        width: 100% !important;
        min-width: unset !important;
    }

    select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"] {
        width: 100% !important;
    }

    /* Buttons full width in forms */
    .btn-accent,
    .btn-ghost,
    .btn {
        width: 100%;
        justify-content: center;
    }

    /* Log box smaller on mobile */
    .log-box {
        max-height: 240px !important;
        font-size: 11px !important;
    }

    /* Training tabs */
    .train-tab {
        padding: 10px 16px !important;
        font-size: 13px !important;
    }

    /* DL type grid: 1 column */
    .dl-type-grid {
        grid-template-columns: 1fr !important;
    }

    /* Plan grid: 1 column */
    .plan-grid {
        grid-template-columns: 1fr !important;
    }

    /* Chat */
    .chat-input-row {
        flex-direction: row !important;
    }

    .chat-bubble {
        max-width: 90% !important;
    }

    /* User chip compact */
    .user-name {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Hide brand text on very small screens */
    .brand strong {
        font-size: 15px;
    }
}

/* ── Very small (≤ 380px) ─────────────────────────────────── */
@media (max-width: 380px) {
    .main {
        padding: 64px 12px 20px;
    }

    .metric-row {
        grid-template-columns: 1fr 1fr !important;
    }

    .metric-card {
        padding: 12px !important;
    }

    .metric-card .mv {
        font-size: 22px !important;
    }
}