/* ==========================================================================
   Comanda · Analytics — Design System
   "il polso del servizio italiano"
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. @font-face — vendored woff2 files
   -------------------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  src: url('fonts/inter-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url('fonts/inter-500.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url('fonts/inter-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url('fonts/inter-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Geist Mono";
  src: url('fonts/geist-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------------------
   2. Design tokens — CSS custom properties
   -------------------------------------------------------------------------- */

/* Light theme (default :root) */
:root {
  /* Accents — unchanged across themes */
  --spritz: #F25C2A;
  --spritz-press: #D8481B;
  --basil: #2E9E7B;

  /* Light palette */
  --bg: #FBF7F2;
  --surface: #FFFFFF;
  --surface-2: #F5EEE6;
  --border: #ECE3D9;
  --ink: #2A201A;
  --muted: #7A6E63;

  /* Shadow — light: soft warm drop */
  --shadow: 0 1px 3px rgba(42, 32, 26, 0.07), 0 4px 12px rgba(42, 32, 26, 0.06);
  --shadow-sm: 0 1px 2px rgba(42, 32, 26, 0.06);

  /* Radii */
  --r-card: 14px;
  --r-ctl: 10px;
  --r-pill: 999px;

  /* Typography */
  --font-display: "Inter", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, monospace;

  /* Spacing scale (4-base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-12: 48px;

  /* Type scale */
  --text-xs: 0.6875rem;   /* 11px */
  --text-sm: 0.8125rem;   /* 13px */
  --text-base: 0.9375rem; /* 15px */
  --text-md: 1.0625rem;   /* 17px */
  --text-lg: 1.25rem;     /* 20px */
  --text-xl: 1.5rem;      /* 24px */

  /* Transition */
  --transition-theme: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

/* Dark theme override */
[data-theme="dark"] {
  --bg: #161311;
  --surface: #211C19;
  --surface-2: #2A2420;
  --border: #352D27;
  --ink: #F2EBE3;
  --muted: #A99E93;

  /* Shadow — dark: subtle depth from darkness itself */
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* --------------------------------------------------------------------------
   3. Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: var(--transition-theme);
  min-height: 100dvh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-body);
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }

a {
  color: var(--spritz);
  text-decoration: none;
}
a:hover { color: var(--spritz-press); }

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

/* Focus — accessible, spritz-ring */
:focus-visible {
  outline: 2px solid var(--spritz);
  outline-offset: 3px;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   4. Layout shell
   -------------------------------------------------------------------------- */

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-main {
  flex: 1;
  padding: var(--sp-6) var(--sp-6) var(--sp-12);
  max-width: 1440px;
  margin-inline: auto;
  width: 100%;
}

/* --------------------------------------------------------------------------
   5. Topbar
   -------------------------------------------------------------------------- */

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  height: 56px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: var(--transition-theme);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-topbar__left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.app-topbar__right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

/* Brand / wordmark */
.brand {
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  transition: color 150ms ease;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0;
}

/* The "·" separator in spritz color — the signature punctuation */
.brand__dot {
  color: var(--spritz);
  margin-inline: 0.18em;
  font-size: 1.1em;
  line-height: 1;
}

.brand__sub {
  font-weight: 500;
  color: var(--muted);
  font-size: var(--text-sm);
  margin-left: var(--sp-1);
  letter-spacing: 0.02em;
}

/* Theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background-color: var(--surface-2);
  color: var(--ink);
  border-color: var(--spritz);
}

/* --------------------------------------------------------------------------
   6. Filters bar + pills
   -------------------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4) 0;
}

.filters__label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex-shrink: 0;
}

/* Pill — filter toggle */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
  user-select: none;
}

.pill:hover {
  border-color: var(--spritz);
  color: var(--ink);
}

.pill.is-active,
.pill[aria-pressed="true"] {
  background-color: var(--spritz);
  border-color: var(--spritz);
  color: #fff;
}

.pill.is-active:hover,
.pill[aria-pressed="true"]:hover {
  background-color: var(--spritz-press);
  border-color: var(--spritz-press);
}

/* Form controls — input + select */
.input,
.select {
  height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  appearance: none;
  -webkit-appearance: none;
}

.input:hover,
.select:hover {
  border-color: var(--muted);
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--spritz);
  box-shadow: 0 0 0 3px rgba(242, 92, 42, 0.15);
}

.select {
  padding-right: var(--sp-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23A99E93' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   7. KPI grid + KPI cards — the signature
   -------------------------------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.kpi {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  transition: var(--transition-theme), box-shadow 150ms ease;
  position: relative;
  overflow: hidden;
}

/* Warm accent stripe — the espresso crema line */
.kpi::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--spritz) 0%, transparent 100%);
  opacity: 0.6;
  border-radius: var(--r-card) var(--r-card) 0 0;
}

.kpi:hover {
  box-shadow: var(--shadow);
}

/* The KPI number — clean, confident Inter */
.kpi-number {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3vw, 2.5rem);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Label — restrained, uppercase Hanken */
.kpi-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.3;
}

/* Delta — positive or negative trend */
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  margin-top: var(--sp-1);
}

.kpi-delta--up {
  color: var(--basil);
}

.kpi-delta--down {
  color: var(--spritz);
}

/* --------------------------------------------------------------------------
   8. Panel — chart/section card
   -------------------------------------------------------------------------- */

.panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
  transition: var(--transition-theme);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.panel-title {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-body {
  flex: 1;
  min-height: 0;
}

/* --------------------------------------------------------------------------
   9. Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  height: 38px;
  border-radius: var(--r-ctl);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  border: 1px solid transparent;
  user-select: none;
  text-decoration: none;
  line-height: 1;
}

/* Primary — spritz */
.btn {
  background-color: var(--spritz);
  color: #fff;
  border-color: var(--spritz);
}

.btn:hover {
  background-color: var(--spritz-press);
  border-color: var(--spritz-press);
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
}

/* Ghost — outline */
.btn-ghost {
  background-color: transparent;
  color: var(--ink);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--spritz);
  color: var(--spritz);
  background-color: transparent;
}

/* Small modifier */
.btn--sm {
  height: 30px;
  padding: 0 var(--sp-3);
  font-size: var(--text-xs);
}

/* --------------------------------------------------------------------------
   10. Table — admin / data
   -------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-card);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table thead tr {
  background-color: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.table td {
  padding: var(--sp-3) var(--sp-4);
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* Zebra striping via surface-2 */
.table tbody tr:nth-child(even) {
  background-color: var(--surface-2);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background-color: var(--surface-2);
}

/* Mono numbers in tables */
.table td.num,
.table .td-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-align: right;
  letter-spacing: 0.03em;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   11. Chat components
   -------------------------------------------------------------------------- */

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
  transition: var(--transition-theme);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  scroll-behavior: smooth;
}

/* Scrollbar — subtle */
.chat-log::-webkit-scrollbar { width: 4px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Message bubbles */
.bubble {
  max-width: 82%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-card);
  font-size: var(--text-sm);
  line-height: 1.55;
  word-break: break-word;
}

.bubble.user {
  align-self: flex-end;
  background-color: var(--spritz);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.bot {
  align-self: flex-start;
  background-color: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Chat key answer — the headline in display sans */
.chat-key {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: var(--sp-2);
  letter-spacing: -0.02em;
}

/* The supporting explanation text after the key answer */
.chat-key-body {
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 1.6;
}

/* Typing loader — three warm dots */
.typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: var(--sp-3) var(--sp-4);
  background-color: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  border-bottom-left-radius: 4px;
}

.typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--spritz);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing__dot:nth-child(2) { animation-delay: 0.2s; }
.typing__dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Chat input row */
.chat-input-row {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
  background-color: var(--surface);
  transition: var(--transition-theme);
}

.chat-input {
  flex: 1;
  height: 40px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background-color: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  resize: none;
}

.chat-input:focus {
  outline: none;
  border-color: var(--spritz);
  box-shadow: 0 0 0 3px rgba(242, 92, 42, 0.12);
}

.chat-input::placeholder { color: var(--muted); }

/* Suggestion chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: 0 var(--sp-6) var(--sp-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background-color: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
  user-select: none;
}

.chip:hover {
  background-color: var(--spritz);
  border-color: var(--spritz);
  color: #fff;
}

/* --------------------------------------------------------------------------
   12. Auth card
   -------------------------------------------------------------------------- */

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  padding: var(--sp-6);
  transition: var(--transition-theme);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-8);
  box-shadow: var(--shadow);
}

.auth-card__brand {
  text-align: center;
  margin-bottom: var(--sp-8);
}

.auth-card__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--ink);
  margin-bottom: var(--sp-1);
}

.auth-card__sub {
  font-size: var(--text-sm);
  color: var(--muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-4);
}

.form-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.form-input {
  width: 100%;
  height: 42px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-ctl);
  border: 1px solid var(--border);
  background-color: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.form-input:hover { border-color: var(--muted); }

.form-input:focus {
  outline: none;
  border-color: var(--spritz);
  box-shadow: 0 0 0 3px rgba(242, 92, 42, 0.12);
}

.form-input::placeholder { color: var(--muted); }

.form-error {
  font-size: var(--text-xs);
  color: var(--spritz);
  margin-top: var(--sp-1);
}

/* --------------------------------------------------------------------------
   13. Utilities
   -------------------------------------------------------------------------- */

.text-muted { color: var(--muted); }
.text-spritz { color: var(--spritz); }
.text-basil { color: var(--basil); }
.text-mono { font-family: var(--font-mono); }
.text-display { font-family: var(--font-display); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Divider */
.divider {
  height: 1px;
  background-color: var(--border);
  border: none;
  margin: var(--sp-6) 0;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.badge--spritz {
  background-color: rgba(242, 92, 42, 0.12);
  color: var(--spritz);
}

.badge--basil {
  background-color: rgba(46, 158, 123, 0.12);
  color: var(--basil);
}

.badge--muted {
  background-color: var(--surface-2);
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   14. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .app-topbar {
    padding: 0 var(--sp-4);
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    padding-block: var(--sp-3);
  }

  .app-main {
    padding: var(--sp-4) var(--sp-4) var(--sp-8);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-3);
  }

  .kpi {
    padding: var(--sp-4);
  }

  .kpi-number {
    font-size: clamp(1.7rem, 7vw, 2rem);
  }

  .panel {
    padding: var(--sp-4);
  }

  .filters {
    gap: var(--sp-1);
  }

  .chat-log {
    padding: var(--sp-4);
  }

  .bubble {
    max-width: 92%;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  /* On phones the topbar wraps; keep action buttons (Admin, Esci) visible
     and drop the less-critical email text to save space. */
  .app-topbar__right {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .app-topbar__right > .text-muted {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   15. Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .typing__dot {
    animation: none;
    opacity: 0.5;
  }
}
