/* Tokens and base. MiPi/Hydra is the reference grammar; Biletix owns this runtime contract. */
:root,
.theme-dark {
    color-scheme: dark;
    --background: #080808;
    --foreground: #e7e5e4;
    --muted: #151515;
    --muted-foreground: #a1a1aa;
    --card: #111111;
    --card-foreground: #e7e5e4;
    --border: #292929;
    --input: #3a3a3a;
    --secondary: #181818;
    --secondary-foreground: #d4d4d8;
    --accent: #242424;
    --accent-foreground: #f4f4f5;
    --primary: #e7e5e4;
    --primary-foreground: #0a0a0a;
    --ai-accent: #4ade80;
    --ai-accent-hover: #86efac;
    --ai-accent-soft: rgba(74, 222, 128, .10);
    --ai-accent-border: rgba(74, 222, 128, .28);
    --ai-accent-text: #86efac;
    --ai-accent-foreground: #052e16;
    --focus-ring: #a5b4fc;
    --success: #86efac;
    --success-soft: rgba(134, 239, 172, .10);
    --warning: #fcd34d;
    --warning-soft: rgba(252, 211, 77, .11);
    --danger: #fda4af;
    --danger-soft: rgba(253, 164, 175, .12);
    --info: #93c5fd;
    --info-soft: rgba(147, 197, 253, .11);
    --radius: .625rem;
    --shadow: 0 18px 48px rgba(0, 0, 0, .28);
    --scrollbar-size: 10px;
    --scrollbar-track: rgba(255, 255, 255, .04);
    --scrollbar-thumb: rgba(255, 255, 255, .16);
    --scrollbar-thumb-hover: rgba(255, 255, 255, .28);
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

.theme-light {
    color-scheme: light;
    --background: #f8fafc;
    --foreground: #0f172a;
    --muted: #f1f5f9;
    --muted-foreground: #64748b;
    --card: #fff;
    --card-foreground: #0f172a;
    --border: #e2e8f0;
    --input: #cbd5e1;
    --secondary: #f1f5f9;
    --secondary-foreground: #0f172a;
    --accent: #dbeafe;
    --accent-foreground: #1e3a8a;
    --primary: #2563eb;
    --primary-foreground: #fff;
    --ai-accent: #16a34a;
    --ai-accent-hover: #15803d;
    --ai-accent-soft: rgba(22, 163, 74, .09);
    --ai-accent-border: rgba(22, 163, 74, .26);
    --ai-accent-text: #15803d;
    --ai-accent-foreground: #fff;
    --focus-ring: #1d4ed8;
    --success: #15803d;
    --success-soft: rgba(22, 163, 74, .10);
    --warning: #a16207;
    --warning-soft: rgba(202, 138, 4, .12);
    --danger: #be123c;
    --danger-soft: rgba(225, 29, 72, .10);
    --info: #2563eb;
    --info-soft: rgba(37, 99, 235, .10);
    --shadow: 0 18px 48px rgba(15, 23, 42, .12);
    --scrollbar-track: rgba(15, 23, 42, .06);
    --scrollbar-thumb: rgba(15, 23, 42, .22);
    --scrollbar-thumb-hover: rgba(15, 23, 42, .36);
}

* { box-sizing: border-box; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track); scrollbar-width: thin; }
*::-webkit-scrollbar { height: var(--scrollbar-size); width: var(--scrollbar-size); }
*::-webkit-scrollbar-track { background: var(--scrollbar-track); border-radius: 999px; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border: 2px solid transparent; background-clip: padding-box; border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); background-clip: padding-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: clip; }
body { background: radial-gradient(circle at top right, rgba(244, 244, 245, .035), transparent 34rem), var(--background); color: var(--foreground); font-family: var(--font-sans); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
code, pre { font-family: var(--font-mono); max-width: 100%; }
code { overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
::selection { background: var(--accent); color: var(--accent-foreground); }

/* Shell */
.app-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.app-main { max-width: 100%; min-width: 0; }
.app-sidebar { align-self: start; background: rgba(14, 14, 14, .92); backdrop-filter: blur(12px); border-right: 1px solid var(--border); display: flex; flex-direction: column; height: 100vh; max-height: 100vh; overflow-y: auto; padding: 16px; position: sticky; top: 0; }
.theme-light .app-sidebar { background: rgba(255, 255, 255, .92); }
.sidebar-brand { align-items: center; border-bottom: 1px solid var(--border); display: flex; min-height: 44px; padding: 0 6px 12px; }
.brand { color: var(--foreground); font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.sidebar-nav { display: flex; flex: 1; flex-direction: column; gap: 12px; padding-top: 12px; }
.nav-section { display: grid; gap: 4px; min-width: 0; }
.nav-section + .nav-section { border-top: 1px solid var(--border); padding-top: 12px; }
.nav-section-bottom { margin-top: auto; }
.nav-section-title { color: var(--muted-foreground); font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 0 10px 3px; text-transform: uppercase; }
.nav-item { align-items: center; background: transparent; border: 0; border-radius: 8px; color: var(--muted-foreground); display: flex; font-weight: 500; gap: 9px; min-height: 34px; padding: 0 10px; position: relative; transition: background-color 120ms ease, color 120ms ease; }
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item-active { background: rgba(244, 244, 245, .075); color: var(--foreground); }
.nav-item-active::before { background: var(--foreground); border-radius: 999px; content: ""; height: 16px; left: 0; opacity: .86; position: absolute; width: 2px; }
.nav-item-icon { align-items: center; display: inline-flex; height: 18px; justify-content: center; width: 18px; }
.nav-item-icon svg, .btn-icon svg { height: 18px; width: 18px; }
.app-topbar { align-items: center; background: rgba(8, 8, 8, .88); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); display: flex; gap: 16px; justify-content: space-between; min-height: 64px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.theme-light .app-topbar { background: rgba(248, 250, 252, .90); }
.topbar-product { color: var(--muted-foreground); font-size: 13px; font-weight: 600; }
.topbar-actions { align-items: center; display: flex; gap: 4px; }
.theme-toggle-icon { display: inline-flex; font-size: 17px; justify-content: center; line-height: 1; width: 18px; }
.app-content { display: flex; flex-direction: column; gap: 16px; margin: 0 auto; max-width: 1180px; padding: 24px; width: 100%; }
.app-content > section { display: grid; gap: 16px; }

/* Page and layout primitives */
.page-header { display: grid; gap: 8px; min-width: 0; }
.page-header-main { align-items: flex-end; display: flex; gap: 20px; justify-content: space-between; min-width: 0; }
.page-header-copy { flex: 1 1 320px; min-width: 0; }
.page-header h1 { font-size: 28px; font-weight: 700; line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
.page-header p { color: var(--muted-foreground); margin: 0; max-width: 760px; overflow-wrap: anywhere; }
.breadcrumbs { color: var(--muted-foreground); font-size: 12px; font-weight: 600; }
.breadcrumb-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.breadcrumb-item { align-items: center; display: inline-flex; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.breadcrumb-item:not(.breadcrumb-current)::after { color: var(--border); content: "/"; }
.breadcrumb-list a:hover { color: var(--foreground); }
.breadcrumb-current { color: var(--foreground); }
.page-actions { align-items: center; display: flex; flex: 0 1 auto; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin: 0; min-width: 0; }
.responsive-grid { display: grid; gap: 20px; }
.content-sidebar-layout { grid-template-columns: minmax(0, 2fr) minmax(240px, .7fr); }
.stack { display: grid; gap: 16px; }

.card { background: rgba(17, 17, 17, .86); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin: 0; min-width: 0; overflow: hidden; }
.theme-light .card { background: var(--card); }
.card-header { align-items: flex-start; border-bottom: 1px solid var(--border); display: flex; gap: 16px; justify-content: space-between; padding: 16px; }
.card-header > :first-child { min-width: 0; }
.card-title { font-size: 16px; font-weight: 650; line-height: 1.3; margin: 0; }
.card-description { color: var(--muted-foreground); font-size: 13px; margin: 4px 0 0; overflow-wrap: anywhere; }
.card-content { padding: 16px; }
.card-content-flush { padding: 0; }
.card-footer { align-items: center; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 12px 16px; }

/* Controls and forms */
.btn { align-items: center; appearance: none; background: transparent; border: 1px solid transparent; border-radius: calc(var(--radius) - 2px); cursor: pointer; display: inline-flex; font-weight: 500; gap: 8px; justify-content: center; max-width: 100%; min-height: 36px; overflow-wrap: anywhere; padding: 8px 14px; transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { filter: brightness(.94); }
.btn-ai { background: var(--ai-accent); border-color: var(--ai-accent); box-shadow: 0 10px 24px var(--ai-accent-soft); color: var(--ai-accent-foreground); }
.btn-ai:hover { background: var(--ai-accent-hover); border-color: var(--ai-accent-hover); }
.btn-secondary { background: var(--secondary); border-color: var(--border); color: var(--secondary-foreground); }
.btn-secondary:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted-foreground); }
.btn-ghost:hover { background: var(--muted); color: var(--foreground); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #1f1114; }
.theme-light .btn-danger { color: #fff; }
.btn-small { font-size: 12px; min-height: 32px; padding: 5px 10px; }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: .55; pointer-events: none; }
.form-field { align-content: start; display: grid; gap: 7px; min-width: 0; }
.form-label { color: var(--foreground); font-size: 13px; font-weight: 700; }
.form-hint { color: var(--muted-foreground); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.form-support { display: grid; gap: 3px; min-width: 0; }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid > .form-field { align-content: start; }
.form-field-wide, .form-grid > .form-actions { grid-column: 1 / -1; }
.input, .textarea, .file-input { appearance: none; background: rgba(8, 8, 8, .72); border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px); color: var(--foreground); min-height: 36px; padding: .55rem .75rem; width: 100%; }
.theme-light .input, .theme-light .textarea, .theme-light .file-input { background: var(--card); }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); opacity: .72; }
.input:focus, .textarea:focus, .file-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.textarea { line-height: 1.55; min-height: 120px; resize: vertical; }
.textarea-analysis { min-height: 16rem; }
.source-switch { border: 0; display: flex; flex-wrap: wrap; gap: 10px 20px; margin: 0; padding: 0; }
.source-switch legend { font-size: 13px; font-weight: 700; margin-bottom: 7px; width: 100%; }
.radio-option { align-items: center; cursor: pointer; display: inline-flex; gap: 7px; }
.row-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.inline-form { align-items: center; display: inline-flex; margin: 0; }
.field-error { color: var(--danger); font-size: 12px; margin: 0; overflow-wrap: anywhere; }

/* Feedback and status */
.badge { align-items: center; border: 1px solid var(--border); border-radius: 999px; display: inline-flex; flex: 0 0 auto; font-size: 11px; font-weight: 800; gap: 6px; line-height: 1rem; padding: 3px 8px; text-transform: uppercase; white-space: nowrap; width: fit-content; }
.status-new { background: var(--info-soft); color: var(--info); }
.status-processing { background: var(--warning-soft); color: var(--warning); }
.status-success { background: var(--success-soft); color: var(--success); }
.status-failed { background: var(--danger-soft); color: var(--danger); }
.alert { border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 3px; margin: 0; padding: 12px 14px; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.secondary-text { color: var(--muted-foreground); overflow-wrap: anywhere; }

/* Data display and navigation */
.table-panel { max-width: 100%; min-width: 0; overflow-x: auto; }
.data-table { border-collapse: collapse; table-layout: auto; width: 100%; }
.data-table th, .data-table td { border-top: 1px solid var(--border); padding: 12px 16px; text-align: left; vertical-align: middle; }
.data-table thead th { background: var(--muted); border-top: 0; color: var(--muted-foreground); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.data-table tbody tr:first-child > * { border-top: 0; }
.data-table td, .data-table td > * { max-width: min(52vw, 36rem); overflow-wrap: anywhere; }
.data-table-cell-actions { white-space: nowrap; width: 1%; }
.data-table .row-actions { flex-wrap: nowrap; }
.metadata-list { display: grid; gap: 12px; min-width: 0; }
.metadata-list-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metadata-list-surface > .metadata-item { background: var(--muted); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); padding: 13px; }
.metadata-item { align-content: start; display: grid; gap: 5px; min-width: 0; }
.metadata-label { color: var(--muted-foreground); font-size: 12px; }
.metadata-value { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.technical-value { font-family: var(--font-mono); overflow-wrap: anywhere; word-break: break-word; }
.empty-state { color: var(--muted-foreground); display: grid; gap: 5px; padding: 42px 22px; text-align: center; }
.empty-state h2 { color: var(--foreground); font-size: 15px; margin: 0 0 5px; }
.empty-state p { margin: 0 auto; max-width: 560px; }
.pagination { align-items: center; display: flex; gap: 10px; justify-content: center; }
.page-link { background: var(--secondary); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); min-width: 34px; padding: 7px 10px; text-align: center; }
.page-link:hover { background: var(--accent); }
.page-link-current { color: var(--muted-foreground); }
.disclosure { border-top: 1px solid var(--border); min-width: 0; padding-top: 8px; }
.disclosure > summary { color: var(--muted-foreground); cursor: pointer; font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.disclosure > summary:hover { color: var(--foreground); }
.disclosure-body { display: grid; gap: 12px; margin-top: 12px; min-width: 0; }
.code-block { background: var(--background); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); color: var(--card-foreground); margin: 0; max-height: 38rem; overflow: auto; padding: 14px; white-space: pre-wrap; word-break: break-word; }
.generated-surface { border-color: var(--ai-accent-border); box-shadow: inset 2px 0 0 var(--ai-accent-border); }
.generated-surface .card-header { border-bottom-color: var(--ai-accent-border); }
.ai-badge { background: var(--ai-accent-soft); border-color: var(--ai-accent-border); color: var(--ai-accent-text); }
.ai-heading { color: var(--ai-accent-text); }

/* Analysis feature surfaces */
.analysis-workspace { grid-template-columns: minmax(0, 1fr); }
.result-sections { display: grid; gap: 0; }
.result-section { border-top: 1px solid var(--border); padding: 16px; }
.result-section:first-child { border-top: 0; }
.result-section h3 { font-size: 14px; margin: 0 0 8px; }
.result-section p, .result-section ul { margin-bottom: 0; margin-top: 8px; }
.detail-list li + li, .evidence + .evidence { margin-top: 10px; }
.evidence { background: var(--muted); border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); padding: 12px 14px; }
.evidence blockquote { font-weight: 600; margin: 0; }
.evidence p { color: var(--muted-foreground); margin-bottom: 0; }
.unknown-notice { border-left: 3px solid var(--warning); }
.source-panel { display: grid; gap: 10px; }
.source-panel[hidden] { display: none; }
.original-input { max-height: 30rem; }
.provider-response-details { padding: 0; }
.provider-response-details > summary { cursor: pointer; font-size: 14px; font-weight: 700; padding: 16px; }
.provider-response-details[open] > summary { border-bottom: 1px solid var(--border); }
.provider-response-details .disclosure-body { margin: 0; padding: 16px; }

/* Authentication */
.auth-page { align-items: center; display: flex; justify-content: center; min-height: 100vh; padding: 28px; }
.auth-card { max-width: 420px; width: 100%; }
.auth-brand { border-bottom: 1px solid var(--border); display: flex; justify-content: center; padding: 24px 20px 18px; }
.auth-brand .brand { font-size: 22px; }
.auth-card .card-header { display: block; text-align: center; }
.auth-card .btn-primary { width: 100%; }
.auth-theme { position: fixed; right: 16px; top: 16px; z-index: 2; }

/* Responsive overrides */
@media (max-width: 860px) {
    .app-shell { grid-template-columns: minmax(0, 1fr); }
    .app-sidebar { border-bottom: 1px solid var(--border); border-right: 0; height: auto; max-height: none; padding: 10px 14px; position: static; }
    .sidebar-brand { border-bottom: 0; min-height: 34px; padding: 0 4px 8px; }
    .sidebar-nav { display: grid; gap: 8px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); padding: 0; }
    .nav-section { display: flex; overflow-x: auto; }
    .nav-section + .nav-section { border-left: 1px solid var(--border); border-top: 0; padding-left: 8px; padding-top: 0; }
    .nav-section-bottom { margin: 0; }
    .nav-section-title { display: none; }
    .nav-item { flex: 1 0 auto; }
    .nav-item-active::before { bottom: -1px; height: 3px; left: 10px; width: calc(100% - 20px); }
    .app-topbar { min-height: 54px; padding: 0 18px; }
    .app-content { padding: 26px 20px 44px; }
    .content-sidebar-layout { grid-template-columns: minmax(0, 1fr); }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .form-field-wide { grid-column: auto; }
    .metadata-list-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .sidebar-brand { display: none; }
    .sidebar-nav { grid-template-columns: minmax(0, 1fr); }
    .nav-section + .nav-section { border-left: 0; padding-left: 0; }
    .nav-item { justify-content: center; min-width: 44px; padding: 8px; }
    .nav-item > span:last-child { display: none; }
    .nav-item-icon, .nav-item-icon svg { height: 20px; width: 20px; }
    .topbar-product { font-size: 12px; }
    .topbar-action-label { position: absolute; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; width: 1px; }
    .app-content { padding: 22px 14px 36px; }
    .page-header-main { align-items: flex-start; flex-direction: column; }
    .page-actions { justify-content: stretch; width: 100%; }
    .page-actions .btn { width: 100%; }
    .card-header { flex-wrap: wrap; }
    .data-table th, .data-table td { padding: 10px 12px; }
    .metadata-list-3 { grid-template-columns: minmax(0, 1fr); }
    .auth-page { padding: 72px 14px 24px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
