/* Elettrica Roma System — stile dell'app. Colori del logo: giallo, rosso, azzurro su nero. */
:root {
  --yellow: #F5B419; --red: #E3263B; --blue: #1E9BE9; --green: #1F9D55;
  --bg: #F4F3EF; --surface: #FFFFFF; --surface2: #ECEAE4; --line: #DDD9CF;
  --text: #17181A; --muted: #6B6A66; --on-accent: #17181A;
  --ok-bg: #E2F4E9; --ok-text: #136B3A; --warn-bg: #FCEBDD; --warn-text: #9A4A0E;
  --blue-bg: #E3F1FC; --blue-text: #0C5E95; --yellow-bg: #FDF1D2; --yellow-text: #7A5600;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B0B0C; --surface: #17181B; --surface2: #222328; --line: #2E3036;
    --text: #F2F1EE; --muted: #9C9AA0;
    --ok-bg: #12301F; --ok-text: #6FDB9D; --warn-bg: #3A2412; --warn-text: #F4B37A;
    --blue-bg: #0E2A40; --blue-text: #8CCBF5; --yellow-bg: #3A2D08; --yellow-text: #F7CF6A;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B0B0C; --surface: #17181B; --surface2: #222328; --line: #2E3036;
  --text: #F2F1EE; --muted: #9C9AA0;
  --ok-bg: #12301F; --ok-text: #6FDB9D; --warn-bg: #3A2412; --warn-text: #F4B37A;
  --blue-bg: #0E2A40; --blue-text: #8CCBF5; --yellow-bg: #3A2D08; --yellow-text: #F7CF6A;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  padding-bottom: env(safe-area-inset-bottom); }
body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 20px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
p { margin: 6px 0; }
a { color: inherit; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.err { color: var(--red); font-size: 14px; min-height: 0; } .ok { color: var(--ok-text); }
.row { display: flex; align-items: center; flex-wrap: wrap; } .gap { gap: 8px; } .between { justify-content: space-between; gap: 8px; }
.row.center { justify-content: center; } .grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.page { max-width: 640px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-left)) 24px max(16px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 12px; }
.page.centered { min-height: 100vh; justify-content: center; align-items: stretch; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg); }
.topbar h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .logo { width: 32px; height: 32px; border-radius: 8px; }
.topbar .actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--text);
  display: inline-grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:active { background: var(--surface2); }
[dir="rtl"] .topbar .icon-btn svg, [dir="rtl"] .menu-item svg[data-flip] { transform: scaleX(-1); }

