/* ===========================================================================
   Manutio — design system
   Mobile-first: le regole base valgono da 360px, i breakpoint aggiungono.
   =========================================================================== */

:root {
  /* --- colori di marca --- */
  --md-primary: #5A4FCF;
  --md-primary-dark: #463CA8;
  --md-primary-soft: #EEECFB;
  --md-accent: #00A896;
  --md-accent-soft: #E0F5F2;

  /* --- neutri --- */
  --md-bg: #F5F6F8;
  --md-surface: #FFFFFF;
  --md-surface-2: #FAFAFB;
  --md-border: #E4E5EA;
  --md-border-strong: #D2D4DB;
  --md-text: #1B1C22;
  --md-text-soft: #5C5F6C;
  --md-text-faint: #8A8D99;

  /* --- stati --- */
  --md-open: #2563EB;
  --md-open-soft: #E6EEFE;
  --md-hold: #C2760A;
  --md-hold-soft: #FDF1DC;
  --md-done: #15803D;
  --md-done-soft: #E3F5E9;
  --md-void: #6B7280;
  --md-void-soft: #EEEFF2;
  --md-late: #C81E1E;
  --md-late-soft: #FDECEC;

  /* --- forma --- */
  --md-r-sm: 8px;
  --md-r: 12px;
  --md-r-lg: 16px;
  --md-shadow: 0 1px 2px rgba(16, 18, 32, .05), 0 1px 3px rgba(16, 18, 32, .04);
  --md-shadow-lift: 0 4px 12px rgba(16, 18, 32, .08);

  /* --- misure --- */
  --md-touch: 44px;
  --md-bottomnav: 60px;
  --md-topbar: 56px;
}

html { -webkit-text-size-adjust: 100%; }

body,
.v-application {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--md-text);
  background: var(--md-bg);
}

.v-application { line-height: 1.5; }

/* nessuno scroll orizzontale involontario */
html, body { overflow-x: hidden; }

/* ===========================================================================
   Tipografia
   =========================================================================== */

.md-h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.md-h2 { font-size: 1.0625rem; font-weight: 650; letter-spacing: -.005em; }
.md-h3 { font-size: .9375rem; font-weight: 600; }
.md-body { font-size: .9375rem; }
.md-small { font-size: .8125rem; color: var(--md-text-soft); }
.md-tiny { font-size: .75rem; color: var(--md-text-faint); }
.md-eyebrow {
  font-size: .6875rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--md-text-faint);
}
.md-num { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }

@media (min-width: 960px) {
  .md-h1 { font-size: 1.625rem; }
  .md-h2 { font-size: 1.125rem; }
}

/* ===========================================================================
   Struttura di pagina
   =========================================================================== */

.md-page {
  padding: 12px 12px calc(var(--md-bottomnav) + 24px) 12px;
  max-width: 1360px;
  margin: 0 auto;
}

@media (min-width: 960px) {
  .md-page { padding: 20px 24px 32px 24px; }
}

.md-page-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.md-page-head .md-h1 { flex: 1 1 auto; min-width: 0; }

/* ===========================================================================
   Card
   =========================================================================== */

.md-card {
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  box-shadow: var(--md-shadow);
}

.md-card + .md-card { margin-top: 12px; }

.md-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--md-border);
}

.md-card-body { padding: 16px; }
.md-card-body-tight { padding: 12px; }

/* ===========================================================================
   Barra superiore e navigazione
   =========================================================================== */

.md-topbar {
  background: var(--md-surface) !important;
  color: var(--md-text) !important;
  border-bottom: 1px solid var(--md-border);
}

.md-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--md-text);
  text-decoration: none;
}

.md-brand-name { font-size: 1.0625rem; line-height: 1; }
.md-brand-sub {
  display: block;
  font-size: .6875rem;
  font-weight: 500;
  color: var(--md-text-faint);
  letter-spacing: .01em;
  margin-top: 2px;
}

/* --- barra inferiore (solo mobile) --- */
.md-bottomnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1005;
  display: flex;
  background: var(--md-surface);
  border-top: 1px solid var(--md-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.md-bottomnav button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--md-bottomnav);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--md-text-soft);
  font-size: .6875rem;
  font-weight: 550;
  cursor: pointer;
  padding: 6px 2px;
}

.md-bottomnav button.md-active { color: var(--md-primary); }
.md-bottomnav button.md-active .v-icon { transform: translateY(-1px); }
.md-bottomnav button span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- barra laterale (solo desktop) --- */
.md-side {
  background: var(--md-surface) !important;
  border-right: 1px solid var(--md-border) !important;
}

