/* ==========================================================================
   Portale Commesse — Serramenti Elmec
   Stile "glass" ispirato al design Apple, palette dal marchio aziendale
   ========================================================================== */

:root {
  --brand: #18914a;          /* verde telaio del logo */
  --brand-light: #52b256;    /* verde lamelle */
  --brand-dark: #0f6b35;
  --teal: #005457;           /* verde petrolio del sito */
  --ink: #3f3a38;            /* grigio antracite scritta SERRAMENTI */
  --ink-soft: #6f6866;       /* grigio "elmec" */
  --ink-faint: #9a9391;
  --danger: #d6453d;
  --warning: #e39a1b;
  --info: #2c7fb8;

  --bg: #eaf1ec;
  --glass: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --glass-soft: rgba(255, 255, 255, 0.38);
  --glass-border: rgba(255, 255, 255, 0.75);
  --hairline: rgba(63, 58, 56, 0.10);
  --shadow: 0 10px 40px -12px rgba(15, 60, 35, 0.25), 0 2px 6px rgba(15, 60, 35, 0.06);
  --shadow-lg: 0 30px 80px -20px rgba(15, 60, 35, 0.35);
  --blur: saturate(180%) blur(24px);

  --tipo-lavoro: var(--brand);
  --tipo-tempo_morto: #e39a1b;
  --tipo-trasporto: #2c7fb8;

  --radius: 22px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2ef;
    --ink-soft: #b7c1bb;
    --ink-faint: #85908a;
    --bg: #0c1511;
    --glass: rgba(28, 40, 34, 0.55);
    --glass-strong: rgba(34, 48, 41, 0.82);
    --glass-soft: rgba(40, 56, 48, 0.35);
    --glass-border: rgba(255, 255, 255, 0.10);
    --hairline: rgba(255, 255, 255, 0.08);
    --shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 30px 80px -20px rgba(0, 0, 0, 0.7);
    --brand-light: #5fc466;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---- sfondo animato ---------------------------------------------------- */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: -1; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: .55;
  animation: float 26s ease-in-out infinite alternate;
}
.b1 { width: 48vw; height: 48vw; background: var(--brand-light); top: -14vw; left: -10vw; }
.b2 { width: 40vw; height: 40vw; background: var(--teal); bottom: -16vw; right: -8vw; opacity: .35; animation-delay: -8s; }
.b3 { width: 30vw; height: 30vw; background: #bfe3c6; top: 30%; right: 20%; animation-delay: -14s; }
.b4 { width: 24vw; height: 24vw; background: #d9d4d1; bottom: 5%; left: 18%; opacity: .5; animation-delay: -4s; }
@media (prefers-color-scheme: dark) {
  .blob { opacity: .28; }
  .b3 { background: var(--brand); }
  .b4 { background: #2a3a33; }
}
@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(4vw, 3vw) scale(1.12); }
}
@media (prefers-reduced-motion: reduce) { .blob { animation: none; } }

/* ---- superfici glass --------------------------------------------------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .5);
  border-radius: var(--radius);
}
@media (prefers-color-scheme: dark) {
  .glass { box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06); }
}

/* ---- barra superiore --------------------------------------------------- */
.topbar {
  position: sticky; top: 12px; z-index: 20;
  margin: 12px auto 0; max-width: 1280px; width: calc(100% - 24px);
  display: flex; align-items: center; gap: 16px;
  padding: 10px 14px 10px 18px;
  border-radius: 20px;
}
.topbar .logo { height: 34px; display: block; }
@media (prefers-color-scheme: dark) { .topbar .logo, .login-card .logo { filter: brightness(1.7) saturate(1.05); } }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  text-decoration: none; color: var(--ink-soft); padding: 8px 14px; border-radius: 12px;
  font-weight: 500; white-space: nowrap; transition: background .2s, color .2s;
}
.nav a:hover { background: var(--glass-soft); color: var(--ink); }
.nav a.active { background: var(--glass-strong); color: var(--brand-dark); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
@media (prefers-color-scheme: dark) { .nav a.active { color: var(--brand-light); } }
.usermenu { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand-light), var(--brand)); color: #fff; font-weight: 600; font-size: 13px;
}
.usermenu .name { font-weight: 600; font-size: 14px; line-height: 1.1; }
.usermenu .role { font-size: 12px; color: var(--ink-faint); }

main { max-width: 1280px; margin: 0 auto; padding: 24px 12px 60px; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 8px 6px 18px; flex-wrap: wrap; }
.page-title h1 { font-size: 30px; letter-spacing: -.02em; margin: 0; font-weight: 700; }
.page-title .sub { color: var(--ink-soft); margin-top: 2px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid.two { grid-template-columns: 1fr; } }
.card { padding: 22px; }
.card h2 { font-size: 17px; margin: 0 0 14px; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.card h2 > svg { width: 20px; height: 20px; flex: none; color: var(--brand); }

/* ---- controlli --------------------------------------------------------- */
.btn {
  appearance: none; border: 1px solid var(--glass-border); cursor: pointer;
  padding: 10px 18px; border-radius: 14px; font-weight: 600;
  background: var(--glass-strong); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .12s, box-shadow .2s, background .2s, opacity .2s;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { box-shadow: 0 4px 14px -4px rgba(0,0,0,.18); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #22a557, var(--brand)); color: #fff; border-color: rgba(0,0,0,.05); }
.btn.danger { background: linear-gradient(180deg, #e25a52, var(--danger)); color: #fff; border-color: rgba(0,0,0,.05); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--glass-soft); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.icon { padding: 7px; width: 34px; height: 34px; border-radius: 10px; }
.btn.big { padding: 16px 28px; font-size: 17px; border-radius: 18px; }
.btn svg { width: 18px; height: 18px; flex: none; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--hairline); background: var(--glass-strong);
  font-size: 15px; font-weight: 400; color: var(--ink); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
textarea.input { resize: vertical; min-height: 70px; }
.input:focus { border-color: var(--brand-light); box-shadow: 0 0 0 4px rgba(82, 178, 86, .22); }
.form { display: grid; gap: 14px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .btn { flex: 0 0 auto; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink); font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* controllo segmentato stile iOS */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  background: var(--glass-soft); border: 1px solid var(--hairline); border-radius: 14px;
}
.segmented button {
  border: 0; background: transparent; padding: 10px 8px; border-radius: 10px; cursor: pointer;
  font-weight: 600; color: var(--ink-soft); display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .2s, color .2s, box-shadow .2s;
}
.segmented button.on { background: var(--glass-strong); color: var(--ink); box-shadow: 0 2px 8px -2px rgba(0,0,0,.18); }
.segmented .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---- tipi di attività -------------------------------------------------- */
.dot.lavoro, .tag.lavoro { --c: var(--tipo-lavoro); }
.dot.tempo_morto, .tag.tempo_morto { --c: var(--tipo-tempo_morto); }
.dot.trasporto, .tag.trasporto { --c: var(--tipo-trasporto); }
.dot { background: var(--c, var(--ink-faint)); display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--c, var(--ink-soft));
  background: color-mix(in srgb, var(--c, var(--ink-faint)) 14%, transparent);
}
.tag.muted { --c: var(--ink-faint); }
.tag.ok { --c: var(--brand); }
.tag.warn { --c: var(--warning); }
.tag.err { --c: var(--danger); }
.tag.info { --c: var(--info); }

/* ---- stato corrente / timer ------------------------------------------- */
.now-card { padding: 26px; position: relative; overflow: hidden; }
.now-card::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 100% 0%, color-mix(in srgb, var(--c, var(--brand)) 22%, transparent), transparent 60%);
}
.now-card.idle::before { background: none; }
.now-label { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); font-weight: 600; }
.timer { font-size: 58px; font-weight: 700; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.05; margin: 6px 0; }
.now-what { font-size: 18px; font-weight: 600; }
.now-meta { color: var(--ink-soft); margin-top: 4px; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--brand)); position: relative; display: inline-block; }
.pulse::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--c, var(--brand));
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.now-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; position: relative; }

/* ---- statistiche ------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; border-radius: 16px; background: var(--glass-soft); border: 1px solid var(--hairline); }
.stat .k { font-size: 12px; color: var(--ink-soft); font-weight: 600; display: flex; gap: 6px; align-items: center; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---- elenchi registrazioni -------------------------------------------- */
.daynav { display: flex; align-items: center; gap: 8px; }
.daynav .input { width: auto; padding: 7px 10px; font-size: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: grid; grid-template-columns: 6px 110px 1fr auto auto; gap: 14px; align-items: center;
  padding: 12px 14px; border-radius: 16px; background: var(--glass-soft); border: 1px solid var(--hairline);
}
.entry .bar { width: 6px; align-self: stretch; border-radius: 3px; background: var(--c); }
.entry .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry .time small { display: block; color: var(--ink-faint); font-weight: 500; }
.entry .what { min-width: 0; }
.entry .what b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .what span { color: var(--ink-soft); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .dur { font-variant-numeric: tabular-nums; font-weight: 700; }
.entry .acts { display: flex; gap: 4px; }
@media (max-width: 640px) {
  .entry { grid-template-columns: 6px 1fr auto; }
  .entry .time { grid-column: 2; }
  .entry .what { grid-column: 2 / 4; grid-row: 2; }
  .entry .dur { grid-column: 3; grid-row: 1; }
  .entry .acts { grid-column: 2 / 4; grid-row: 3; justify-content: flex-end; }
  .entry .bar { grid-row: 1 / 4; }
}
.empty { text-align: center; color: var(--ink-faint); padding: 30px 10px; }

/* ---- tabelle ----------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.t th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint);
  font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--hairline); white-space: nowrap;
}
.t td { padding: 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr { transition: background .15s; }
.t tbody tr:hover { background: var(--glass-soft); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; }
.t .nowrap { white-space: nowrap; }
.t .muted, .muted { color: var(--ink-faint); }
.t tfoot td { font-weight: 700; border-top: 1px solid var(--hairline); border-bottom: 0; }

/* ---- dashboard in diretta --------------------------------------------- */
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.person { padding: 18px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden; }
.person::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--hairline));
}
.person.idle { opacity: .82; }
.person .head { display: flex; align-items: center; gap: 10px; }
.person .head .avatar { width: 38px; height: 38px; }
.person .head .n { font-weight: 650; }
.person .head .u { font-size: 12px; color: var(--ink-faint); }
.person .head .spacer { flex: 1; }
.person .activity { font-weight: 600; }
.person .activity .sub { display: block; font-weight: 400; color: var(--ink-soft); font-size: 13px; }
.person .clock { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.person .foot { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--ink-soft); }
.person .foot .spacer { flex: 1; }
.person .actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: auto; padding-top: 4px; border-top: 1px solid var(--hairline); }
.live-summary { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- login ------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; padding: 36px 32px 30px; }
.login-card .logo { width: 100%; max-width: 280px; display: block; margin: 0 auto 8px; }
.login-card h1 { font-size: 20px; text-align: center; margin: 10px 0 24px; font-weight: 600; color: var(--ink-soft); }
.login-card .btn { width: 100%; margin-top: 6px; }
.login-foot { text-align: center; font-size: 12px; color: var(--ink-faint); margin-top: 18px; }

