/* FerieFacile */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201e;
  --muted: #5d6b67;
  --line: #dfe5e3;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #ccebe7;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --ferie: #0f766e;
  --permesso: #6d28d9;
  --malattia: #be123c;
  --altro: #475569;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #18201e;
    --text: #e6eeec;
    --muted: #9aaba6;
    --line: #2a3532;
    --brand: #2dd4bf;
    --brand-ink: #062a26;
    --brand-soft: #134e48;
    --ok: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --ferie: #2dd4bf;
    --permesso: #a78bfa;
    --malattia: #fb7185;
    --altro: #94a3b8;
    --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.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
code { font-size: .85em; word-break: break-all; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offline { font-size: .75rem; background: var(--warn); color: #fff; padding: 2px 8px; border-radius: 99px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }
.loading, .empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
.card.narrow { max-width: 420px; margin: 8vh auto 0; }
details.card summary { cursor: pointer; padding: 2px 0; }
details.card[open] summary { margin-bottom: 12px; }

/* form */
form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: .9rem; font-weight: 600; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: 20px; min-height: 20px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); align-items: end; }
.row.closure { grid-template-columns: 150px 1fr auto; }
.hint { font-size: .8rem; font-weight: 400; color: var(--muted); margin: 0; }
.form-error { color: var(--danger); margin: 0; min-height: 0; }
.form-error:empty { display: none; }
[hidden] { display: none !important; }

fieldset.seg { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
fieldset.seg legend { font-size: .9rem; font-weight: 600; margin-bottom: 4px; padding: 0; }
fieldset.seg label { display: block; }
fieldset.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
fieldset.seg span {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px;
  font-weight: 500; cursor: pointer; background: var(--bg);
}
fieldset.seg input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
fieldset.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.block { display: flex; width: 100%; margin: 16px 0; }

.alert {
  display: block; padding: 12px 14px; border-radius: var(--radius); margin: 0 0 16px;
  background: var(--brand-soft); color: var(--text); text-decoration: none;
}

/* statistiche */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 6px; box-shadow: var(--shadow); }
.stat .label { font-size: .85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stat .value small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 99px; transition: width .4s; }

/* liste */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.item.inactive { opacity: .6; }
.item-main { min-width: 0; flex: 1 1 220px; }
.item-title { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-sub { color: var(--muted); font-size: .9rem; }
.item-note { font-size: .9rem; margin-top: 4px; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card .list .item { border-left: 0; border-right: 0; border-radius: 0; padding-left: 0; padding-right: 0; border-top: 0; }

.badge { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); }
.st-pending { background: #fef3c7; color: #78350f; }
.st-approved { background: #dcfce7; color: #14532d; }
.st-rejected { background: #fee2e2; color: #7f1d1d; }
.st-cancelled { background: var(--line); color: var(--muted); }
.type { font-weight: 700; }
.type.t-ferie { color: var(--ferie); }
.type.t-permesso { color: var(--permesso); }
.type.t-malattia { color: var(--malattia); }
.type.t-altro, .type.t-assenza { color: var(--altro); }

/* tabs */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: none; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.filters { margin-bottom: 12px; max-width: 240px; }

/* tabella */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* calendario */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cal-head h1 { margin: 0; text-transform: capitalize; font-size: 1.25rem; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 12px; }
.cal-dow { font-size: .75rem; text-align: center; color: var(--muted); font-weight: 600; }
.cal-cell {
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  min-height: 72px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; gap: 2px; overflow: hidden; min-width: 0;
}
.cal-cell.pad { background: transparent; border: 0; cursor: default; }
.cal-cell.off { background: var(--bg); }
.cal-cell.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.cal-num { font-size: .8rem; font-weight: 700; }
.cal-cell.off .cal-num { color: var(--muted); }
.cal-hol { font-size: .6rem; color: var(--danger); line-height: 1.1; }
.chip {
  font-size: .65rem; line-height: 1.3; padding: 1px 4px; border-radius: 4px; color: #fff;
  background: var(--altro); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.t-ferie { background: var(--ferie); }
.chip.t-permesso { background: var(--permesso); }
.chip.t-malattia { background: var(--malattia); }
.chip.pending { background: transparent; color: var(--text); border: 1px dashed var(--muted); }
.chip.more { background: var(--line); color: var(--text); }
@media (prefers-color-scheme: dark) { .chip:not(.pending):not(.more) { color: #0b1110; } }
.legend { display: flex; gap: 8px; font-size: .8rem; margin: 12px 0; }
.legend .chip { font-size: .75rem; padding: 2px 8px; }

.hol-list { list-style: none; padding: 0; margin: 0; columns: 2 220px; }
.hol-list li { padding: 4px 0; font-size: .9rem; break-inside: avoid; }
.hol-list span { display: inline-block; min-width: 90px; color: var(--muted); }

.checks { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; }
.checks li::before { display: inline-block; width: 1.5em; font-weight: 700; }
.checks li.ok::before { content: "✓"; color: var(--ok); }
.checks li.warn::before { content: "!"; color: var(--warn); }
.checks li.ko::before { content: "✕"; color: var(--danger); }
.checks li.ko { color: var(--danger); font-weight: 600; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin-top: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* barra di navigazione in basso */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; max-width: 120px;
  padding: 6px 0; font-size: .7rem; font-weight: 600; color: var(--muted); text-decoration: none; border-radius: 8px;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--brand); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px);
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}
.toast.err { background: var(--danger); color: #fff; }

@media (min-width: 720px) {
  .cal-cell { min-height: 92px; }
  .chip { font-size: .75rem; }
  .cal-hol { font-size: .7rem; }
}
@media (max-width: 420px) {
  .row.closure { grid-template-columns: 1fr auto; }
  .row.closure input[type=date] { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
