:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #dfe3e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f2ef;
  --danger: #b42318;
  --warn: #a15c07;
  --ok: #157f3c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1b201e; --ink: #e8ece9; --muted: #9aa49f; --line: #2c3430;
    --accent: #2bb3a3; --accent-ink: #062a26; --accent-soft: #173431;
    --danger: #f07167; --warn: #f2b84b; --ok: #4ccf7a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
.card h2 { margin-top: 0; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* layout */
.wrap { max-width: 1040px; margin: 0 auto; padding: 16px; }
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-row { max-width: 1040px; margin: 0 auto; padding: 10px 16px 4px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 650; color: var(--ink); min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { font-size: 1.15rem; }
.top-user { display: flex; gap: 12px; align-items: center; font-size: .9rem; white-space: nowrap; }
.tabs { max-width: 1040px; margin: 0 auto; padding: 0 10px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 10px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.impersonate { background: var(--accent-soft); font-size: .85rem; padding: 4px 16px; text-align: center; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow { max-width: 460px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.inline { display: inline; margin: 0; }
[hidden] { display: none !important; }

/* form */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 450; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-height: 40px; width: 100%;
}
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 650; padding: 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; padding: 8px 14px; min-height: 40px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 140px; }
.toolbar label { flex-direction: row; align-items: center; gap: 8px; }
.pager { display: flex; gap: 8px; justify-content: center; margin: 14px 0; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.flash.err { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

/* login */
.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 380px; }

/* agenda */
.days { display: flex; flex-direction: column; gap: 12px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.day.today { border-color: var(--accent); }
.day > header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--accent-soft); }
.day h2 { margin: 0; font-size: .95rem; text-transform: capitalize; }
.day .add { font-size: 1.3rem; line-height: 1; padding: 0 6px; }
.day .empty { margin: 0; padding: 10px 12px; color: var(--muted); font-size: .9rem; }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 1px 8px; font-size: .75rem; text-transform: none; vertical-align: 1px; }
.appt { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; border-top: 1px solid var(--line); color: var(--ink); }
.appt:hover { background: var(--accent-soft); text-decoration: none; }
.appt .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.appt .who { min-width: 0; display: flex; flex-direction: column; }
.appt .who small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appt.st-cancelled .who strong, .appt.st-cancelled .time { text-decoration: line-through; color: var(--muted); }
.notifs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 140px; }
.dot { font-size: .7rem; font-weight: 700; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); color: var(--muted); }
.legend { font-size: .8rem; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 14px; }

/* stati */
.badge { display: inline-block; font-size: .75rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); white-space: nowrap; }
.s-pending { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: transparent; }
.s-sending, .s-sent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); border-color: transparent; }
.s-delivered, .s-read, .s-completed, .s-scheduled { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); border-color: transparent; }
.s-failed, .s-no_show { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: transparent; }
.s-cancelled, .s-skipped { background: var(--line); color: var(--muted); border-color: transparent; }

/* tabelle */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
tr.old td { opacity: .55; }
details summary { cursor: pointer; color: var(--accent); }

.facts { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts dd:first-of-type::first-letter { text-transform: uppercase; }

/* autocomplete clienti */
.customer-pick .selected { display: flex; justify-content: space-between; gap: 8px; padding: 9px 10px; background: var(--accent-soft); border-radius: 8px; font-weight: 600; }
.suggest { list-style: none; margin: 4px 0 0; padding: 0; border-radius: 8px; overflow: hidden; }
.suggest:not(:empty) { border: 1px solid var(--line); }
.suggest li button { width: 100%; text-align: left; background: var(--surface); border: 0; border-bottom: 1px solid var(--line); padding: 9px 10px; font: inherit; color: var(--ink); cursor: pointer; }
.suggest li:last-child button { border-bottom: 0; }
.suggest li button:hover, .suggest li button:focus { background: var(--accent-soft); }

.preview { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; }
.preview p { margin: 6px 0 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .num { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