.md-side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  margin: 2px 8px;
  border-radius: var(--md-r-sm);
  color: var(--md-text-soft);
  font-size: .9375rem;
  font-weight: 550;
  cursor: pointer;
  border: 0;
  background: none;
  width: calc(100% - 16px);
  text-align: left;
}

.md-side-link:hover { background: var(--md-surface-2); color: var(--md-text); }

.md-side-link.md-active {
  background: var(--md-primary-soft);
  color: var(--md-primary-dark);
}

.md-side-group {
  padding: 14px 20px 6px 20px;
}

/* ===========================================================================
   Badge di stato — colore + icona + testo (mai solo colore)
   =========================================================================== */

/* Etichette di macro-area: discrete, con icona sempre presente.
   Il colore accompagna, non sostituisce, la parola. */
.md-area {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--md-text-soft);
  white-space: nowrap;
}

.md-st-doing { background: #EEF2FF; color: #4338CA; }

.md-area.is-a1 { color: #3F51B5; }
.md-area.is-a2 { color: #2E7D32; }

.md-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  border: 1px solid transparent;
}

.md-badge .v-icon { font-size: 14px !important; }

.md-st-open   { background: var(--md-open-soft); color: var(--md-open); border-color: #CFE0FD; }
.md-st-hold   { background: var(--md-hold-soft); color: var(--md-hold); border-color: #F6E2BD; }
.md-st-done   { background: var(--md-done-soft); color: var(--md-done); border-color: #C8E9D4; }
.md-st-void   { background: var(--md-void-soft); color: var(--md-void); border-color: #DEE0E5; }
.md-st-late   { background: var(--md-late-soft); color: var(--md-late); border-color: #F7CFCF; }

/* priorità alta */
.md-prio {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  font-weight: 650;
  color: var(--md-late);
}

/* ===========================================================================
   Lista attività — card su mobile, righe su desktop
   =========================================================================== */

.md-list { display: flex; flex-direction: column; gap: 10px; }

.md-task {
  position: relative;
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  box-shadow: var(--md-shadow);
  padding: 12px 12px 12px 15px;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.md-task:active { background: var(--md-surface-2); }

/* barra di stato laterale: rinforza il badge, non lo sostituisce */
.md-task::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--md-border-strong);
}

.md-task.is-open::before { background: var(--md-open); }
.md-task.is-hold::before { background: var(--md-hold); }
.md-task.is-done::before { background: var(--md-done); }
.md-task.is-void::before { background: var(--md-void); }
.md-task.is-late::before { background: var(--md-late); }

.md-task-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.md-task-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.md-task.is-done .md-task-title,
.md-task.is-void .md-task-title { color: var(--md-text-soft); }

.md-task-desc {
  font-size: .8125rem;
  color: var(--md-text-soft);
  line-height: 1.35;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.md-task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  font-size: .75rem;
  color: var(--md-text-faint);
}

.md-task-meta .md-meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.md-task-meta .md-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 190px;
}

.md-task-meta .v-icon { font-size: 14px !important; opacity: .75; }

/* tabella desktop */
.md-table { width: 100%; border-collapse: collapse; }

.md-table thead th {
  text-align: left;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--md-text-faint);
  padding: 10px 12px;
  border-bottom: 1px solid var(--md-border);
  white-space: nowrap;
}

.md-table tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--md-border);
  font-size: .875rem;
  vertical-align: middle;
}

.md-table tbody tr { cursor: pointer; }
.md-table tbody tr:hover { background: var(--md-surface-2); }
.md-table tbody tr:last-child td { border-bottom: 0; }

.md-cell-title { font-weight: 600; }
.md-cell-sub { font-size: .8125rem; color: var(--md-text-soft); }
.md-truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===========================================================================
   Stati vuoti, caricamento, errori
   =========================================================================== */

.md-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--md-text-soft);
}