.btn { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--on-accent); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-ghost { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.wide { width: 100%; } .btn.big { min-height: 54px; font-size: 17px; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 10px; }
.btn.present { background: var(--green); border-color: var(--green); color: #fff; }
.btn.outline-ok { border: 2px solid var(--green); color: var(--green); }
.btn.wa { background: #25D366; border-color: #25D366; color: #0B2E17; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ""; position: absolute; width: 18px; height: 18px; border: 2px solid var(--muted);
  border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; color: var(--blue); font: inherit; padding: 8px; cursor: pointer; display: inline-flex; align-items: center; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

input, select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; }
textarea { min-height: 80px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px; }
.card.off { opacity: .6; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card.project { cursor: pointer; }
.card.project h2 { font-size: 19px; }
.addr { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.who { font-size: 13px; color: var(--muted); margin: 0; }
.hello { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface2); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok-text); } .pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.blue { background: var(--blue-bg); color: var(--blue-text); } .pill.yellow { background: var(--yellow-bg); color: var(--yellow-text); }
.chip { display: inline-flex; align-items: center; gap: 4px; margin-inline-start: 8px; color: var(--blue); text-decoration: none; }
.badge { background: var(--yellow); color: #17181A; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 8px; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; background: var(--surface2); padding: 4px; border-radius: 14px; }
.tabs a { min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px;
  text-decoration: none; font-weight: 600; color: var(--muted); }
.tabs a.on { background: var(--yellow); color: #17181A; }
.proj-info { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }

.lines { list-style: none; margin: 0; padding: 0; }
.lines li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.lines li:last-child { border-bottom: 0; }
.lines li b { white-space: nowrap; font-variant-numeric: tabular-nums; }
ul.lines.card { padding: 6px 14px; }

/* Scelta materiali */
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker-search { position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 4; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.sheet .picker-search { top: 0; }
.picker-search input { border: 0; padding-inline: 0; background: transparent; }
.cat-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cat-block > h3 { padding: 12px 14px 4px; }
.cat-head { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border: 0; background: transparent;
  color: var(--text); font: inherit; font-weight: 700; text-align: start; cursor: pointer; }
.cat-head span:first-child { flex: 1; }
.chev { color: var(--muted); }
.pick { border-top: 1px solid var(--line); padding: 8px 12px; }
.pick.on { background: var(--yellow-bg); }
.pick-main { display: flex; align-items: center; gap: 10px; }
.thumb { width: 48px; height: 48px; border-radius: 10px; object-fit: contain; background: #fff; flex: none; border: 1px solid var(--line); }
.pick-name { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pick-name b { font-weight: 600; font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.step { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer; }
.qty { width: 58px; min-height: 40px; text-align: center; padding: 4px; font-weight: 700; }
.brand-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding-inline-start: 58px; flex-wrap: wrap; }
.brand-row select { flex: 1; min-height: 40px; min-width: 140px; }
.brand-other { min-height: 40px; }
.with-sendbar { padding-bottom: 80px; }
.sendbar { position: fixed; inset-inline: 0; bottom: 0; z-index: 6; display: none; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--surface); border-top: 1px solid var(--line); font-weight: 600; }
.sendbar.show { display: flex; }
body.has-nav .sendbar { bottom: calc(64px + env(safe-area-inset-bottom)); }
.preview { white-space: pre-wrap; background: var(--surface2); padding: 12px; border-radius: 12px; font: 14px/1.5 ui-monospace, monospace; max-height: 40vh; overflow: auto; }

/* Fattura */
.photo-box { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.photo-box img { max-height: 260px; border-radius: 12px; border: 1px solid var(--line); }
.inv-lines { display: flex; flex-direction: column; gap: 10px; }
.inv-line.bad { border-color: var(--red); }
.inv-head { display: flex; align-items: flex-start; gap: 8px; }
.inv-title { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; }
.alloc { display: grid; grid-template-columns: 1fr 90px auto; gap: 6px; align-items: center; }
.invoice-photo { width: 100%; border-radius: 12px; }

/* Riepilogo */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.stat span { color: var(--muted); font-size: 13px; } .stat b { font-size: 24px; font-variant-numeric: tabular-nums; }
.sec { margin-top: 8px; }
.rep-cat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.rep-cat h3 { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.rep-mat summary { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; cursor: pointer; border-bottom: 1px solid var(--line); list-style: none; }
.rep-mat summary::-webkit-details-marker { display: none; }
.rep-mat[open] summary { border-bottom-color: transparent; }
.rep-head h2 { font-size: 22px; }

/* Menu e fogli */
.menu { display: flex; flex-direction: column; }
.menu-item { min-height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 4px; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--text); font: inherit; font-weight: 600; text-align: start; text-decoration: none; cursor: pointer; width: 100%; }
.menu-item:last-child { border-bottom: 0; }
.menu-item.danger { color: var(--red); } .menu-item.on { color: var(--blue); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 4px 14px; border-top: 1px solid var(--line); }
.switch-row input[type=checkbox] { width: 24px; min-height: 24px; height: 24px; }
.switch-row.off { opacity: .55; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface2); padding: 4px; border-radius: 12px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s; }
.sheet-back.show { opacity: 1; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; display: flex; flex-direction: column; background: var(--bg);
  border-radius: 18px 18px 0 0; transform: translateY(30px); transition: transform .2s; }
.sheet-back.show .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px 6px; }
.sheet-head h2 { flex: 1; }
.sheet-body { overflow: auto; padding: 4px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.sticky-bottom { position: sticky; bottom: 0; }

.toast { position: fixed; inset-inline: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60; margin: 0 auto; max-width: 480px;
  padding: 12px 16px; border-radius: 12px; background: #17181A; color: #fff; font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(10px); transition: all .25s; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--red); }

.bottomnav { position: fixed; inset-inline: 0; bottom: 0; z-index: 7; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.bottomnav a.on { color: var(--text); }
.bottomnav a.on svg { color: var(--yellow); }

.login { display: flex; flex-direction: column; gap: 2px; }
.login h1 { text-align: center; margin-top: 8px; } .login > .muted { text-align: center; }
.big-logo { width: 110px; height: 110px; border-radius: 26px; align-self: center; margin: 0 auto; display: block; }
.login .btn.big { margin-top: 14px; }
.login .link { align-self: center; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 20px; }
body.offline .topbar::after { content: "Senza rete"; position: absolute; inset-inline-end: 0; top: calc(2px + env(safe-area-inset-top));
  font-size: 11px; background: var(--warn-bg); color: var(--warn-text); padding: 1px 8px; border-radius: 999px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Stampa / PDF */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; font: 12px/1.4 Arial, sans-serif; }
  #print-area .doc-head { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
  #print-area .doc-head img { width: 48px; height: 48px; }
  #print-area table { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 4px 6px; text-align: left; vertical-align: top; }
  #print-area th { background: #eee; } #print-area .n { text-align: right; white-space: nowrap; }
  #print-area h2 { font-size: 16px; } #print-area h3 { font-size: 13px; margin-top: 10px; }
  #print-area .small { font-size: 10px; } #print-area .doc-foot { margin-top: 16px; color: #555; font-size: 10px; }
}

/* Chat */
.chat-page { padding-bottom: 90px; }
.chat-list { display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface2); padding: 2px 10px; border-radius: 999px; margin: 8px 0; }
.bubble { max-width: 82%; align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px;
  padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.bubble.mine { align-self: flex-end; background: var(--yellow-bg); border-color: transparent; border-radius: 16px 16px 4px 16px; }
[dir="rtl"] .bubble { border-radius: 16px 16px 4px 16px; } [dir="rtl"] .bubble.mine { border-radius: 16px 16px 16px 4px; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .from { font-size: 13px; color: var(--blue-text); }
.bubble .meta { font-size: 11px; color: var(--muted); align-self: flex-end; display: inline-flex; gap: 6px; align-items: center; }
.bubble audio { width: 230px; max-width: 100%; height: 40px; }
.chat-photo { max-width: 240px; max-height: 260px; border-radius: 10px; cursor: pointer; }
.link.tiny { padding: 0 2px; font-size: 12px; color: var(--muted); }
.composer { position: fixed; inset-inline: 0; bottom: 0; z-index: 8; display: flex; align-items: flex-end; gap: 6px;
  padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--surface); border-top: 1px solid var(--line); }
body.has-nav .composer { bottom: calc(64px + env(safe-area-inset-bottom)); }
body.has-nav .chat-page { padding-bottom: 160px; }
.composer textarea { min-height: 44px; max-height: 120px; resize: none; border-radius: 22px; padding: 11px 14px; }
.round-btn { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: var(--yellow); color: #17181A; }
.round-btn.mic { background: var(--green); color: #fff; }
.composer.recording { align-items: center; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; }
.rec-time { font-weight: 700; font-variant-numeric: tabular-nums; }
@keyframes blink { 50% { opacity: .3; } }
.badge-wrap { position: relative; }
.dot-badge { position: absolute; top: 4px; inset-inline-end: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.msg-badge { display: inline-flex; align-items: center; gap: 2px; border: 0; border-radius: 999px; padding: 4px 10px; min-height: 30px;
  background: var(--red); color: #fff; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.tabs a { font-size: 14px; padding: 0 4px; text-align: center; }
.tabs .badge { background: var(--red); color: #fff; }
.btn.ai { border-color: var(--blue); color: var(--blue); }
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.inv-thumb { display: flex; flex-direction: column; gap: 4px; text-decoration: none; font-size: 12px; color: var(--muted); }
.inv-thumb img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
[dir="rtl"] .chev { display: inline-block; transform: scaleX(-1); }
