/* ============================================================
   FARO Ticketing — design system
   Tema chiaro/scuro automatico (prefers-color-scheme) con override
   manuale via html[data-theme="light|dark"].
   ============================================================ */

:root {
  --font: "Karla", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-head: "Montserrat", var(--font);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --brand: #c80008;
  --brand-600: #950006;
  --brand-100: #fbe3e3;
  --accent: #2563eb;
  --accent-600: #1d4ed8;
  --accent-100: #dbeafe;
  --ok: #16a34a;   --ok-100: #dcfce7;
  --warn: #d97706; --warn-100: #fef3c7;
  --danger: #dc2626; --danger-100: #fee2e2;
  --info: #0284c7; --info-100: #e0f2fe;
  --violet: #7c3aed; --violet-100: #ede9fe;
  --teal: #0d9488; --teal-100: #ccfbf1;
  --orange: #ea580c; --orange-100: #ffedd5;

  --bg: #f4f6fa;
  --bg-2: #eceff5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: rgba(255,255,255,.08);
  --sidebar-hover: rgba(255,255,255,.05);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px -4px rgba(15,23,42,.08);
  --shadow-lg: 0 10px 30px -10px rgba(15,23,42,.25);
  --ring: 0 0 0 3px rgba(37,99,235,.25);
  --radius: 12px;
  --radius-sm: 8px;
  --r-xs: 6px;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --is-dark: 1; }
}
:root[data-theme="dark"] { --is-dark: 1; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1220; --bg-2: #0f172a; --surface: #111a2b; --surface-2: #162036; --surface-3: #1b2740;
    --text: #e5e9f0; --text-2: #a7b3c6; --text-3: #6b7a93; --line: #223049; --line-2: #2f4062;
    --sidebar-bg: #0a0f1c; --sidebar-text: #8b98ad;
    --brand-100: rgba(200,0,8,.2); --accent-100: rgba(37,99,235,.2); --ok-100: rgba(22,163,74,.18); --warn-100: rgba(217,119,6,.2);
    --danger-100: rgba(220,38,38,.2); --info-100: rgba(2,132,199,.2); --violet-100: rgba(124,58,237,.22); --teal-100: rgba(13,148,136,.2); --orange-100: rgba(234,88,12,.2);
    --ok: #4ade80; --warn: #fbbf24; --danger: #f87171; --info: #38bdf8; --violet: #a78bfa; --teal: #2dd4bf; --orange: #fb923c; --accent: #60a5fa; --accent-600: #3b82f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.5), 0 6px 16px -6px rgba(0,0,0,.6); --shadow-lg: 0 16px 40px -12px rgba(0,0,0,.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220; --bg-2: #0f172a; --surface: #111a2b; --surface-2: #162036; --surface-3: #1b2740;
  --text: #e5e9f0; --text-2: #a7b3c6; --text-3: #6b7a93; --line: #223049; --line-2: #2f4062;
  --sidebar-bg: #0a0f1c; --sidebar-text: #8b98ad;
  --brand-100: rgba(200,0,8,.2); --accent-100: rgba(37,99,235,.2); --ok-100: rgba(22,163,74,.18); --warn-100: rgba(217,119,6,.2);
  --danger-100: rgba(220,38,38,.2); --info-100: rgba(2,132,199,.2); --violet-100: rgba(124,58,237,.22); --teal-100: rgba(13,148,136,.2); --orange-100: rgba(234,88,12,.2);
  --ok: #4ade80; --warn: #fbbf24; --danger: #f87171; --info: #38bdf8; --violet: #a78bfa; --teal: #2dd4bf; --orange: #fb923c; --accent: #60a5fa; --accent-600: #3b82f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.5), 0 6px 16px -6px rgba(0,0,0,.6); --shadow-lg: 0 16px 40px -12px rgba(0,0,0,.7);
}

/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; font-family: var(--font); font-size: 14.5px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-family: var(--font-head); font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; }
h3 { font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: 0 0 .6rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
pre.code { background: var(--surface-3); color: var(--text); border: 1px solid var(--line); padding: .8rem 1rem; border-radius: var(--radius-sm); overflow: auto; font: .78rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-3); padding: .1em .35em; border-radius: 4px; }
::selection { background: var(--accent-100); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-xs); }

.muted { color: var(--text-2); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }
.flex { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.space { justify-content: space-between; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100dvh; }
.sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; flex-shrink: 0; z-index: 40; transition: transform .25s ease; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem .9rem; color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand small { display: block; font-weight: 500; font-size: .62rem; color: var(--sidebar-text); letter-spacing: .14em; text-transform: uppercase; }
.brand-mark { display: inline-flex; width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #ff6b6b); align-items: center; justify-content: center; font-weight: 800; color: #fff; box-shadow: 0 4px 12px -2px rgba(215,38,61,.5); }
.sidebar nav { display: flex; flex-direction: column; padding: .3rem .7rem; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav a { color: var(--sidebar-text); padding: .55rem .75rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; display: flex; align-items: center; gap: .6rem; transition: background .15s, color .15s; }
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.sidebar nav a:hover { background: var(--sidebar-hover); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar nav a.active svg { opacity: 1; color: #ff7b8a; }
.nav-section { font-size: .65rem; text-transform: uppercase; letter-spacing: .12em; color: #556179; padding: 1rem .75rem .35rem; font-weight: 600; }
.sidebar-footer { padding: .8rem .9rem; border-top: 1px solid rgba(255,255,255,.07); display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.sidebar-footer .user { color: #fff; display: flex; flex-direction: column; font-size: .85rem; min-width: 0; }
.sidebar-footer .user small { color: var(--sidebar-text); }
.sidebar-footer .user strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .btn-ghost { color: var(--sidebar-text); }
.sidebar-footer .btn-ghost:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 39; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: 0 1.4rem; min-height: var(--topbar-h); display: flex; align-items: center; gap: .8rem; position: sticky; top: 0; z-index: 30; }
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-toggle { display: none; }
.content { padding: 1.3rem 1.4rem 4rem; max-width: 1560px; width: 100%; }
#page { display: contents; }
.page-loading .content { opacity: .55; pointer-events: none; transition: opacity .15s; }
.progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: linear-gradient(90deg, var(--brand), var(--accent)); z-index: 100; transition: width .3s ease, opacity .3s; opacity: 0; }
.page-loading .progress { opacity: 1; width: 70%; }

/* ---------- cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.1rem; box-shadow: var(--shadow-sm); }
.card > h2:first-child { margin-bottom: .8rem; }
.card.narrow { max-width: 600px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 1.1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 1.1rem; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 1.1rem; align-items: start; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; color: var(--text); box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s, border-color .15s; }
.stat:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--line-2); }
.stat-n { font-size: 1.75rem; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-l { font-size: .78rem; color: var(--text-2); margin-top: .15rem; }
.stat-danger .stat-n { color: var(--danger); }
.stat-accent .stat-n { color: var(--accent); }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }
.kpi { padding: .7rem .9rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.kpi-n { display: block; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-l { font-size: .75rem; color: var(--text-2); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -.25rem; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .88rem; }
.table th, .table td { text-align: left; padding: .6rem .65rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table thead th:first-child { border-top-left-radius: var(--r-xs); } .table thead th:last-child { border-top-right-radius: var(--r-xs); }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact th, .table.compact td { padding: .42rem .55rem; }
.table .row-urgent td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th.sortable::after { content: "↕"; opacity: .35; margin-left: .3rem; font-size: .75rem; }
.table th.sort-asc::after { content: "↑"; opacity: 1; color: var(--accent); }
.table th.sort-desc::after { content: "↓"; opacity: 1; color: var(--accent); }
.table tr.filter-row th { padding: .25rem .4rem; background: var(--surface); position: sticky; top: 33px; }
.table tr.filter-row input { width: 100%; min-width: 60px; padding: .3rem .45rem; font-size: .78rem; border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--surface); color: var(--text); font-weight: 400; text-transform: none; letter-spacing: 0; }
.table tr.filter-row input:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.table tbody tr.no-match { display: none; }
.table .empty-filter td { color: var(--text-3); text-align: center; padding: 1.2rem; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .14rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.4; }
.badge.ok { background: var(--ok-100); color: var(--ok); }
.badge.ko, .badge.danger { background: var(--danger-100); color: var(--danger); }
.badge.warn { background: var(--warn-100); color: var(--warn); }
.badge.info { background: var(--info-100); color: var(--info); }
.st-new { background: var(--info-100); color: var(--info); }
.st-triage { background: var(--violet-100); color: var(--violet); }
.st-waiting_customer { background: var(--warn-100); color: var(--warn); }
.st-waiting_partner { background: var(--orange-100); color: var(--orange); }
.st-planned { background: var(--teal-100); color: var(--teal); }
.st-in_progress { background: var(--ok-100); color: var(--ok); }
.st-resolved { background: var(--ok-100); color: var(--ok); }
.st-closed { background: var(--surface-3); color: var(--text-2); }
.ur-alta { background: var(--danger-100); color: var(--danger); }
.ur-media { background: var(--warn-100); color: var(--warn); }
.ur-bassa { background: var(--surface-3); color: var(--text-2); }
.badge-ai { background: linear-gradient(135deg, #4f46e5, #9333ea); color: #fff; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem .95rem; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-size: .875rem; font-weight: 500; line-height: 1.25; cursor: pointer; font-family: inherit; transition: background .12s, border-color .12s, transform .05s, box-shadow .12s; white-space: nowrap; box-shadow: var(--shadow-sm); }
.btn:hover { background: var(--surface-2); border-color: var(--text-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-600); border-color: var(--accent-600); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.92); color: #fff; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: var(--surface); }
.btn-danger:hover { background: var(--danger-100); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); box-shadow: none; }
.btn-ghost:hover { background: var(--accent-100); border-color: transparent; }
.btn-sm { padding: .32rem .65rem; font-size: .8rem; border-radius: var(--r-xs); }
.btn-block { width: 100%; }
.btn[disabled], .btn.loading { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn.loading::before { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.form label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .75rem; color: var(--text-2); }
.form label > input, .form label > select, .form label > textarea,
.form input:not([type=checkbox]):not([type=radio]):not([type=file]), .form select, .form textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font: inherit; font-size: .9rem; font-weight: 400; background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s;
}
.form input[type=file] { margin-top: .3rem; font-weight: 400; font-size: .85rem; color: var(--text-2); }
.form textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.form input[disabled], .form select[disabled], .form textarea[disabled] { background: var(--surface-3); color: var(--text-2); }
.form .inline, .form label.inline { display: flex; gap: .5rem; align-items: center; font-weight: 500; color: var(--text); }
.form .inline input { width: auto; margin: 0; }
.form input[type=checkbox], .form input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 0 1rem; }
.field-error { color: var(--danger); font-size: .78rem; margin: -.5rem 0 .7rem; }
.help { font-size: .78rem; color: var(--text-2); font-weight: 400; }
.filters { display: flex; gap: .55rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.filters label { font-size: .7rem; color: var(--text-2); display: flex; flex-direction: column; gap: .25rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.filters input, .filters select { padding: .42rem .6rem; border: 1px solid var(--line-2); border-radius: var(--r-xs); font: inherit; font-size: .85rem; background: var(--surface); color: var(--text); min-width: 120px; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.inline-form { display: inline; }
.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .35rem .9rem; }
.check-list label { display: flex; gap: .45rem; align-items: flex-start; font-weight: 400; font-size: .86rem; margin: 0; color: var(--text); }
.check-list input { margin-top: .2rem; }

/* combobox (select con ricerca) */
.combo { position: relative; margin-top: .3rem; }
.combo-input { display: block; width: 100%; padding: .55rem 2rem .55rem .7rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm); font: inherit; font-size: .9rem; background: var(--surface); color: var(--text); cursor: pointer; }
.filters .combo { margin: 0; } .filters .combo-input { padding: .42rem 1.8rem .42rem .6rem; font-size: .85rem; border-radius: var(--r-xs); }
.combo-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); cursor: text; }
.combo::after { content: ""; position: absolute; right: .75rem; top: 50%; width: 7px; height: 7px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); z-index: 50; padding: .3rem; display: none; }
.combo.open .combo-list { display: block; }
.combo-opt { padding: .45rem .6rem; border-radius: var(--r-xs); cursor: pointer; font-size: .88rem; font-weight: 400; color: var(--text); }
.combo-opt:hover, .combo-opt.hl { background: var(--accent-100); }
.combo-opt.selected { font-weight: 600; }
.combo-opt mark { background: none; color: var(--accent); font-weight: 700; }
.combo-empty { padding: .5rem .6rem; color: var(--text-3); font-size: .85rem; }
.combo select { display: none !important; }

/* ---------- flash / toast / dialog ---------- */
.flash { padding: .7rem 1rem; font-size: .88rem; border-radius: var(--radius-sm); border: 1px solid transparent; margin-bottom: .8rem; display: flex; gap: .6rem; align-items: flex-start; }
.flash-success { background: var(--ok-100); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.flash-error { background: var(--danger-100); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.flash-info { background: var(--info-100); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.flash-warning { background: var(--warn-100); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
#toasts { position: fixed; top: calc(var(--topbar-h) + .6rem); right: .9rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 1.8rem)); }
#toasts .flash { margin: 0; box-shadow: var(--shadow-lg); background: var(--surface); animation: toast-in .25s ease; }
#toasts .flash-success { border-left: 4px solid var(--ok); } #toasts .flash-error { border-left: 4px solid var(--danger); }
#toasts .flash-info { border-left: 4px solid var(--info); } #toasts .flash-warning { border-left: 4px solid var(--warn); }
#toasts .flash button { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1; opacity: .6; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); max-width: min(440px, 92vw); width: 100%; }
dialog::backdrop { background: rgba(2,6,23,.55); backdrop-filter: blur(2px); }
dialog .dialog-body { padding: 1.3rem 1.4rem .6rem; font-size: .95rem; }
dialog .dialog-body h3 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.05rem; margin-bottom: .4rem; }
dialog .dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .6rem 1.4rem 1.2rem; }

/* ---------- auth ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; background: radial-gradient(1200px 600px at 10% -10%, rgba(215,38,61,.35), transparent), radial-gradient(900px 500px at 110% 110%, rgba(37,99,235,.35), transparent), var(--sidebar-bg); padding: 1rem; }
.auth-card { background: var(--surface); padding: 2rem; border-radius: 16px; width: min(400px, 94vw); box-shadow: var(--shadow-lg); }
.auth-card .brand { padding: 0 0 1.3rem; color: var(--text); }
.auth-card .brand small { color: var(--text-2); }
.error-page { text-align: center; padding: 3rem 1rem; }
.error-page h2 { font-size: 2rem; }

/* ---------- ticket ---------- */
.ticket-head { display: flex; gap: 1.2rem; flex-wrap: wrap; align-items: flex-start; }
.ticket-head .meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .55rem 1rem; font-size: .87rem; flex: 1; margin: 0; }
.ticket-head .meta dt { color: var(--text-3); font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.ticket-head .meta dd { margin: 0; }
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .6rem .9rem; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; font-size: .88rem; white-space: nowrap; display: inline-flex; align-items: center; gap: .4rem; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--brand); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tab-panel { display: none; } .tab-panel.active { display: block; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.thread { display: flex; flex-direction: column; gap: .8rem; }
.msg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.msg-head { display: flex; justify-content: space-between; gap: .6rem; flex-wrap: wrap; padding: .55rem .9rem; border-bottom: 1px solid var(--line); font-size: .8rem; background: var(--surface-2); }
.msg-body { padding: .85rem .95rem; white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
.msg.in { border-left: 4px solid var(--accent); }
.msg.out { border-left: 4px solid var(--ok); }
.msg.note { border-left: 4px solid var(--warn); background: color-mix(in srgb, var(--warn-100) 40%, var(--surface)); }
.msg.system { border: 0; background: transparent; font-size: .78rem; color: var(--text-3); text-align: center; padding: .1rem; }
.msg .quoted { color: var(--text-3); display: none; }
.msg.show-quoted .quoted { display: block; }
.att-list { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0 .9rem .8rem; }
.att { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .35rem .6rem; font-size: .78rem; display: inline-flex; gap: .45rem; align-items: center; background: var(--surface); color: var(--text); }
.att:hover { border-color: var(--accent); text-decoration: none; }
.att img { max-height: 90px; border-radius: 4px; display: block; }
.ai-box { border: 1px solid color-mix(in srgb, var(--violet) 35%, var(--line)); background: color-mix(in srgb, var(--violet-100) 45%, var(--surface)); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.ai-box h3 { color: var(--violet); margin-bottom: .6rem; text-transform: none; letter-spacing: 0; font-size: .9rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.ai-field { display: grid; grid-template-columns: 180px 1fr; gap: .3rem .8rem; font-size: .88rem; margin-bottom: .45rem; }
.ai-field > span:first-child { color: var(--text-2); font-size: .78rem; padding-top: .2rem; font-weight: 600; }
.ai-field input, .ai-field select, .ai-field textarea { margin-top: 0 !important; }
.evidence { color: var(--text-3); font-size: .78rem; font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: .15rem .6rem; font-size: .8rem; }
.list-plain { margin: .2rem 0; padding-left: 1.2rem; }
.list-plain li { margin-bottom: .15rem; }
.conf { font-weight: 600; font-variant-numeric: tabular-nums; }
.conf-hi { color: var(--ok); } .conf-mid { color: var(--warn); } .conf-lo { color: var(--danger); }
.inline-list { list-style: none; margin: 0; padding: 0; display: flex; gap: 1rem; flex-wrap: wrap; font-size: .88rem; }
.timeline { font-size: .84rem; list-style: none; padding: 0; margin: 0; }
.timeline li { margin-bottom: .45rem; padding-left: .9rem; border-left: 2px solid var(--line); }
.pagination { display: flex; gap: .3rem; align-items: center; margin-top: 1rem; font-size: .86rem; flex-wrap: wrap; }
.pagination a, .pagination span { padding: .35rem .7rem; border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--surface); color: var(--text); }
.pagination a:hover { border-color: var(--accent); text-decoration: none; }
.pagination span.current { background: var(--text); color: var(--bg); border-color: var(--text); }
details.box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .65rem .95rem; margin-bottom: .8rem; background: var(--surface); }
details.box summary { cursor: pointer; font-weight: 600; font-size: .88rem; list-style: none; display: flex; align-items: center; gap: .5rem; }
details.box summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(-45deg); transition: transform .15s; }
details.box[open] summary::before { transform: rotate(45deg); }
details.box summary::-webkit-details-marker { display: none; }
.sticky-side { position: sticky; top: calc(var(--topbar-h) + 1rem); }
.bar { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); }

/* ---------- mobile bottom nav ---------- */
.bottom-nav { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 1rem 1rem 5.5rem; }
  .topbar { padding: 0 .9rem; }
  .ai-field { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .filters { padding: .7rem; }
  .filters label { flex: 1 1 140px; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 35; padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: .1rem; font-size: .62rem; color: var(--text-2); padding: .25rem .5rem; border-radius: var(--r-xs); min-width: 56px; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav a:hover { text-decoration: none; }
  #toasts { top: auto; bottom: 4.5rem; left: .9rem; right: .9rem; max-width: none; }
  .ticket-head .meta { grid-template-columns: repeat(2, 1fr); }
  .table { font-size: .84rem; }
  dialog .dialog-actions { flex-direction: column-reverse; } dialog .dialog-actions .btn { width: 100%; }
}
@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
@media print { .sidebar, .topbar, .btn, form, .bottom-nav, #toasts { display: none !important; } .content { padding: 0; } .card { break-inside: avoid; } }

/* ---------- logo ---------- */
.brand-logo { height: 30px; width: auto; display: block; }
.sidebar .brand { flex-direction: column; align-items: flex-start; gap: .15rem; padding: 1.2rem 1.1rem 1rem; }
.sidebar .brand small { padding-left: 2px; }
.auth-card .brand { flex-direction: column; align-items: center; gap: .2rem; }
.auth-card .brand img { height: 38px; width: auto; }
.sidebar-footer form { margin: 0; }
.table td.ellipsis { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 900px) { .table td.ellipsis { max-width: 200px; } }
@media (max-width: 900px) { .card > .table, .card > .table-wrap > .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; } .card > .table td, .card > .table th { white-space: nowrap; } .table td.ellipsis { max-width: 240px; } }