.md-empty-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--md-primary-soft);
  color: var(--md-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.md-empty-title { font-weight: 650; color: var(--md-text); margin-bottom: 4px; }

.md-skeleton {
  background: linear-gradient(90deg, #ECEDF1 25%, #F4F5F7 37%, #ECEDF1 63%);
  background-size: 400% 100%;
  animation: md-shimmer 1.4s ease infinite;
  border-radius: var(--md-r-sm);
}

@keyframes md-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
  .md-skeleton { animation: none; }
}

.md-skel-card {
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  padding: 14px;
}

/* ===========================================================================
   Filtri
   =========================================================================== */

.md-filter-group + .md-filter-group { margin-top: 18px; }

.md-filter-label {
  font-size: .8125rem;
  font-weight: 650;
  color: var(--md-text);
  margin-bottom: 8px;
}

.md-choice-row { display: flex; flex-wrap: wrap; gap: 8px; }

.md-choice {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--md-border-strong);
  background: var(--md-surface);
  color: var(--md-text-soft);
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.md-choice:hover { border-color: var(--md-primary); color: var(--md-primary); }

.md-choice.md-on {
  background: var(--md-primary);
  border-color: var(--md-primary);
  color: #fff;
}

.md-choice:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}

/* pillola con il numero di filtri attivi */
.md-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--md-primary);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
}

/* foglio inferiore mobile */
.md-sheet {
  border-top-left-radius: var(--md-r-lg);
  border-top-right-radius: var(--md-r-lg);
  background: var(--md-surface);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.md-sheet-grip {
  width: 38px; height: 4px;
  border-radius: 999px;
  background: var(--md-border-strong);
  margin: 10px auto 4px auto;
}

.md-sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px 12px 16px;
  border-bottom: 1px solid var(--md-border);
}

.md-sheet-body { overflow-y: auto; padding: 16px; flex: 1 1 auto; }

.md-sheet-foot {
  display: flex; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0)) 16px;
  border-top: 1px solid var(--md-border);
  background: var(--md-surface);
}

/* ===========================================================================
   Dettaglio attività
   =========================================================================== */

.md-detail-hero {
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  box-shadow: var(--md-shadow);
  padding: 16px;
}

.md-detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
  margin: 10px 0 8px 0;
}

.md-facts { display: grid; grid-template-columns: 1fr; gap: 2px; }

@media (min-width: 600px) {
  .md-facts { grid-template-columns: 1fr 1fr; gap: 2px 20px; }
}

.md-fact {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--md-border);
  font-size: .875rem;
}

.md-fact:last-child { border-bottom: 0; }

.md-fact-k {
  flex: 0 0 96px;
  color: var(--md-text-faint);
  font-size: .8125rem;
}

.md-fact-v { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }

/* barra azioni fissa su mobile */
.md-actionbar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 1006;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0)) 12px;
  background: var(--md-surface);
  border-top: 1px solid var(--md-border);
  box-shadow: 0 -2px 10px rgba(16, 18, 32, .06);
}

.md-actionbar .v-btn { flex: 1 1 auto; }

@media (min-width: 960px) {
  .md-actionbar {
    position: static;
    box-shadow: none;
    border-top: 0;
    padding: 0;
    background: none;
    justify-content: flex-end;
  }
  .md-actionbar .v-btn { flex: 0 0 auto; }
}

/* ===========================================================================
   Commenti e cronologia
   =========================================================================== */

.md-thread { display: flex; flex-direction: column; gap: 14px; }

.md-comment { display: flex; gap: 10px; }

.md-comment-body {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--md-surface-2);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  padding: 10px 12px;
}

.md-comment-head {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 3px;
}

.md-comment-author { font-size: .8125rem; font-weight: 650; }
.md-comment-text { font-size: .875rem; overflow-wrap: anywhere; white-space: pre-wrap; }

.md-event {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: .8125rem; color: var(--md-text-soft);
}

.md-event-dot {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--md-surface-2);
  border: 1px solid var(--md-border);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--md-text-faint);
}

.md-event .v-icon { font-size: 15px !important; }

/* ===========================================================================
   Calendario
   =========================================================================== */

.md-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.md-cal-head {
  text-align: center;
  font-size: .6875rem;
  font-weight: 700;
  color: var(--md-text-faint);
  padding: 6px 0;
}

.md-cal-day {
  position: relative;
  min-height: 42px;
  border: 0;
  background: none;
  border-radius: var(--md-r-sm);
  font-size: .875rem;
  color: var(--md-text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.md-cal-day:hover:not(:disabled) { background: var(--md-surface-2); }
.md-cal-day.md-out { visibility: hidden; }

.md-cal-day.md-sel {
  background: var(--md-primary);
  color: #fff;
  font-weight: 700;
}

.md-cal-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--md-primary);
  display: block;
}

