/* Studio 23·24 — Gestionale */

:root {
  --bg: #f4f1ea;
  --card: #fcfaf5;
  --ink: #16140f;
  --muted: #7d766a;
  --line: #e4dfd2;
  --green: #2e7d4f;
  --green-bg: #e4efe7;
  --amber: #a8761c;
  --amber-bg: #f4ead4;
  --red: #b3372e;
  --red-bg: #f4dedc;
  --gray-bg: #e9e6de;
  --radius: 14px;
  --serif: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

h1, h2, h3 { font-family: var(--serif); font-weight: 400; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 24px;
}
.login-logo { width: min(320px, 75vw); }
.login-form { width: min(320px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-error { color: var(--red); text-align: center; margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-icon { width: 30px; height: 30px; border-radius: 7px; }
.topbar-title { flex: 1; margin: 0; font-size: 22px; }
.btn-ghost {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 6px 8px;
  cursor: pointer;
}

/* ---------- Layout ---------- */
main {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(86px + env(safe-area-inset-bottom));
}
.section-title {
  font-size: 21px;
  margin: 26px 0 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.section-title small { font-family: -apple-system, sans-serif; font-size: 13px; color: var(--muted); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.tab svg { width: 23px; height: 23px; fill: currentColor; }
.tab.active { color: var(--ink); }

/* ---------- Cards & stats ---------- */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-family: var(--serif); font-size: 30px; margin-top: 2px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 9px;
  cursor: pointer;
}
.card.static { cursor: default; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-title { font-family: var(--serif); font-size: 19px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-amount { font-family: var(--serif); font-size: 18px; white-space: nowrap; }
.card-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; font-size: 12.5px; color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------- Chips ---------- */
.chip {
  display: inline-block;
  font-size: 11.5px;
  padding: 2px 9px;
  border-radius: 99px;
  background: var(--gray-bg);
  color: var(--ink);
  white-space: nowrap;
}
.chip.attivo     { background: var(--green-bg); color: var(--green); }
.chip.trattativa { background: var(--amber-bg); color: var(--amber); }
.chip.sospeso    { background: var(--red-bg);   color: var(--red); }
.chip.cessato    { background: var(--gray-bg);  color: var(--muted); }
.chip.warn       { background: var(--amber-bg); color: var(--amber); }
.chip.danger     { background: var(--red-bg);   color: var(--red); }
.chip.ok         { background: var(--green-bg); color: var(--green); }

/* ---------- Buttons & forms ---------- */
.btn {
  font: inherit;
  padding: 10px 16px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-danger { color: var(--red); border-color: var(--red-bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }

.toolbar { display: flex; gap: 9px; margin-bottom: 14px; }
.toolbar input[type="search"], .toolbar input[type="month"] { flex: 1; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  min-height: 42px;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label small { color: var(--muted); font-size: 11px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Dialog / sheet ---------- */
dialog {
  border: none;
  padding: 0;
  background: transparent;
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  max-height: 92dvh;
}
dialog::backdrop { background: rgba(22, 20, 15, .45); }
.sheet {
  display: flex;
  flex-direction: column;
  gap: 13px;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 92dvh;
  overflow-y: auto;
}
@media (min-width: 600px) {
  dialog { margin: auto; }
  .sheet { border-radius: 18px; }
}
.sheet-title { margin: 0 0 4px; font-size: 24px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Dettaglio cliente ---------- */
.detail-head { display: flex; align-items: center; gap: 10px; }
.detail-head h2 { margin: 0; font-size: 26px; flex: 1; }
.info-grid { display: grid; gap: 3px; }
.info-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.info-row .k { color: var(--muted); width: 110px; flex-shrink: 0; }
.info-row .v { flex: 1; word-break: break-word; }
.info-row a { color: var(--ink); }

.svc-row, .pay-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.svc-row .grow, .pay-row .grow { flex: 1; min-width: 0; }
.svc-row.inactive .grow { color: var(--muted); text-decoration: line-through; }
.icon-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 7px;
  color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-btn {
  font: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}

.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 14px; }

.alert {
  padding: 11px 14px;
  border-radius: 11px;
  font-size: 13.5px;
}
.alert.warn { background: var(--amber-bg); color: var(--amber); }
.alert.danger { background: var(--red-bg); color: var(--red); }

.fab-row { display: flex; justify-content: flex-end; margin-bottom: 14px; }

.total-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--serif);
  font-size: 19px;
  padding: 10px 2px;
}
