:root {
  --bg: #18120E;
  --bg-side: #221A14;
  --text: #E4DBD2;
  --strong: #FBF8F4;
  --mid: #C6BAB0;
  --muted: #9C8E83;
  --accent: #FF6A1F;
  --cta: #F2481B;
  --ok: #3CC07C;
  --late: #FF8A57;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .22);
  --panel: rgba(255, 255, 255, .04);
  --field: rgba(255, 255, 255, .025);
  --f-head: 'Space Grotesk', sans-serif;
  --f-body: 'Hanken Grotesk', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body {
  min-height: 100vh; color: var(--text); font: 16px/1.6 var(--f-body);
  letter-spacing: -0.01em; -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--strong); }
input::placeholder, textarea::placeholder { color: #7A6B60; }
select option { background: var(--bg-side); color: var(--strong); }
[hidden] { display: none !important; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.bg-glow { position: absolute; top: -220px; right: -180px; width: 600px; height: 600px; border-radius: 50%;
  background: radial-gradient(circle, rgba(242, 72, 27, .2), transparent 62%); pointer-events: none; }

/* Marca */
.brand { display: inline-flex; align-items: center; gap: .55em; font-size: 22px; color: var(--strong); }
.brand img { display: block; height: 1.05em; width: auto; }
.brand b { font: 700 1em/1 var(--f-head); letter-spacing: -0.045em; }
.brand .tag { font: 500 10px/1 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent);
  border: 1px solid rgba(255, 106, 31, .45); border-radius: 999px; padding: 4px 8px; }

/* Pagina cliente / conversazione */
.page { position: relative; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: relative; border-bottom: 1px solid rgba(255, 255, 255, .07); }
.topbar-in { margin: 0 auto; padding: 0 20px; min-height: 64px; display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.topbar-in .who { font-size: 14px; font-weight: 600; color: var(--strong); text-align: right; }
.col { position: relative; flex: 1; width: 100%; margin: 0 auto; padding: 28px 20px 120px; display: flex; flex-direction: column; gap: 28px; }
.w-760 { max-width: 760px; }
.w-800 { max-width: 800px; }
.section { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 4px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Tipografia */
h1, h2, h3 { margin: 0; font-family: var(--f-head); color: var(--strong); }
h1 { font-weight: 600; font-size: 32px; letter-spacing: -0.03em; line-height: 1.1; }
h1.big { font-size: 38px; line-height: 1.05; letter-spacing: -0.035em; }
h2 { font-weight: 600; font-size: 22px; letter-spacing: -0.02em; }
h2.card-title { font-size: 21px; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }
.mid { color: var(--mid); }
.small { font-size: 14px; }
.mono { font-family: var(--f-mono); }
.eyebrow { font: 500 11.5px var(--f-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.eyebrow.accent { color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.between { justify-content: space-between; }

/* Pill / badge */
.pill { display: inline-flex; align-items: center; gap: .5em; font: 500 12px var(--f-mono); text-transform: uppercase; letter-spacing: .06em;
  padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .06); color: var(--text); border: 1px solid rgba(255, 255, 255, .14); }
.pill .dot { width: 8px; height: 8px; border-radius: 999px; background: var(--accent); }
.pill .sq { width: 7px; height: 7px; border-radius: 2px; }
.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font: 500 11.5px var(--f-mono); text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; background: rgba(255, 255, 255, .06); color: var(--text); border: 1px solid rgba(255, 255, 255, .14); }
.badge.client { background: rgba(255, 106, 31, .12); color: var(--accent); border-color: rgba(255, 106, 31, .45); }
.badge.ok { background: rgba(60, 192, 124, .14); color: var(--ok); border-color: rgba(60, 192, 124, .4); }
.badge.received { color: var(--strong); border-color: rgba(60, 192, 124, .4); }
.badge.late { background: rgba(242, 72, 27, .14); color: var(--late); border-color: rgba(242, 72, 27, .5); }
.badge.zero { background: transparent; color: var(--muted); border-color: rgba(255, 255, 255, .1); }
.count { font: 700 12px var(--f-mono); background: var(--cta); color: #fff; padding: 1px 8px; border-radius: 999px; }

/* Card / pannelli */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.card.accent { background: rgba(255, 106, 31, .12); border-color: rgba(255, 106, 31, .45); }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.link-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; font: inherit; cursor: pointer; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.link-card.accent { background: rgba(255, 106, 31, .12); border-color: rgba(255, 106, 31, .45); }
.link-card:hover { color: var(--text); border-color: rgba(255, 255, 255, .2); }
.link-card .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.link-card strong { font: 600 18px var(--f-head); letter-spacing: -0.02em; color: var(--strong); }
.arrow { font-weight: 700; color: var(--accent); }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 999px; background: var(--cta); color: #fff; display: flex; align-items: center;
  justify-content: center; font: 700 15px var(--f-head); }
.avatar.client { background: rgba(255, 255, 255, .1); color: var(--strong); }

/* Bottoni e campi */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 22px; border-radius: 999px;
  font: 600 15px var(--f-body); cursor: pointer; border: 1px solid transparent; text-decoration: none; }
.btn.primary { background: var(--cta); color: #fff; }
.btn.primary:hover { color: #fff; filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--strong); border-color: var(--line-strong); }
.btn.ghost:hover { border-color: var(--strong); }
.btn.text { background: none; color: var(--accent); font-weight: 500; padding: 0 8px; }
.btn.sm { font-size: 14px; padding: 0 16px; }
.btn.glow { box-shadow: 0 16px 40px rgba(242, 72, 27, .28); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .field:focus-visible, a:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.label { font-size: 14px; font-weight: 600; color: var(--mid); }
.field { font: inherit; color: var(--strong); background: var(--field); border: 1px solid rgba(255, 255, 255, .14); border-radius: 13px; padding: 10px 14px; min-height: 44px; width: 100%; }
textarea.field { resize: vertical; padding: 12px 14px; }
input[type=date].field { color-scheme: dark; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.chip { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line-strong);
  border-radius: 999px; color: var(--strong); cursor: pointer; }
.chip input { accent-color: var(--cta); }
.check { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { accent-color: var(--cta); width: 18px; height: 18px; }
.attach { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--accent); font-weight: 500; cursor: pointer; }
.file-link { display: inline-flex; align-items: center; gap: 10px; align-self: flex-start; min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid rgba(255, 255, 255, .1); color: var(--strong); font-size: 14px; }
.sep { border-top: 1px solid var(--line); padding-top: 16px; }

/* Progress */
.bar { height: 8px; background: rgba(255, 255, 255, .08); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 8px; background: var(--cta); border-radius: 999px; }
.segs { display: flex; gap: 6px; }
.segs i { flex: 1; height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .12); }
.segs.thin { gap: 3px; } .segs.thin i { height: 5px; }
.segs i.done { background: var(--ok); } .segs i.now { background: var(--cta); }
.segs.thin i.on { background: var(--accent); }
.big-num { font: 700 36px/1 var(--f-head); letter-spacing: -0.03em; color: var(--strong); }

/* Tab bar cliente */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(24, 18, 14, .92); backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%); border-top: 1px solid var(--line); }
.tabbar-in { max-width: 560px; margin: 0 auto; padding: 6px 8px 10px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; padding: 6px 4px; border-radius: 14px;
  color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0; }
.tab:hover { color: var(--strong); }
.tab[aria-current=page] { color: var(--accent); background: rgba(255, 106, 31, .1); }
.tab .ico { position: relative; display: inline-flex; }
.tab .dot-n { position: absolute; top: -6px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--cta); color: #fff;
  font: 700 11px/18px var(--f-mono); text-align: center; }

/* Lavori (fasi) */
.phases { list-style: none; margin: 0; padding: 0; background: var(--field); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.phases > li { display: flex; gap: 14px; padding: 18px 20px; border-bottom: 1px solid rgba(255, 255, 255, .07); }
.phases > li:last-child { border-bottom: 0; }
.phases > li.now { background: rgba(255, 106, 31, .06); }
.phase-num { flex: none; width: 32px; height: 32px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font: 600 15px var(--f-head); }
.phase-num.done { background: rgba(60, 192, 124, .16); border-color: transparent; }
.phase-num.now { background: var(--cta); border-color: transparent; color: #fff; font-weight: 700; }
.phase-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.phase-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; }
.phase-head strong { font: 600 17px var(--f-head); color: var(--strong); }
.phase-body.todo strong { color: var(--mid); }
.task-lines { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.task-lines li { display: flex; justify-content: space-between; gap: 12px; }
.tl-state { font: 12px var(--f-mono); color: var(--ok); }
.tl-state.wait { color: var(--accent); font-weight: 700; }

/* Messaggi / conversazione */
.thread-list a { display: flex; flex-direction: column; gap: 6px; padding: 18px 20px; background: var(--field); border: 1px solid var(--line); border-radius: 16px; color: var(--text); }
.thread-list a.new { background: var(--panel); border-color: rgba(255, 106, 31, .45); }
.thread-list strong { font: 600 17px var(--f-head); color: var(--strong); }
.thread-list .meta { font: 11.5px var(--f-mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.thread-list a.new .meta { color: var(--accent); }
.thread-list .meta.ok { color: var(--ok); }
.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.msg { display: flex; gap: 14px; padding: 16px 0; }
.msg .body { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg .who { font-size: 14px; } .msg .who strong { color: var(--strong); }
.msg .when { font: 12px var(--f-mono); color: var(--muted); }
.msg p { white-space: pre-wrap; overflow-wrap: anywhere; }
.divider { display: flex; align-items: center; gap: 12px; padding: 14px 0; color: var(--muted); }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, .1); }
.divider span { font: 11.5px var(--f-mono); text-transform: uppercase; letter-spacing: .05em; text-align: center; }

/* Login */
.center { min-height: 100vh; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; padding: 48px 16px; }
.center main { position: relative; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 28px; align-items: center; text-align: center; }
.center .card { width: 100%; padding: 32px 28px; text-align: left; gap: 20px; }
.err { color: var(--late); font-size: 14px; min-height: 1.4em; }

/* Admin */
.admin { min-height: 100vh; display: flex; flex-wrap: wrap; align-items: stretch; position: relative; }
.side { flex: 1 1 240px; max-width: 100%; background: var(--bg-side); border-right: 1px solid rgba(255, 255, 255, .07);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 22px; }
.side .brand { padding: 0 8px; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side a.item { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 12px;
  border: 1px solid transparent; color: var(--mid); }
.side a.item:hover { color: var(--strong); }
.side a.item[aria-current=page] { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .1); color: var(--strong); font-weight: 600; }
.side a.back { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 8px; font-weight: 600; }
.side .eyebrow { padding: 0 8px; margin-bottom: 6px; }
.main { flex: 999 1 560px; min-width: 0; padding: 36px 32px; display: flex; flex-direction: column; gap: 28px; max-width: 1180px; position: relative; }
.main.wide { margin: 0 auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat.accent { background: rgba(255, 106, 31, .12); border-color: rgba(255, 106, 31, .45); }
.stat.accent .eyebrow { color: var(--accent); }
.stat.late { background: rgba(242, 72, 27, .14); border-color: rgba(242, 72, 27, .5); }
.stat.late .eyebrow { color: var(--late); }
.stat.ok .big-num { color: var(--ok); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button { min-height: 44px; padding: 0 16px; border-radius: 999px; font: 600 14px var(--f-body); cursor: pointer;
  border: 1px solid var(--line-strong); background: transparent; color: var(--text); }
.filters button[aria-pressed=true] { background: var(--cta); border-color: var(--cta); color: #fff; }
.table-wrap { overflow-x: auto; background: var(--field); border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; font: 500 11.5px var(--f-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 16px; border-bottom: 1px solid var(--line); }
td { padding: 14px 16px; border-bottom: 1px solid rgba(255, 255, 255, .06); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .t { font-weight: 600; color: var(--strong); }
td .resp { font-size: 13px; color: var(--mid); margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 420px; }
td .due { font: 13px var(--f-mono); color: var(--mid); }
.cmt { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; padding: 18px 20px; background: var(--field);
  border: 1px solid var(--line); border-radius: 16px; }
.cmt.hot { background: var(--panel); border-color: rgba(255, 106, 31, .45); }
.cmt .info { flex: 1 1 360px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cmt .info .line { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.cmt .info .line strong { color: var(--strong); }
.cmt .info .tagline { font: 11.5px var(--f-mono); text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.cmt .quick { flex-basis: 100%; display: flex; gap: 10px; flex-wrap: wrap; }
.cmt .quick .field { flex: 1 1 260px; }

/* Modale */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg-side); border: 1px solid var(--line-strong); border-radius: 16px; padding: 28px; width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 16px; max-height: 92vh; overflow: auto; }
.copy-box { font: 15px var(--f-mono); background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; overflow-wrap: anywhere; color: var(--strong); }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--strong); color: var(--bg); padding: 10px 18px;
  border-radius: 999px; font-weight: 600; z-index: 60; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 720px) {
  .main { padding: 24px 16px; }
  h1.big { font-size: 32px; }
}
