/* Design system in stile shadcn/ui, implementato in CSS puro.
   Palette: navy per il testo, teal per le azioni primarie,
   coral solo per valore del creep e azioni distruttive. */

:root {
  --navy: #1a2b4a;
  --teal: #2a9d8f;
  --teal-dark: #23867b;
  --coral: #e76f51;
  --coral-soft: #fdf1ec;
  --coral-border: #f6cdbd;

  --background: #ffffff;
  --foreground: var(--navy);
  --muted: #64748b;
  --muted-bg: #f8fafc;
  --border: #e2e8f0;
  --ring: rgba(42, 157, 143, 0.25);
  --ring-danger: rgba(231, 111, 81, 0.3);
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 10px -2px rgb(26 43 74 / 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;

  /* Footer sempre ancorato al fondo della viewport anche con poco contenuto. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* width: 100% — i margini auto del container disattiverebbero lo stretch flex */
body > main { flex: 1 0 auto; width: 100%; }

.container {
  max-width: 56rem;
  margin-inline: auto;
  padding-inline: 1.5rem;
}

main.container { padding-block: 2rem 5rem; }

h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 0.25rem; }
h2 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.015em; margin: 2rem 0 0.75rem; }
h3 { font-size: 0.9375rem; font-weight: 600; margin: 0; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); margin-top: 0; }

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--background);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 4rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--navy);
}

.brand:hover { text-decoration: none; }

.brand svg { height: 1.75rem; width: auto; display: block; }

.wordmark {
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--navy);
}

.wordmark .wm-log { color: var(--teal); }

.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links form { margin: 0; }

.nav-link { color: var(--muted); font-weight: 500; }
.nav-link:hover { color: var(--navy); text-decoration: none; }

/* ---------- Bottoni ---------- */

button, input[type="submit"] { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.25rem;
  padding: 0 1rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.06s;
}

a.btn:hover { text-decoration: none; }

/* Icons inside buttons: sized in em so they track the label, and nudged
   slightly on hover for a bit of life. */
.btn svg { width: 1.05em; height: 1.05em; flex: none; transition: transform 0.15s ease; }
.btn:hover svg { transform: scale(1.12); }
.btn:active { transform: translateY(1px); }

/* Keyboard focus ring — buttons previously had none (only inputs did). */
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn-danger:focus-visible,
.btn-ghost-danger:focus-visible { box-shadow: 0 0 0 3px var(--ring-danger); }

/* The trash icon gives a little shake on hover — personality in the details. */
.btn-danger:hover svg,
.btn-ghost-danger:hover svg { animation: btn-shake 0.4s ease; transform: none; }

@keyframes btn-shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-1.5px) rotate(-7deg); }
  75% { transform: translateX(1.5px) rotate(7deg); }
}

/* Copy button: copy icon swaps to an animated check while "Copied!" shows. */
.btn-icon { display: inline-flex; align-items: center; }
.btn .icon-check { display: none; }
.btn.is-copied .icon-copy { display: none; }
.btn.is-copied .icon-check { display: inline-flex; animation: btn-pop 0.3s ease; }

@keyframes btn-pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .btn svg { transition: none; }
  .btn:hover svg,
  .btn-danger:hover svg,
  .btn-ghost-danger:hover svg,
  .btn.is-copied .icon-check { animation: none; transform: none; }
}

.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }

.btn-outline { background: var(--background); border-color: var(--border); color: var(--navy); box-shadow: var(--shadow-sm); }
.btn-outline:hover { background: var(--muted-bg); }

.btn-danger { background: var(--background); border-color: var(--coral-border); color: var(--coral); box-shadow: var(--shadow-sm); }
.btn-danger:hover { background: var(--coral-soft); }

.btn-ghost-danger { background: transparent; border-color: transparent; color: var(--coral); height: 2rem; padding: 0 0.625rem; }
.btn-ghost-danger:hover { background: var(--coral-soft); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); height: 2rem; padding: 0 0.625rem; }
.btn-ghost:hover { background: var(--muted-bg); color: var(--navy); }

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }

/* ---------- Form ---------- */

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"] {
  display: block;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--foreground);
  background: var(--background);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--ring);
}

input::placeholder { color: #94a3b8; }

.field { margin-bottom: 1rem; }

.hint { font-size: 0.8125rem; color: var(--muted); margin: 0.375rem 0 0; }

.form-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 1.5rem; }

.form-errors {
  background: var(--coral-soft);
  border: 1px solid var(--coral-border);
  border-radius: var(--radius);
  padding: 0.625rem 1rem;
  margin-bottom: 1rem;
}

.form-errors ul { margin: 0; padding-left: 1.1rem; }
.form-errors li { color: var(--coral); }

/* ---------- Messaggi flash ---------- */

.flash {
  padding: 0.625rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
  margin: 0 0 1.5rem;
  overflow-wrap: anywhere;
}

.flash-notice { background: #effaf8; border-color: #b8e4de; color: var(--teal-dark); }
.flash-alert { background: var(--coral-soft); border-color: var(--coral-border); color: var(--coral); }

/* ---------- Breadcrumb ---------- */

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

.breadcrumb-link { color: var(--muted); font-weight: 500; }
.breadcrumb-link:hover { color: var(--navy); text-decoration: none; }
.breadcrumb-sep { display: inline-flex; color: #cbd5e1; }
.breadcrumb-sep svg { width: 0.875rem; height: 0.875rem; }
.breadcrumb-current { color: var(--muted); }

/* ---------- Intestazione pagina ---------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.page-header h1 { margin: 0; }

.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.page-actions form { margin: 0; }

/* Section heading with a trailing action (e.g. "Logged requests" + New). */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 0.75rem;
}
.section-header h2 { margin: 0; }

/* ---------- Modale (native <dialog>) ---------- */

.modal {
  width: min(34rem, calc(100vw - 2rem));
  margin: auto;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  background: var(--background);
  color: var(--foreground);
}

.modal::backdrop { background: rgba(26, 43, 74, 0.45); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.modal-head h2 { margin: 0; }

/* Inside the modal the entry form stacks vertically, with a full-width submit. */
.modal .entry-form-fields { grid-template-columns: 1fr; gap: 1rem; }
.modal .entry-form-fields .btn { width: 100%; }

/* ---------- Numeri grandi ---------- */

.stats {
  display: flex;
  gap: 3rem;
  background: #f1f5f9;
  border: 1px solid #dfe6ef;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

.stat { display: flex; flex-direction: column; gap: 0.125rem; }

.stat-value {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.creep-value { color: var(--coral); }

/* ---------- Lista progetti ---------- */

.project-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.project-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.project-card:hover {
  text-decoration: none;
  border-color: #cbd5e1;
  box-shadow: var(--shadow-md);
}

.project-card h3 { margin-bottom: 0.375rem; }
.project-card .meta { margin: 0; color: var(--muted); }

/* ---------- Form entry inline ---------- */

.entry-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem;
  margin-bottom: 0.5rem;
}

.entry-form-fields {
  display: grid;
  grid-template-columns: 3fr 1fr 1.3fr auto;
  gap: 0.75rem;
  align-items: end;
}

.entry-form-fields .field { margin: 0; }

@media (max-width: 720px) {
  .entry-form-fields { grid-template-columns: 1fr; }
  .stats { flex-direction: column; gap: 1.25rem; }

  /* Per-row Edit/Delete collapse to icon-only to save horizontal space
     (the aria-label keeps them named for screen readers). */
  .entry-actions .btn-label { display: none; }
  .entry-actions .btn { min-width: 2rem; padding: 0 0.5rem; }

  /* Same treatment for the crowded project header actions, so the row of
     Summary/Archive/Edit/Delete stays on one line instead of wrapping. */
  .page-actions--icons .btn-label { display: none; }
  .page-actions--icons .btn { min-width: 2.25rem; padding: 0 0.6rem; }
}

/* ---------- Tabelle ---------- */

/* Su schermi stretti la tabella scrolla dentro il suo box invece di
   allargare l'intera pagina (overflow orizzontale del viewport). */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: var(--muted-bg); }

tfoot th { color: var(--navy); font-size: 0.875rem; }

td form { margin: 0; display: inline; }

.num { text-align: right; }

.entry-date { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.entry-actions { white-space: nowrap; }
.entry-actions form { display: inline-block; }

/* Riga in modifica inline */
.entry-edit-row td { background: var(--muted-bg); padding: 1rem 0.75rem; }
.entry-edit-row:hover { background: transparent; }
.entry-edit-actions { display: flex; gap: 0.5rem; }

/* ---------- Selezione multipla righe (bulk) ---------- */

.bulk-form { display: none; }

/* Only show the bulk bar once at least one row is selected. A class with
   display:flex would otherwise win over the [hidden] attribute. */
.bulk-bar[hidden] { display: none; }

.col-check { width: 1%; white-space: nowrap; }
.col-check input { width: 1rem; height: 1rem; accent-color: var(--teal); cursor: pointer; }

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.5rem 0.875rem;
  margin-bottom: 0.75rem;
  background: var(--muted-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bulk-count { color: var(--muted); font-size: 0.8125rem; }
.bulk-count strong { color: var(--navy); }
.bulk-actions { display: flex; gap: 0.5rem; }

/* Done entries: dimmed, struck through, dropped from the active total. */
.entries-table tr.is-done td { color: var(--muted); }
.entries-table tr.is-done .entry-desc { text-decoration: line-through; text-decoration-color: var(--border); }
.entries-table tr.is-done:hover { background: transparent; }

.badge-done {
  background: #effaf8;
  border-color: #b8e4de;
  color: var(--teal-dark);
  text-decoration: none;
  margin-left: 0.375rem;
}

/* On phones the entries list drops the table grid and becomes a stack of
   cards — readable and tappable without horizontal scrolling. Scoped to
   #entries so the summary table is left alone. */
@media (max-width: 600px) {
  #entries .table-scroll { overflow-x: visible; }
  #entries .entries-table thead { display: none; }
  #entries .entries-table,
  #entries .entries-table tbody { display: block; width: 100%; }

  #entries .entries-table tr:not(.entry-edit-row) {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "check desc    hours"
      "check date    actions";
    column-gap: 0.75rem;
    row-gap: 0.25rem;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.5rem;
  }

  #entries .entries-table tr:not(.entry-edit-row):hover { background: transparent; }

  #entries .entries-table tr:not(.entry-edit-row) td {
    display: block;
    border: none;
    padding: 0;
  }

  #entries .entries-table .col-check { grid-area: check; }
  #entries .entries-table .entry-desc { grid-area: desc; font-weight: 500; white-space: normal; }
  #entries .entries-table .entry-hours { grid-area: hours; text-align: right; font-weight: 700; font-size: 1rem; }
  #entries .entries-table .entry-date { grid-area: date; font-size: 0.75rem; }
  #entries .entries-table .entry-actions { grid-area: actions; text-align: right; }

  /* The inline-edit row stays a normal stacked block, not a card grid. */
  #entries .entries-table tr.entry-edit-row,
  #entries .entries-table tr.entry-edit-row > td { display: block; width: 100%; }
}

/* ---------- Auth ---------- */

.auth-card {
  max-width: 24rem;
  margin: 3.5rem auto 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 2rem;
}

.auth-card h1 { margin-top: 0; }
.auth-card .muted { margin-bottom: 1.5rem; }

.auth-footer {
  margin: 1.5rem 0 0;
  text-align: center;
  color: var(--muted);
}

/* ---------- Badge e archiviati ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--muted-bg);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.25rem 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

h1 .badge, h3 .badge { margin-left: 0.375rem; }

.project-card.is-archived { background: var(--muted-bg); }
.project-card.is-archived h3 { color: var(--muted); }

.archived-note {
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--muted-bg);
  color: var(--muted);
  padding: 1rem 1.5rem;
}

/* ---------- Varie ---------- */

.empty-state { color: var(--muted); font-style: italic; }

.summary-period { color: var(--muted); margin-top: 0; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  text-align: center;
}

.footer-links { display: flex; gap: 1.25rem; align-items: center; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--navy); }

.footer-link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}

.footer-link-btn:hover { color: var(--navy); text-decoration: underline; }

/* ---------- Banner consenso (vanilla-cookieconsent) ---------- */

#cc-main {
  --cc-font-family: var(--pico-font-family, system-ui, sans-serif);
  --cc-btn-primary-bg: var(--teal);
  --cc-btn-primary-border-color: var(--teal);
  --cc-btn-primary-hover-bg: #23867b;
  --cc-btn-primary-hover-border-color: #23867b;
  --cc-primary-color: var(--navy);
  --cc-modal-border-radius: 0.75rem;
  --cc-btn-border-radius: 0.375rem;
}

/* ---------- Pagine legali ---------- */

.legal {
  max-width: 44rem;
  margin: 0 auto;
  padding-bottom: 2rem;
}

.legal h1 { margin-bottom: 0.25rem; }

.legal-meta {
  color: var(--muted);
  font-size: 0.8125rem;
  margin: 0 0 2rem;
}

.legal h2 {
  font-size: 1rem;
  margin-top: 2rem;
}

.legal p, .legal li { line-height: 1.7; }

.legal ul { padding-left: 1.25rem; }

.legal table { margin: 1rem 0; }

.legal-consent {
  margin-top: 1rem;
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: center;
}
