/* Palette calda e riposante: crema e terracotta di giorno, caffè e ambra di sera. */
:root {
  --bg: #f6efe6;
  --bg-soft: #efe5d8;
  --surface: #fffaf3;
  --surface-2: #f8f0e4;
  --text: #3a2f27;
  --muted: #7b6b5d;
  --border: #e4d6c4;
  --accent: #c2693d;
  --accent-hover: #ab5a31;
  --accent-ink: #fffaf3;
  --ok: #6f9a6a;
  --bad: #c25b4a;
  --shadow: 0 1px 2px rgba(80, 52, 30, .06), 0 6px 18px rgba(80, 52, 30, .07);
  --shadow-hover: 0 2px 4px rgba(80, 52, 30, .08), 0 12px 28px rgba(80, 52, 30, .12);
  --radius: 18px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1916;
    --bg-soft: #241f1b;
    --surface: #28221e;
    --surface-2: #302923;
    --text: #efe5d8;
    --muted: #a99a8a;
    --border: #3b332c;
    --accent: #de9a6b;
    --accent-hover: #e9ac82;
    --accent-ink: #2a1c12;
    --ok: #8ab583;
    --bad: #de7a68;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 12px 28px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1d1916;
  --bg-soft: #241f1b;
  --surface: #28221e;
  --surface-2: #302923;
  --text: #efe5d8;
  --muted: #a99a8a;
  --border: #3b332c;
  --accent: #de9a6b;
  --accent-hover: #e9ac82;
  --accent-ink: #2a1c12;
  --ok: #8ab583;
  --bad: #de7a68;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 12px 28px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -10%, color-mix(in srgb, var(--accent) 11%, transparent), transparent 70%),
    radial-gradient(900px 480px at 100% 0%, color-mix(in srgb, var(--ok) 9%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------- Pulsanti e campi ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .6rem 1rem; border-radius: 12px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: .35rem .7rem; border-radius: 10px; font-size: .9rem; }
.btn[disabled] { opacity: .6; cursor: default; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-width: 2.6rem; height: 2.6rem; padding: 0 .7rem;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: 12px; cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field label, .label { font-size: .88rem; color: var(--muted); font-weight: 500; }
.input {
  width: 100%; padding: .7rem .85rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }

.error { color: var(--bad); font-size: .92rem; min-height: 1.3em; margin: 0 0 .6rem; }

/* ---------- Login ---------- */

.login {
  min-height: 100vh; display: grid; place-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 1rem 1.5rem;
}
.login-card {
  width: min(420px, 100%); padding: 2.2rem 2rem 1.8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  box-shadow: var(--shadow-hover); animation: rise .5s ease both;
}
.mark {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--accent); margin-bottom: 1.2rem;
}
.mark svg { width: 30px; height: 30px; }
.login-card h1 { font: 600 1.9rem/1.2 var(--serif); margin: 0 0 .3rem; }
.login-card .lead { color: var(--muted); margin: 0 0 1.6rem; }
.login-card .btn.primary { width: 100%; padding: .8rem; margin-top: .3rem; }

/* ---------- Home ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .5rem;
  padding: max(.8rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .8rem max(1rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.brand { display: flex; align-items: center; gap: .65rem; font: 600 1.15rem var(--serif); }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; margin: 0; }
.brand .mark svg { width: 19px; height: 19px; }
.spacer { flex: 1; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 230px; padding: .4rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-hover); animation: pop .15s ease both;
}
.menu[hidden] { display: none; }
.menu .who { padding: .55rem .7rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu .who b { display: block; }
.menu .who span { color: var(--muted); font-size: .85rem; }
.menu button {
  display: flex; align-items: center; gap: .65rem; width: 100%; text-align: left;
  background: none; border: none; padding: .6rem .7rem; border-radius: 10px; cursor: pointer; color: var(--text);
}
.menu button:hover { background: var(--surface-2); }

main { width: min(1120px, 100%); margin: 0 auto; padding: 1.6rem max(1rem, env(safe-area-inset-left)) 4rem; }

.hello { margin: .6rem 0 1.4rem; animation: rise .5s ease both; }
.eyebrow { margin: 0 0 .25rem; color: var(--muted); font-size: .92rem; text-transform: capitalize; }
.hello h1 { font: 600 clamp(1.8rem, 5vw, 2.5rem)/1.15 var(--serif); margin: 0; letter-spacing: -.01em; }

.toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.8rem; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search .icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 2.6rem; }
.summary { color: var(--muted); font-size: .92rem; }

.group { margin-bottom: 2rem; }
.group h2 {
  margin: 0 0 .8rem; font: 600 .8rem var(--sans); letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }

.card {
  --c: var(--accent);
  position: relative; display: flex; align-items: center; gap: 1rem;
  padding: 1.05rem 1.1rem; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  animation: rise .45s ease both; animation-delay: calc(var(--i, 0) * 35ms);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--c) 45%, var(--border)); }
.tile {
  width: 52px; height: 52px; flex: none; border-radius: 15px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 17%, var(--surface)); color: var(--c);
}
.tile .icon { width: 26px; height: 26px; }
.card .body { min-width: 0; flex: 1; display: flex; flex-direction: column; align-items: flex-start; }
.card .name { font-weight: 600; font-size: 1.05rem; padding-right: 4.2rem; max-width: 100%; }
.card .desc { color: var(--muted); font-size: .9rem; margin-top: .1rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  display: inline-block; margin-top: .45rem; padding: .08rem .55rem; border-radius: 99px;
  font-size: .74rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
}

.dot { width: .62rem; height: .62rem; border-radius: 50%; flex: none; background: var(--border); }
.dot.up { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.card .state { position: absolute; top: .85rem; right: .95rem; display: flex; align-items: center; gap: .4rem; font-size: .76rem; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 3.5rem 1rem; }
.empty .icon { width: 2.4rem; height: 2.4rem; margin-bottom: .6rem; opacity: .6; }

/* ---------- Finestre ---------- */

dialog {
  width: min(560px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-hover);
}
dialog[open] { animation: pop .18s ease both; display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(30, 20, 12, .45); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.3rem .4rem; }
.dlg-head h2 { margin: 0; font: 600 1.3rem var(--serif); }
.dlg-body { padding: .6rem 1.3rem 1.2rem; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: .9rem 1.3rem; border-top: 1px solid var(--border); }

.rows { display: grid; gap: .6rem; margin-bottom: 1.4rem; }
.row {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .75rem .9rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2);
}
.row .info { flex: 1 1 160px; min-width: 0; }
.row .info b { display: flex; align-items: center; gap: .5rem; }
.row .info small { color: var(--muted); display: block; margin-top: .1rem; }
.row .actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.pill {
  font-size: .72rem; font-weight: 600; padding: .05rem .5rem; border-radius: 99px;
  background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent);
}
.sub { margin: 1.2rem 0 .7rem; font: 600 1rem var(--serif); }
.checks { display: grid; gap: .45rem; margin-bottom: 1rem; }
.check { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

.toast {
  position: fixed; left: 50%; bottom: max(1.2rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: .65rem 1.1rem; border-radius: 12px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-hover); animation: pop .2s ease both; z-index: 20; max-width: calc(100% - 2rem);
}

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .brand span:last-child { display: none; }
  .login-card { padding: 1.8rem 1.4rem 1.5rem; }
}

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

/* ---------- Modifica servizi (admin) ---------- */
.card-wrap { position: relative; display: flex; }
.card-wrap .card { flex: 1; min-width: 0; }
.edit-btn {
  position: absolute; right: .6rem; bottom: .6rem; width: 2rem; height: 2rem;
  display: grid; place-items: center; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.edit-btn .icon { width: 1rem; height: 1rem; }
.card-wrap:hover .edit-btn, .edit-btn:focus-visible { opacity: 1; }
.edit-btn:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .edit-btn { opacity: .8; } }
.pill.off { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.input.color { padding: .25rem; height: 2.9rem; cursor: pointer; }
