/* Om Design – Gestionale */
@font-face { font-family: Ambit; src: url(../fonts/Ambit-Light.otf) format("opentype"); font-weight: 300; font-display: swap; }
@font-face { font-family: Ambit; src: url(../fonts/Ambit-Regular.otf) format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: Ambit; src: url(../fonts/Ambit-SemiBold.otf) format("opentype"); font-weight: 600; font-display: swap; }
@font-face { font-family: Ambit; src: url(../fonts/Ambit-Bold.otf) format("opentype"); font-weight: 700; font-display: swap; }
@font-face { font-family: Ambit; src: url(../fonts/Ambit-Black.otf) format("opentype"); font-weight: 900; font-display: swap; }

:root {
  --brand: #111111;
  --ink: #141414;
  --ink-2: #4a4a48;
  --ink-3: #8a8a86;
  --line: #e6e5e1;
  --line-2: #d6d5d0;
  --bg: #f5f4f0;
  --card: #ffffff;
  --side: #111111;
  --ok: #1f7a4d;   --ok-bg: #e5f3ea;
  --warn: #9a5b00; --warn-bg: #fbf0dc;
  --bad: #b3261e;  --bad-bg: #fbe7e5;
  --info: #24569c; --info-bg: #e6eef9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: Ambit, "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); }
a { color: inherit; }
h1, h2, h3 { font-weight: 700; line-height: 1.2; margin: 0 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code { background: #f0efea; padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ico { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--side); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex: none; z-index: 30; }
.sidebar-head { padding: 26px 22px 18px; display: flex; align-items: center; justify-content: space-between; }
.logo img { height: 42px; display: block; }
.nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: rgba(255,255,255,.7); font-weight: 400; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav a.active { color: #111; background: #fff; font-weight: 600; }
.nav a span { flex: 1; }
.nav .badge { font-style: normal; font-size: .72rem; font-weight: 700; background: #e5484d; color: #fff; border-radius: 99px; padding: 1px 7px; }
.nav-sep { height: 1px; background: rgba(255,255,255,.1); margin: 10px 12px; }
.sidebar-foot { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot form { margin: 0; }
.sidebar .icon-btn { color: rgba(255,255,255,.7); }
.sidebar .icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.me { display: flex; align-items: center; gap: 10px; font-size: .9rem; min-width: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; font-size: .75rem; font-weight: 700; flex: none; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 26px 36px 8px; }
.topbar h1 { font-size: 1.7rem; font-weight: 900; margin: 0; flex: 1; letter-spacing: -.02em; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.content { padding: 18px 36px 60px; max-width: 1280px; width: 100%; }
.only-mobile { display: none !important; }

/* ---------- Componenti ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 18px 22px 0; }

.grid { display: grid; gap: 18px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 14px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols { display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 15px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.25); border-color: var(--brand); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); background: var(--bad-bg); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn .ico { width: 16px; height: 16px; }
.icon-btn { background: none; border: 0; padding: 7px; border-radius: 8px; cursor: pointer; color: var(--ink-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: #efeee9; color: var(--ink); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
form.inline { display: inline; margin: 0; }

.chip { display: inline-flex; align-items: center; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: #efeee9; color: var(--ink-2); }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-warn { background: var(--warn-bg); color: var(--warn); }
.chip-bad { background: var(--bad-bg); color: var(--bad); }
.chip-info { background: var(--info-bg); color: var(--info); }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .92rem; background: var(--ok-bg); color: var(--ok); }
.flash-bad { background: var(--bad-bg); color: var(--bad); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-info { background: var(--info-bg); color: var(--info); }

/* ---------- Form ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--ink-2); }
input, select, textarea { font: inherit; font-size: .95rem; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ink); }
label.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 400; font-size: .92rem; color: var(--ink); cursor: pointer; }
.fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.fieldset legend { font-weight: 700; margin-bottom: 10px; padding: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.search { position: relative; }
.search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search input { padding-left: 36px; }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafaf7; }
.table .actions { text-align: right; white-space: nowrap; }
.table a.rowlink { text-decoration: none; font-weight: 600; }
.table a.rowlink:hover { text-decoration: underline; }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: 22px; }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: 22px; }
.sub { display: block; color: var(--ink-3); font-size: .82rem; font-weight: 400; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--ink-3); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--ink); border-color: var(--ink); }
.tabs a em { font-style: normal; color: var(--ink-3); font-weight: 400; margin-left: 4px; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty p { margin-bottom: 14px; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); text-decoration: none; display: block; }
.kpi.dark { background: var(--brand); color: #fff; border-color: var(--brand); }
.kpi .label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.kpi.dark .label, .kpi.dark .foot { color: rgba(255,255,255,.65); }
.kpi .value { font-size: 1.75rem; font-weight: 900; letter-spacing: -.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: .82rem; color: var(--ink-3); }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.alerts li:last-child { border-bottom: 0; }
.alerts .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--ink-3); }
.alerts .dot.bad { background: var(--bad); } .alerts .dot.warn { background: #d18a00; } .alerts .dot.info { background: var(--info); }
.alerts a { text-decoration: none; }
.alerts a:hover { text-decoration: underline; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.bars .bar i { display: block; width: 100%; max-width: 46px; background: var(--brand); border-radius: 5px 5px 2px 2px; min-height: 2px; }
.bars .bar.current i { background: repeating-linear-gradient(-45deg, var(--brand) 0 6px, #444 6px 9px); }
.bars .bar span { font-size: .72rem; color: var(--ink-3); }
.bars .bar b { font-size: .72rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.list-plain li:last-child { border-bottom: 0; }

/* ---------- Cliente ---------- */
.client-head { display: flex; gap: 18px; align-items: center; }
.client-head .avatar { width: 52px; height: 52px; font-size: 1.1rem; background: var(--brand); color: #fff; }
.dl { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: .9rem; margin: 0; }
.dl dt { color: var(--ink-3); }
.dl dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 12px 0 12px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 17px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.timeline .meta { font-size: .8rem; color: var(--ink-3); }

/* ---------- Editor preventivo ---------- */
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); text-align: left; padding: 0 6px 8px; }
.items td { padding: 6px; vertical-align: top; border-top: 1px solid var(--line); }
.items .c-qty { width: 80px; } .items .c-unit { width: 100px; } .items .c-price { width: 120px; } .items .c-tot { width: 110px; } .items .c-del { width: 40px; }
.items textarea { min-height: 54px; margin-top: 6px; font-size: .88rem; }
.items .line-total { padding-top: 16px; font-weight: 700; }
.picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.picker select { max-width: 380px; }
.totals { font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; font-size: .95rem; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-size: 1.25rem; font-weight: 900; }
.totals .note { font-size: .8rem; color: var(--ink-3); display: block; }
.sticky { position: sticky; top: 18px; }
.inst td { padding: 4px; border-top: 0; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.link-box { display: flex; gap: 8px; }
.link-box input { font-size: .82rem; background: #fafaf7; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 34px 30px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-card.wide { max-width: 760px; }
.auth-logo { width: 110px; margin: 0 auto 4px; display: block; }

/* ---------- Mobile ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 820px) {
  .only-mobile { display: inline-grid !important; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .25s ease; width: 270px; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .topbar { padding: 14px 16px 4px; position: sticky; top: 0; background: var(--bg); z-index: 10; flex-wrap: wrap; }
  .topbar h1 { font-size: 1.3rem; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .content { padding: 12px 16px 60px; }
  .card { padding: 16px; }
  .card.flush .card-head { padding: 16px 16px 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .kpi .value { font-size: 1.35rem; }
  .dl { grid-template-columns: 100px 1fr; }
  /* tabelle → schede */
  .table.responsive thead { display: none; }
  .table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0 !important; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--ink-3); font-size: .78rem; font-weight: 600; text-align: left; }
  .table.responsive td:first-child { display: block; text-align: left; font-size: 1rem; }
  .table.responsive td:first-child::before { display: none; }
  .table.responsive td.actions { justify-content: flex-end; padding-top: 8px !important; }
  .table.responsive td.actions::before { display: none; }
  /* righe preventivo */
  .items thead { display: none; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr 40px; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
  .items td { border: 0; padding: 0; width: auto !important; }
  .items td.c-name { grid-column: 1 / -1; }
  .items td.c-tot { grid-column: 1 / 4; grid-row: 3; text-align: left; padding-top: 8px; }
  .items td.c-del { grid-column: 4; grid-row: 3; }
  .items td.c-tot::before { content: "Totale riga: "; font-weight: 400; color: var(--ink-3); }
  .inst tr { grid-template-columns: 1fr 1fr 40px; }
  .inst td:nth-child(1) { grid-column: 1 / -1; }
  .inst td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .inst td:nth-child(3) { grid-column: 2; grid-row: 2; }
  .inst td:nth-child(4) { grid-column: 1; grid-row: 3; }
  .inst td:nth-child(5) { grid-column: 2; grid-row: 3; }
  .inst td:nth-child(6) { grid-column: 3; grid-row: 2; }
}

.table tr[data-href] { cursor: pointer; }
