/* ── Design tokens ───────────────────────────────────────────────────────────
   Every colour in the app comes from here (templates use var(--…) in their
   inline styles too). Neutral greys + one blue accent + three status colours;
   no violet anywhere, by design. */
:root {
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f9fafb;
  --surface-3:     #f2f4f7;
  --border:        #e4e7ec;
  --border-strong: #d0d5dd;

  --text:   #101828;
  --text-2: #344054;
  --text-3: #5d6779;
  --text-4: #8a94a6;

  --accent:        #1d5fbf;
  --accent-hover:  #174e9e;
  --accent-soft:   #eef4fc;
  --accent-border: #c6d9f3;

  --success:        #067647;
  --success-soft:   #ecfdf3;
  --success-border: #abefc6;
  --warning:        #b54708;
  --warning-soft:   #fffaeb;
  --warning-border: #fedf89;
  --danger:         #b42318;
  --danger-soft:    #fef3f2;
  --danger-border:  #fecdca;

  /* Notes typed by hand (manual ingest): a calm teal, distinct from status colours. */
  --manual:        #0e7490;
  --manual-soft:   #effbfd;
  --manual-border: #b9e6ee;

  --on-solid: #ffffff;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow:    0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font);
       font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
       font-feature-settings: "tnum" 1, "cv11" 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-3);
       color: var(--text-2); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); }
h2 { font-size: 1rem; font-weight: 600; color: var(--text); letter-spacing: -.005em; }
h3 { font-size: .9rem; font-weight: 600; color: var(--text); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Shell: sidebar + main ─────────────────────────────────────────────────── */
.page { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh;
        /* the sidebar column stays white below the fold on long pages */
        background: linear-gradient(to right, var(--surface) 243px, var(--border) 243px 244px, var(--bg) 244px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border);
           padding: 18px 14px 14px; display: flex; flex-direction: column; gap: 1px;
           position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-size: .98rem;
                 font-weight: 650; letter-spacing: -.01em; padding: 2px 6px; color: var(--text); }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--text);
              color: var(--on-solid); display: grid; place-items: center;
              font-size: .85rem; font-weight: 700; letter-spacing: 0; flex: none; }
.brand-sub { display: block; font-size: .68rem; font-weight: 500; color: var(--text-4);
             letter-spacing: .01em; margin-top: -2px; }
.sidebar-subtitle { font-size: .68rem; font-weight: 600; color: var(--text-4);
                    text-transform: uppercase; letter-spacing: .06em;
                    margin: 18px 6px 6px; }
.sidebar-tour { margin: 16px 0 8px; padding: 10px; border: 1px solid var(--border);
                border-radius: var(--radius); background: var(--surface-2);
                display: flex; flex-direction: column; gap: 6px; }
.sidebar-tour-label { font-size: .66rem; font-weight: 600; color: var(--text-4);
                      text-transform: uppercase; letter-spacing: .06em; }
.sidebar-tour-name { font-size: .92rem; font-weight: 650; color: var(--text);
                     line-height: 1.25; overflow-wrap: anywhere; }
.sidebar-tour-select { width: 100%; font-size: .8rem; padding: 5px 8px; }
.sidebar-tour-all { display: flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 500; }
.sidebar-tour-all svg { width: 13px; height: 13px; }
.sidebar-tour-all.active { color: var(--accent-hover); text-decoration: underline; }
.sidebar-tour-form { display: flex; gap: 6px; margin: 0 0 8px; }
.sidebar-tour-form input { flex: 1; min-width: 0; font-size: .8rem; padding: 6px 9px; }
.sidebar-tour-btn { display: grid; place-items: center; width: 32px; flex: none;
                    background: var(--surface); color: var(--text-3);
                    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
                    cursor: pointer; font-size: .8rem; }
.sidebar-tour-btn:hover { background: var(--surface-3); color: var(--text); }
.sidebar-tour-btn svg { width: 14px; height: 14px; }
.sidebar-section { font-size: .66rem; font-weight: 600; color: var(--text-4);
                   text-transform: uppercase; letter-spacing: .07em; margin: 16px 6px 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; font-size: .84rem;
            font-weight: 500; color: var(--text-2); padding: 7px 8px;
            border-radius: var(--radius-sm); text-decoration: none; }
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--text-4); }
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item:hover svg { color: var(--text-3); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }

.badge { display: inline-block; background: var(--danger); color: var(--on-solid);
         font-size: .62rem; font-weight: 600; border-radius: 99px; padding: 1px 7px; margin-left: 6px; }
.badge.warn { background: var(--warning); }
.badge.ok { background: var(--success); }

