/* ============================================================
   style.css – Mobile-first, dark-mode, glassmorphism
   Torino Crea – Rapportini PWA
   ============================================================ */

/* ---- Google Font ---- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---- CSS Variables – Light Theme ---- */
:root {
  --primary:       #132339;  /* TorinooCrea brand navy */
  --primary-light: #1d3a5c;
  --accent:        #F0A500;
  --accent-dark:   #C98A1A;
  --bg:            #f2f5f9;
  --surface:       #ffffff;
  --surface-2:     #eef1f6;
  --glass:         rgba(255,255,255,0.7);
  --glass-border:  rgba(19,35,57,0.10);
  --text:          #1a2535;
  --text-muted:    #6b7d92;
  --success:       #1a7f37;
  --warning:       #a8760f;
  --error:         #b91c1c;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 2px 12px rgba(19,35,57,0.08);
  --shadow-md:     0 4px 24px rgba(19,35,57,0.12);
  --transition:    .2s ease;
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: opacity var(--transition); }
a:hover { opacity: .8; }

img { max-width: 100%; display: block; }

/* ---- Layout ---- */
.app-header {
  background: var(--primary);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}
/* Logo invertito per header scuro */
.header-logo img {
  filter: brightness(0) invert(1);
  height: 28px;
  width: auto;
}
.header-nav { display: flex; align-items: center; gap: .75rem; }
.user-badge {
  font-size: .8rem;
  color: rgba(255,255,255,.7);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 5rem;
}

/* ---- Glass Card (light) ---- */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

/* ---- Buttons ---- */
.btn-primary, .btn-secondary, .btn-small, .btn-icon, .btn-back, .btn-now {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--accent);
  color: #000;
  padding: .75rem 1.25rem;
  font-size: 1rem;
  box-shadow: 0 2px 12px rgba(243,156,18,.3);
}
.btn-primary:hover { background: var(--accent-dark); box-shadow: 0 4px 16px rgba(243,156,18,.4); }
.btn-primary:active { transform: scale(.98); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  padding: .75rem 1.25rem;
  font-size: 1rem;
  border: 1px solid var(--glass-border);
}
.btn-secondary:hover { background: var(--surface); }

.btn-small {
  background: var(--primary-light);
  color: #fff;
  padding: .35rem .7rem;
  font-size: .82rem;
}
.btn-danger {
  background: rgba(218,54,51,.2);
  color: #f1706e;
  border: 1px solid rgba(218,54,51,.35);
  padding: .35rem .7rem;
  font-size: .82rem;
}
.btn-danger:hover { background: rgba(218,54,51,.35); }
.btn-icon {
  background: transparent;
  color: rgba(255,255,255,.8);
  padding: .4rem;
  border-radius: 50%;
}
.btn-icon:hover { background: rgba(255,255,255,.12); color: #fff; }

.btn-back {
  background: transparent;
  color: var(--text-muted);
  padding: .35rem;
}
.btn-back:hover { color: var(--text); }

.btn-now {
  background: var(--primary);
  color: var(--accent);
  padding: .3rem .65rem;
  font-size: .78rem;
  margin-top: .3rem;
  width: 100%;
}
.btn-now:hover { background: var(--primary-light); }

.btn-block { width: 100%; }
.btn-lg { padding: 1rem 1.25rem; font-size: 1.05rem; }

/* ---- Alerts ---- */
.alert {
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .9rem;
}
/* ---- Alert (light) ---- */
.alert-error   { background: rgba(185,28,28,.08); border: 1px solid rgba(185,28,28,.25); color: #b91c1c; }
.alert-success { background: rgba(26,127,55,.08); border: 1px solid rgba(26,127,55,.25); color: #1a7f37; }
.error-list { padding-left: 1.2rem; }

/* ---- Form ---- */
.field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: .9rem;
}
label {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .02em;
}
input, select, textarea {
  background: var(--surface);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: .75rem .9rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(19,35,57,.12);
}
input.is-error, select.is-error, textarea.is-error {
  border-color: var(--error);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b949e' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .9rem center; padding-right: 2.5rem; }
textarea { resize: vertical; min-height: 100px; }
select:disabled { opacity: .5; }

input[type="date"], input[type="time"] { color-scheme: light; }

.input-wrap { position: relative; }
.input-wrap input { padding-right: 2.8rem; }
.toggle-pw {
  position: absolute;
  right: .75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  display: flex;
}

/* ---- KPI Cards ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.kpi-wide { grid-column: 1 / -1; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  box-shadow: var(--shadow);
}
.kpi-card-warn { border-color: rgba(168,118,15,.3); background: rgba(168,118,15,.04); }
.kpi-header { display: flex; align-items: baseline; justify-content: space-between; }
.kpi-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.kpi-value { font-size: 1.8rem; font-weight: 800; line-height: 1; margin: .15rem 0; }
.kpi-value.kpi-navy  { color: var(--primary); }
.kpi-value.kpi-green { color: #1a7f37; }
.kpi-value.kpi-amber { color: #a8760f; }
.kpi-sub { font-size: .78rem; color: var(--text-muted); }

/* Progress bar */
.kpi-progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin: .5rem 0 .3rem;
}
.kpi-progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.kpi-progress-fill.kpi-navy  { background: var(--primary); }
.kpi-progress-fill.kpi-green { background: #1a7f37; }
.kpi-progress-fill.kpi-amber { background: #a8760f; }
.kpi-progress-label { font-size: .78rem; color: var(--text-muted); }

/* ---- Auth Page ---- */
.auth-wrap {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow-md);
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
}
.auth-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}
.auth-logo img { margin: 0 auto .75rem; }
.auth-logo p  { color: var(--text-muted); font-size: .9rem; margin-top: .3rem; }
.form-auth { display: flex; flex-direction: column; gap: .1rem; }

/* ---- Dashboard ---- */
.dashboard { padding-top: .5rem; }
.dashboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.dashboard-hero h2 { font-size: 1.4rem; font-weight: 700; }
.dashboard-section { margin-bottom: 1.75rem; }
.section-title {
  font-size: .9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 .35rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-warning { background: rgba(210,153,34,.25); color: var(--warning); }
.text-muted { color: var(--text-muted); font-size: .9rem; }

/* ---- Report List ---- */
.report-list { list-style: none; display: flex; flex-direction: column; gap: .6rem; }
.report-card {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow);
}
.report-card:hover { border-color: rgba(19,35,57,.2); box-shadow: var(--shadow-md); }
.report-card.draft { border-left: 3px solid var(--warning); }
.report-main { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.report-main strong { font-size: .97rem; font-weight: 600; }
.commessa-tag {
  font-size: .78rem;
  background: rgba(19,35,57,.08);
  color: var(--primary);
  padding: .15rem .55rem;
  border-radius: 99px;
  white-space: nowrap;
}
.report-meta { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; font-size: .82rem; color: var(--text-muted); }
.report-note { font-size: .82rem; color: var(--text-muted); font-style: italic; }
.sync-badge { font-size: .9rem; }

.empty-state {
  background: var(--surface);
  border: 1.5px dashed var(--glass-border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}

/* ---- Rapportino Form Page ---- */
.form-page { padding-top: .25rem; }
.form-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.form-header h2 { font-size: 1.25rem; font-weight: 700; flex: 1; }
.form-section {
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 1rem 1rem .4rem;
  margin-bottom: .85rem;
  box-shadow: var(--shadow);
}
.section-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--primary);
  margin-bottom: .75rem;
}
.time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.duration-display {
  margin-top: .5rem;
  margin-bottom: .4rem;
}
.duration-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  padding: .5rem 0;
}
.form-actions { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.25rem; }
.autosave-status {
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: .5rem;
  min-height: 1.2rem;
}

/* ---- Autocomplete Dropdown ---- */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface-2);
  border: 1px solid var(--glass-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.autocomplete-wrap { position: relative; }
.autocomplete-dropdown li {
  padding: .75rem 1rem;
  cursor: pointer;
  font-size: .9rem;
  transition: background var(--transition);
}
.autocomplete-dropdown li:hover,
.autocomplete-dropdown li.active { background: var(--glass); color: var(--accent); }
.autocomplete-dropdown li small { display: block; color: var(--text-muted); font-size: .76rem; }

/* ---- 404 ---- */
.not-found { text-align: center; padding: 4rem 1rem; }
.not-found h2 { font-size: 5rem; font-weight: 800; color: var(--primary-light); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: rgba(19,35,57,.2); border-radius: 4px; }

/* ---- Time-Slot Card Picker ---- */
.time-picker-field { gap: .4rem; }

.time-picker-field label {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.time-selected-badge {
  display: inline-block;
  background: var(--primary);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 700;
  padding: .1rem .55rem;
  border-radius: 99px;
  min-width: 3.2rem;
  text-align: center;
  opacity: 0;
  transform: scale(.8);
  transition: opacity var(--transition), transform var(--transition);
}
.time-selected-badge.visible {
  opacity: 1;
  transform: scale(1);
}

/* Scrollable row of slot pills */
.time-slots-wrap {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding: .35rem .1rem .55rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;          /* Firefox */
}
.time-slots-wrap::-webkit-scrollbar { display: none; }

/* Individual slot pill */
.time-slot {
  flex: 0 0 auto;
  scroll-snap-align: start;
  padding: .45rem .7rem;
  border-radius: 99px;
  border: 1.5px solid var(--glass-border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition),
    box-shadow var(--transition),
    transform .1s ease;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.2;
  user-select: none;
}
.time-slot:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface-2);
  box-shadow: 0 2px 8px rgba(19,35,57,.1);
}
.time-slot:active:not(:disabled) { transform: scale(.95); }

/* Selected state */
.time-slot.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 3px 12px rgba(19,35,57,.25);
}

/* Mezzanotte / slot speciale */
.time-slot.midnight {
  border-color: rgba(19,35,57,.25);
  background: var(--surface-2);
  color: var(--text-muted);
  font-style: italic;
}
.time-slot.midnight.selected {
  background: var(--primary);
  color: var(--accent);
  font-style: normal;
}

/* Disabled (slot fine < slot inizio) */
.time-slot:disabled {
  opacity: .3;
  cursor: not-allowed;
  pointer-events: none;
}

/* Hint quando ancora non è stato scelto l'inizio */
.slots-hint {
  color: var(--text-muted);
  font-size: .84rem;
  padding: .4rem 0;
  font-style: italic;
}

/* Error highlight */
.is-error-field .time-slots-wrap {
  border-radius: var(--radius-sm);
  outline: 2px solid var(--error);
  outline-offset: 2px;
}

/* ---- Desktop refinements ---- */
@media (min-width: 600px) {
  .auth-card { padding: 2.5rem 2rem; }
  .form-section { padding: 1.25rem 1.25rem .6rem; }
  .dashboard-hero h2 { font-size: 1.6rem; }
}