.md-cal-day.md-sel .md-cal-dot { background: #fff; }

/* ===========================================================================
   Statistiche
   =========================================================================== */

.md-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (min-width: 960px) {
  .md-kpis { grid-template-columns: repeat(4, 1fr); gap: 14px; }
}

.md-kpi {
  background: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--md-r);
  box-shadow: var(--md-shadow);
  padding: 14px;
}

.md-kpi-label {
  font-size: .75rem;
  color: var(--md-text-faint);
  font-weight: 600;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}

/* grafico a barre orizzontali: leggibile anche a 360px */
.md-bars { display: flex; flex-direction: column; gap: 10px; }

.md-bar-row { display: grid; grid-template-columns: 1fr; gap: 4px; }

.md-bar-head {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: .8125rem;
}

.md-bar-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--md-text);
}

.md-bar-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.md-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--md-surface-2);
  border: 1px solid var(--md-border);
  overflow: hidden;
}

.md-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--md-primary);
  min-width: 3px;
}

.md-bar-fill.is-open { background: var(--md-open); }
.md-bar-fill.is-hold { background: var(--md-hold); }
.md-bar-fill.is-done { background: var(--md-done); }
.md-bar-fill.is-void { background: var(--md-void); }

/* ===========================================================================
   Login
   =========================================================================== */

.md-login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--md-bg);
}

.md-login-side { display: none; }

.md-login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom, 0)) 18px;
}

.md-login-card { width: 100%; max-width: 380px; }

@media (min-width: 960px) {
  .md-login { grid-template-columns: 1.05fr .95fr; }

  .md-login-side {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    padding: 56px;
    color: #fff;
    background:
      radial-gradient(120% 120% at 0% 0%, #7C6BF0 0%, #5A4FCF 45%, #2F2A78 100%);
  }

  .md-login-claim {
    font-size: 2.125rem;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.15;
    max-width: 20ch;
  }

  .md-login-points { display: flex; flex-direction: column; gap: 12px; max-width: 40ch; }

  .md-login-point {
    display: flex; align-items: flex-start; gap: 10px;
    font-size: .9375rem;
    color: rgba(255, 255, 255, .92);
  }
}

/* ===========================================================================
   Pulsanti e campi — arrotondati, target touch adeguati
   =========================================================================== */

.v-btn {
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-weight: 600 !important;
  border-radius: var(--md-r-sm) !important;
}

.v-btn--size-default { min-height: var(--md-touch); }
.v-btn--icon { border-radius: 50% !important; }

/* su touch anche le azioni secondarie devono restare toccabili */
@media (max-width: 959.98px) {
  .v-btn--size-small { min-height: var(--md-touch); }
}

.v-field { border-radius: var(--md-r-sm) !important; }

/* i campi non devono innescare lo zoom automatico su iOS */
.v-field input,
.v-field textarea,
.v-field .v-field__input {
  font-size: 16px !important;
}

@media (min-width: 960px) {
  .v-field input,
  .v-field textarea,
  .v-field .v-field__input { font-size: .9375rem !important; }
}

.v-label { font-size: .875rem; }

/* focus sempre visibile */
.v-btn:focus-visible,
.md-task:focus-visible,
.md-side-link:focus-visible,
.md-bottomnav button:focus-visible {
  outline: 2px solid var(--md-primary);
  outline-offset: 2px;
}

.md-task:focus-visible { outline-offset: -2px; }

/* ===========================================================================
   Utilità
   =========================================================================== */

.md-row { display: flex; align-items: center; gap: 10px; }
.md-wrap { flex-wrap: wrap; }
.md-grow { flex: 1 1 auto; min-width: 0; }
.md-nowrap { white-space: nowrap; }
.md-hide-mobile { display: none; }
.md-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (min-width: 960px) {
  .md-hide-mobile { display: initial; }
  .md-only-mobile { display: none !important; }
}

.md-divider { height: 1px; background: var(--md-border); margin: 14px 0; }

.md-avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--md-primary-soft);
  color: var(--md-primary-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .6875rem; font-weight: 700;
  letter-spacing: .02em;
}

.md-avatar.md-lg { width: 38px; height: 38px; font-size: .8125rem; }
.md-avatar.md-empty-av { background: var(--md-surface-2); color: var(--md-text-faint); }

/* la finestra di dialogo non deve mai eccedere lo schermo */
.v-overlay__content > .v-card { border-radius: var(--md-r-lg); }

@media (max-width: 599px) {
  .v-overlay__content { max-width: calc(100vw - 24px) !important; }
}