.main { display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.topbar { background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(8px);
          border-bottom: 1px solid var(--border); padding: 0 32px; height: 60px;
          display: flex; align-items: center; justify-content: space-between; gap: 16px;
          position: sticky; top: 0; z-index: 50; }
.topbar h1 { font-size: 1.08rem; font-weight: 600; letter-spacing: -.01em; color: var(--text);
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .meta { font-size: .78rem; color: var(--text-3); text-align: right; }
.content { padding: 28px 32px 48px; flex: 1; display: flex; flex-direction: column; gap: 20px;
           width: 100%; max-width: 1440px; }

/* ── Status cards ──────────────────────────────────────────────────────────── */
.conflict { border-radius: var(--radius); padding: 14px 16px; display: flex;
            align-items: flex-start; gap: 12px; margin-bottom: 8px; background: var(--surface);
            border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.conflict.red { background: var(--danger-soft); border-color: var(--danger-border); }
.conflict.yellow { background: var(--warning-soft); border-color: var(--warning-border); }
.conflict-body { flex: 1; }
.conflict-title { font-size: .86rem; font-weight: 600; margin-bottom: 3px; color: var(--text); }
.conflict-desc { font-size: .8rem; color: var(--text-2); }
.conflict-action { font-size: .78rem; color: var(--accent); margin-top: 6px; }

.section-head { font-size: .7rem; font-weight: 600; color: var(--text-3); text-transform: uppercase;
                letter-spacing: .07em; margin-bottom: 10px; display: flex;
                align-items: center; gap: 8px; }

.task { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 16px 18px; display: flex; gap: 14px; margin-bottom: 10px;
        box-shadow: var(--shadow-sm); position: relative; transition: border-color .15s, box-shadow .15s; }
.task:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.task::before { content: ""; position: absolute; left: -1px; top: 14px; bottom: 14px; width: 3px;
                border-radius: 0 3px 3px 0; background: transparent; }
.task.alta::before { background: var(--danger); }
.task.media::before { background: var(--warning); }
.task.bassa::before { background: var(--success); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: .92rem; font-weight: 600; line-height: 1.45; margin-bottom: 6px; color: var(--text); }
.task-meta { font-size: .78rem; color: var(--text-3); margin-bottom: 8px; }
.task-source { font-size: .74rem; color: var(--text-4); }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; font-weight: 500;
       background: var(--surface-3); color: var(--text-3); border: 1px solid transparent;
       border-radius: 99px; padding: 1px 8px; margin-right: 4px; line-height: 1.6; white-space: nowrap; }
.tag.alta { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.tag.media { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.tag.bassa { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.tag.ok { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.tag.manual { color: var(--manual); background: var(--manual-soft); border-color: var(--manual-border); }

/* Task inserted via the manual-ingest form (web/bp_inbox.py: manual_entry) —
   a tinted background so it reads as "not auto-extracted" at a glance,
   on top of (not instead of) the urgency marker. */
.task.manual { background: var(--manual-soft); border-color: var(--manual-border); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
       font-family: inherit; font-size: .78rem; font-weight: 500; line-height: 1.2;
       padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
       background: var(--surface); color: var(--text-2); cursor: pointer; text-decoration: none;
       box-shadow: var(--shadow-sm); white-space: nowrap;
       transition: background .12s, border-color .12s, color .12s; }
.btn:hover { background: var(--surface-2); border-color: var(--text-4); color: var(--text); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--on-solid); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-solid); }
.btn.ghost { background: transparent; color: var(--text-3); border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }

/* Plain <button> elements without a class still look like part of the product. */
button { font-family: inherit; }

.draft-box { margin-top: 12px; background: var(--surface-2); border: 1px solid var(--border);
             border-radius: var(--radius-sm); padding: 14px; }
.draft-label { font-size: .68rem; font-weight: 600; color: var(--accent); text-transform: uppercase;
               letter-spacing: .06em; margin-bottom: 8px; }
.draft-text { font-size: .82rem; color: var(--text-2); line-height: 1.65; white-space: pre-wrap;
              font-family: var(--font); }
.draft-actions { display: flex; gap: 6px; margin-top: 12px; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.upload-zone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 40px;
               text-align: center; color: var(--text-3); background: var(--surface); }
.upload-zone input[type=file] { display: block; margin: 16px auto 0; color: var(--text-2); }
select, input[type=text], input[type=date], input[type=time], input[type=number], input[type=email],
input[type=search], input[type=password], input:not([type]), textarea {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 7px 10px; border-radius: var(--radius-sm); font-size: .84rem; font-family: inherit;
  box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-4); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
label { color: var(--text-2); }

/* ── Data ──────────────────────────────────────────────────────────────────── */
.content table { border-collapse: collapse; }
.content th { font-weight: 600; color: var(--text-3); }

.fact-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
             padding: 14px 18px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.fact-type { font-size: .7rem; color: var(--accent); text-transform: uppercase; font-weight: 600;
             letter-spacing: .05em; margin-bottom: 4px; }
.fact-payload { font-size: .8rem; color: var(--text-2); font-family: var(--mono); }

.flash { background: var(--success-soft); border: 1px solid var(--success-border); border-radius: var(--radius);
         padding: 11px 14px; color: var(--success); font-size: .84rem; margin-bottom: 12px; }

details > summary { cursor: pointer; }

/* Reset entry: pushed to the bottom of the sidebar and coloured apart from
   navigation, so a destructive action is never adjacent to a routine click. */
.sidebar-danger-section { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.nav-item-danger { color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-user { display: flex; align-items: center; gap: 8px; padding-left: 16px;
               border-left: 1px solid var(--border); min-width: 0; }
.topbar-user-email { font-size: .8rem; font-weight: 500; color: var(--text-2);
                     overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.topbar-user-role { font-size: .66rem; font-weight: 600; color: var(--accent); background: var(--accent-soft);
                    border: 1px solid var(--accent-border); border-radius: 99px; padding: 0 7px; }
.topbar-logout { font-size: .78rem; padding: 4px 10px; }
@media (max-width: 760px) { .topbar-right .meta { display: none; } .topbar-user-email { max-width: 140px; } }
.nav-item-danger:hover, .nav-item-danger.active { background: var(--danger-soft); color: var(--danger); }
.nav-item-danger:hover svg, .nav-item-danger.active svg { color: var(--danger); }

/* ── Offerte di viaggio ─────────────────────────────────────────────────────
   Le soluzioni di viaggio hanno colonne omogenee (orario, durata, prezzo):
   una griglia allineata si scorre con l'occhio molto meglio di una pila di
   schede. Larghezze fisse per colonna così le cifre restano in colonna anche
   quando cambia il contenuto. */
.term { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
        margin: 10px 0; overflow: hidden; box-shadow: var(--shadow-sm); font-variant-numeric: tabular-nums; }
.term-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px;
             background: var(--surface-2); border-bottom: 1px solid var(--border); }
.term-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex: none; }
.term-title { color: var(--text); font-size: .8rem; font-weight: 600;
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-count { margin-left: auto; color: var(--text-3); font-size: .74rem; flex: none; }

.term-body { max-height: 360px; overflow-y: auto; }
.term-row { display: flex; align-items: center; gap: 12px; padding: 7px 12px;
            font-size: .8rem; border-bottom: 1px solid var(--border); }
.term-row:last-child { border-bottom: 0; }
.term-row:hover { background: var(--surface-2); }
.term-legend { color: var(--text-4); font-size: .66rem; font-weight: 600; text-transform: uppercase;
               letter-spacing: .06em; background: var(--surface); }
.term-legend:hover { background: var(--surface); }

.term .c-time  { flex: none; width: 122px; color: var(--text); font-weight: 500; }
.term .c-dur   { flex: none; width: 118px; color: var(--text-3); }
.term .c-car   { flex: 1; min-width: 0; color: var(--text-2);
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term .c-price { flex: none; width: 70px; text-align: right; color: var(--text-4); }
.term .c-price.has { color: var(--text); font-weight: 600; }
.term .c-price.alt { color: var(--text-3); }
.term .c-act   { flex: none; width: 70px; text-align: right; }

.term-btn { background: var(--surface); border: 1px solid var(--border-strong); color: var(--accent);
            font-family: inherit; font-size: .72rem; font-weight: 500; padding: 3px 9px;
            border-radius: var(--radius-sm); cursor: pointer; }
.term-btn:hover { background: var(--accent-soft); border-color: var(--accent-border); }
.term-btn:disabled { opacity: .5; cursor: wait; }

.term-foot { padding: 7px 12px; border-top: 1px solid var(--border); background: var(--surface-2);
             color: var(--text-3); font-size: .72rem; }

/* ── Small screens ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .page { grid-template-columns: 1fr; background: var(--bg); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-danger-section { margin-top: 12px; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 40px; }
}

/* Icon tile used at the top of upload / sync areas. */
.zone-icon { width: 40px; height: 40px; border-radius: var(--radius); display: grid; place-items: center;
             background: var(--surface-3); color: var(--text-3); flex: none; }
.zone-icon svg { width: 20px; height: 20px; }
.zone-icon-sm { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.zone-icon-sm svg { width: 15px; height: 15px; }
.upload-zone:hover .zone-icon { background: var(--accent-soft); color: var(--accent); }
label:hover > .upload-zone { border-color: var(--accent); background: var(--surface); }

/* Data tables (calendar, quick views, CO₂ detail…): a white card with a light header. */
.data-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
              border-collapse: separate; border-spacing: 0; overflow: hidden; box-shadow: var(--shadow-sm); }
.data-table th { padding: 10px 12px !important; background: var(--surface-2); color: var(--text-3);
                 font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
                 text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 12px !important; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }
