/* ==========================================================================
   GALGI SRL — Portale Strumenti Ufficio Tecnico
   Foglio di stile principale
   ========================================================================== */

/* ---------- Token di design (modifica qui colori e misure) ---------- */
:root {
  --brand: #d42a26;          /* rosso GALGI */
  --brand-strong: #a91f1c;
  --brand-soft: #fdeceb;
  --accent: #e8302c;         /* rosso logo */
  --accent-soft: #fdeceb;

  --bg: #f5f5f6;
  --surface: #ffffff;
  --surface-2: #f9f9fa;
  --border: #e2e1e4;
  --text: #1f1d20;
  --text-muted: #625f66;

  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --warn: #b86e00;
  --warn-soft: #fff1d6;
  --danger: #c0392b;
  --danger-soft: #fbe5e2;

  --sidebar-bg: #1c1b1d;     /* nero logo */
  --sidebar-text: #d6d4d6;
  --sidebar-muted: #8d8a8e;
  --sidebar-active: #2e2c30;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --sidebar-w: 264px;
  --topbar-h: 60px;

  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

[data-theme="dark"] {
  --brand: #f0605a;
  --brand-strong: #f58b86;
  --brand-soft: #3a1918;
  --accent: #f0605a;
  --accent-soft: #3a1918;

  --bg: #121113;
  --surface: #1b1a1c;
  --surface-2: #222124;
  --border: #333135;
  --text: #ecebed;
  --text-muted: #a3a0a5;

  --ok: #4cc27f;
  --ok-soft: #133022;
  --warn: #f0b04a;
  --warn-soft: #36290f;
  --danger: #ef7466;
  --danger-soft: #3a1a17;

  --sidebar-bg: #0c0b0d;
  --sidebar-text: #d0ced2;
  --sidebar-muted: #7d7a80;
  --sidebar-active: #252327;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1em; }
svg.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: #fff;
}
.sidebar__brand:hover { text-decoration: none; }
.sidebar__brand img { width: 36px; height: 36px; }
.sidebar__brand strong { display: block; font-size: 1.05rem; letter-spacing: .04em; }
.sidebar__brand span { display: block; font-size: .72rem; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .08em; }

.sidebar__search { padding: 14px 14px 6px; }
.sidebar__search input {
  width: 100%;
  padding: 8px 10px 8px 34px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.06) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237f93ab' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E") no-repeat 11px center;
  color: #fff;
  font: inherit; font-size: .9rem;
}
.sidebar__search input::placeholder { color: var(--sidebar-muted); }
.sidebar__search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; }
.nav-group { margin-top: 14px; }
.nav-group__title {
  padding: 0 10px 6px;
  font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--sidebar-muted);
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: .92rem;
}
.nav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav-link.is-active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav-link .icon { width: 18px; height: 18px; opacity: .85; }
.nav-link__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link.is-disabled { opacity: .5; }
.nav-empty { padding: 10px; font-size: .85rem; color: var(--sidebar-muted); }

.sidebar__footer {
  padding: 12px 18px;
  font-size: .75rem;
  color: var(--sidebar-muted);
  border-top: 1px solid rgba(255,255,255,.07);
}

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.icon-btn.topbar__menu { display: none; }
.breadcrumb { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb strong { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { display: flex; align-items: center; gap: 6px; }

.content { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px; }

.footer {
  padding: 16px 28px;
  font-size: .8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

.backdrop { display: none; }

/* ---------- Componenti ---------- */
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
[data-theme="dark"] .btn--primary { color: #1a0a0a; }
.btn--primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn .icon { width: 18px; height: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card__header h2, .card__header h3 { margin: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .72rem; font-weight: 600;
  white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.alert {
  display: flex; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: .9rem;
  margin-bottom: 16px;
}
.alert--info { background: var(--brand-soft); border-color: transparent; color: var(--text); }
.alert--warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.alert--danger { background: var(--danger-soft); border-color: transparent; color: var(--text); }

/* ---------- Home ---------- */
.hero {
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap;
  padding: 28px 30px;
  margin-bottom: 26px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, #1c1b1d 0%, #2f2c31 100%);
  color: #fff;
}
[data-theme="dark"] .hero { background: linear-gradient(120deg, #1f1d21 0%, #2a2729 100%); border: 1px solid var(--border); }
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px;
  width: 260px; height: 260px; border-radius: 50%;
  border: 36px solid rgba(232,48,44,.45);
}
.hero h1 { color: #fff; margin-bottom: 4px; }
.hero p { margin: 0; color: rgba(255,255,255,.8); max-width: 60ch; }
.hero__stats { display: flex; gap: 12px; position: relative; z-index: 1; }
.stat {
  min-width: 110px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
}
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .78rem; color: rgba(255,255,255,.75); }

.section { margin-bottom: 30px; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section__head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }
.section__head p { margin: 0; color: var(--text-muted); font-size: .88rem; white-space: nowrap; }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tool-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
a.tool-card:hover { text-decoration: none; border-color: var(--brand); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.tool-card.is-disabled { opacity: .7; cursor: default; }
.tool-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tool-card__icon {
  display: grid; place-items: center;
  width: 42px; height: 42px;
  border-radius: 9px;
  background: var(--brand-soft); color: var(--brand);
}
.tool-card h3 { margin: 0; }
.tool-card p { margin: 0; font-size: .87rem; color: var(--text-muted); }

.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); }

/* ---------- Pagina strumento ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head__title { display: flex; gap: 14px; align-items: flex-start; }
.page-head__title .tool-card__icon { width: 48px; height: 48px; }
.page-head p { margin: 0; color: var(--text-muted); }

.tool-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 5px; font-size: .84rem; font-weight: 600; }
.field .hint { margin-top: 4px; font-size: .78rem; color: var(--text-muted); }
.input-group { display: flex; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: .92rem;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .unit {
  display: grid; place-items: center;
  padding: 0 12px;
  border: 1px solid var(--border); border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  color: var(--text-muted); font-size: .85rem;
}
.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.result-main {
  padding: 18px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  margin-bottom: 14px;
}
.result-main small { display: block; color: var(--text-muted); font-size: .8rem; }
.result-main b { font-size: 2rem; font-variant-numeric: tabular-nums; }
.result-main b span { font-size: 1rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }

.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.table-wrap { overflow-x: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .tool-layout { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .icon-btn.topbar__menu { display: inline-grid; }
  .content { padding: 20px 16px; }
  .footer { padding: 14px 16px; }
  .hero { padding: 22px 20px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Stampa ---------- */
@media print {
  .sidebar, .topbar, .footer, .form-actions, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* Evita lo "sfarfallio" prima che app.js costruisca il layout */
body:not(.pronto) #page { visibility: hidden; }

/* ---------- Pagina di accesso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login__card { width: 100%; max-width: 400px; padding: 32px 28px; }
.login__card .field { margin-bottom: 14px; }
.login__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login__brand img { width: 48px; height: 48px; }
.login__brand strong { display: block; font-size: 1.1rem; letter-spacing: .04em; }
.login__brand span { display: block; font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.login h1 { font-size: 1.35rem; margin-bottom: 4px; }
.login__sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 20px; }
.login__submit { width: 100%; margin-top: 6px; padding: 11px 16px; }
.login__foot { margin: 18px 0 0; font-size: .78rem; color: var(--text-muted); text-align: center; }

/* ---------- Utente collegato (barra superiore) ---------- */
.topbar__user { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; font-size: .88rem; font-weight: 600; color: var(--text); }
.topbar__user:hover { background: var(--surface-2); text-decoration: none; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; font-size: .8rem; font-weight: 700; }
@media (max-width: 520px) { .topbar__user .topbar__user-name { display: none; } }