/* ---- modale ------------------------------------------------------------ */
.modal-back {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 30, 25, .25); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fade .18s ease-out;
}
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; padding: 24px; background: var(--glass-strong); box-shadow: var(--shadow-lg); animation: pop .22s cubic-bezier(.2, .9, .3, 1.2); }
.modal.wide { max-width: 820px; }
.modal h3 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.01em; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal .actions .left { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(8px); } }

/* ---- notifiche --------------------------------------------------------- */
[data-recent] { align-items: center; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 12px 18px; border-radius: 14px; font-weight: 500; max-width: 90vw;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg); animation: pop .25s ease-out;
  display: flex; gap: 10px; align-items: center;
}
.toast.err { border-left: 4px solid var(--danger); }
.toast.ok { border-left: 4px solid var(--brand); }

/* ---- varie ------------------------------------------------------------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
.toolbar label.field { min-width: 150px; }
.hint { font-size: 13px; color: var(--ink-soft); }
.alert { padding: 12px 16px; border-radius: 14px; background: color-mix(in srgb, var(--warning) 16%, transparent); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); font-size: 14px; }
.diff { font-size: 12px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--ink-soft); white-space: pre-wrap; word-break: break-word; }
.diff del { color: var(--danger); text-decoration: line-through; }
.diff ins { color: var(--brand); text-decoration: none; }
.history { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.history .h { padding: 10px 12px; border-radius: 12px; background: var(--glass-soft); border: 1px solid var(--hairline); font-size: 13px; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--hairline); border-top-color: var(--brand); animation: rot .8s linear infinite; margin: 40px auto; }
@keyframes rot { to { transform: rotate(360deg); } }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; background: var(--glass-soft); padding: 1px 6px; border-radius: 6px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; top: 8px; }
  .topbar .logo { height: 28px; }
  .nav { order: 3; flex-basis: 100%; }
  .usermenu { margin-left: auto; }
  .usermenu .who { display: none; }
  .timer { font-size: 46px; }
  .page-title h1 { font-size: 24px; }
}

/* ---- piscine ----------------------------------------------------------- */
a.pisc-card { text-decoration: none; color: inherit; cursor: pointer; transition: transform .15s, box-shadow .2s; }
a.pisc-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.pisc-card.da_produrre { --c: var(--info); }
.pisc-card.in_lavorazione { --c: var(--brand); }
.pisc-card.completato { --c: var(--ink-faint); opacity: .85; }
.pisc-card.annullato { --c: var(--danger); opacity: .7; }
.progress { height: 8px; border-radius: 4px; background: var(--hairline); overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-light), var(--brand)); border-radius: 4px; transition: width .3s; }
.pisc-lista tr.done td { opacity: .5; }
.pisc-lista tr.done td:nth-child(2) b { text-decoration: line-through; }
.pisc-check { width: 20px; height: 20px; accent-color: var(--brand); cursor: pointer; }
.t tr.pisc-missing td { background: color-mix(in srgb, var(--danger) 10%, transparent); }
details summary::-webkit-details-marker { color: var(--brand); }

.lista-link { display: grid; grid-template-columns: minmax(0, 1fr) 110px auto; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: 16px; background: var(--glass-soft); border: 1px solid var(--hairline);
  text-decoration: none; color: inherit; transition: background .15s, transform .15s; }
.lista-link:hover { background: var(--glass-strong); transform: translateY(-1px); }
.lista-link .what { min-width: 0; }
.lista-link .what b { display: block; }
.lista-link .what span { display: block; color: var(--ink-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
