/* ============ OrderOne Dashboard ============ */
:root {
  --ink: #101915;
  --ink-soft: #45524b;
  --ink-faint: #6d7a72;
  --bg: #f4f3ee;
  --surface: #ffffff;
  --line: #e6e4dc;
  --green: #0e5f45;
  --green-deep: #0a4634;
  --green-soft: #e3f0ea;
  --lime: #cdf05f;
  --amber: #b45309;
  --amber-soft: #fdf1e0;
  --red: #b3261e;
  --red-soft: #fdecea;
  --indigo: #4338ca;
  --indigo-soft: #eef2ff;
  --dark: #0c1210;
  --dark-2: #121b17;
  --on-dark: #f2f4f0;
  --on-dark-soft: #a8b5ad;

  --font-display: "Sora", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;

  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(16, 25, 21, 0.05), 0 2px 8px rgba(16, 25, 21, 0.05);
  --shadow-md: 0 2px 6px rgba(16, 25, 21, 0.06), 0 12px 32px rgba(16, 25, 21, 0.1);
  --shadow-lg: 0 4px 12px rgba(16, 25, 21, 0.1), 0 24px 64px rgba(16, 25, 21, 0.18);

  --sidebar-w: 248px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.02em; }
svg { display: block; }

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

/* ============ Sidebar (desktop) ============ */
.sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--dark);
  color: var(--on-dark);
  padding: 22px 16px;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100dvh;
}
.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.12rem;
  padding: 4px 8px;
}
.sidebar__nav { display: grid; gap: 4px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--on-dark-soft);
  font-weight: 500;
  font-size: 0.93rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.side-link svg { width: 19px; height: 19px; flex-shrink: 0; }
.side-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--on-dark); }
.side-link.is-active { background: rgba(205, 240, 95, 0.12); color: var(--lime); }
.side-badge {
  margin-left: auto;
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 999px;
  padding: 1px 8px;
}
.side-badge--red { background: var(--red-soft); color: var(--red); }
.sidebar__foot { margin-top: auto; display: grid; gap: 14px; }
.autopilot-tile {
  background: var(--dark-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 14px;
}
.autopilot-tile__row { display: flex; align-items: center; justify-content: space-between; }
.autopilot-tile__label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--lime);
}
.autopilot-tile__label svg { width: 16px; height: 16px; }
.autopilot-tile p { font-size: 0.78rem; color: var(--on-dark-soft); margin-top: 8px; }
.switch {
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.switch i {
  position: absolute;
  top: 2.5px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.switch.is-on { background: var(--green); }
.switch.is-on i { transform: translateX(16px); }
.autopilot-tile__link {
  margin-top: 10px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--lime);
  padding: 0;
}
.autopilot-tile__link:hover { text-decoration: underline; }
.user { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.user__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2b6f5b, #0e5f45);
  color: #eaf6f0;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user strong { display: block; font-size: 0.86rem; font-weight: 600; }
.user small { color: var(--on-dark-soft); font-size: 0.75rem; }
.dict-tile {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--dark-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.dict-tile svg { width: 18px; height: 18px; color: var(--lime); flex-shrink: 0; }
.dict-tile strong { display: block; font-size: 0.88rem; }
.dict-tile small { color: var(--on-dark-soft); font-size: 0.72rem; }
.dict-tile em { font-style: normal; color: var(--lime); font-weight: 600; }

/* ============ Main ============ */
.main {
  flex: 1;
  min-width: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 1180px;
  margin-inline: auto;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar__title { display: flex; align-items: center; gap: 12px; }
.topbar__logo { display: grid; place-items: center; }
.topbar h1 { font-size: 1.35rem; font-weight: 700; }
.topbar__date { font-size: 0.8rem; color: var(--ink-faint); }
.topbar__actions { display: flex; align-items: center; gap: 10px; }
.search {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  width: 250px;
  color: var(--ink-faint);
}
.search svg { width: 16px; height: 16px; flex-shrink: 0; }
.search input {
  border: none;
  outline: none;
  font: inherit;
  width: 100%;
  background: transparent;
  color: var(--ink);
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  position: relative;
  color: var(--ink-soft);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { border-color: var(--ink-faint); }
.ping {
  position: absolute;
  top: 9px;
  right: 10px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  border: 1.5px solid var(--surface);
}

/* KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.kpi__label { font-size: 0.75rem; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi__value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 800;
  margin-top: 4px;
  line-height: 1.1;
}
.kpi__delta { font-size: 0.75rem; color: var(--ink-faint); display: block; margin-top: 4px; }
.kpi__delta.up { color: var(--green); font-weight: 600; }
.kpi--attention { border-color: #f3d9b7; background: #fffcf7; }
.kpi--attention .kpi__value { color: var(--amber); }
.kpi--chart { grid-column: 1 / -1; }
.chan-bars {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  height: 62px;
  margin-top: 8px;
  padding-inline: 4px;
}
.chan-bar {
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  row-gap: 3px;
  height: 100%;
  flex: 1;
  max-width: 72px;
}
.chan-bar i {
  grid-row: 1;
  align-self: end;
  width: 100%;
  height: var(--v);
  min-height: 6px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, #2f8a6b, var(--green));
}
.chan-bar span { font-size: 0.8rem; line-height: 1; }
.chan-bar small { font-size: 0.68rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ============ Radar dei silenzi ============ */
.silences {
  background: var(--surface);
  border: 1px solid #f3d9b7;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.silences__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.silences__head h2 { display: flex; align-items: center; gap: 8px; font-size: 0.98rem; font-weight: 700; }
.silences__head h2 svg { width: 17px; height: 17px; color: var(--amber); }
.silences__head h2 em {
  font-style: normal;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--amber-soft);
  color: var(--amber);
  border-radius: 999px;
  padding: 1px 8px;
}
.silences__head p { font-size: 0.8rem; color: var(--ink-faint); }
.silences__row { display: grid; gap: 10px; }
.sil-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fffdfa;
  display: grid;
  gap: 8px;
  align-content: start;
}
.sil-card__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.sil-card__top strong { font-size: 0.9rem; }
.sil-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-soft);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.sil-card p { font-size: 0.78rem; color: var(--ink-soft); }
.sil-card__actions { display: flex; flex-wrap: wrap; gap: 6px; }
.sil-card.is-done { background: var(--green-soft); border-color: #cfe5da; }
.sil-card__done { color: var(--green); font-weight: 600; }
.silences__empty { font-size: 0.85rem; color: var(--ink-faint); grid-column: 1 / -1; }

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.chip:hover { border-color: var(--green); color: var(--green); }
.chip--primary { background: var(--green); border-color: var(--green); color: #fff; }
.chip--primary:hover { background: var(--green-deep); border-color: var(--green-deep); color: #fff; }
.chip--quiet { border-color: transparent; background: transparent; color: var(--ink-faint); }

/* Toolbar / tabs */
.toolbar { margin-bottom: 12px; }
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--ink-soft);
  min-height: 38px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.tab em { font-style: normal; font-size: 0.74rem; font-weight: 700; color: var(--ink-faint); }
.tab.is-active { background: var(--dark); border-color: var(--dark); color: #fff; }
.tab.is-active em { color: var(--lime); }
.tab--error em { color: var(--red); }
.tab--error.is-active { background: var(--red); border-color: var(--red); }
.tab--error.is-active em { color: #fff; }

/* ============ Orders list ============ */
.orders { display: grid; gap: 8px; }
.order {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  grid-template-areas: "src head badge" "src sub badge";
  column-gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.order:hover { border-color: #c9d6cf; box-shadow: var(--shadow-md); }
.order:active { transform: scale(0.995); }
.order.is-focused { border-color: var(--green); box-shadow: 0 0 0 3px rgba(14, 95, 69, 0.14), var(--shadow-md); }
.order__src {
  grid-area: src;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 1.05rem;
}
.order__head { grid-area: head; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.order__client { font-weight: 600; font-size: 0.94rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order__id { font-size: 0.76rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.order__sub {
  grid-area: sub;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-faint);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.order__badge { grid-area: badge; justify-self: end; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--exported { background: var(--green-soft); color: var(--green); }
.badge--auto { background: var(--indigo-soft); color: var(--indigo); }
.badge--review { background: var(--amber-soft); color: var(--amber); }
.badge--error { background: var(--red-soft); color: var(--red); }

.orders__empty { text-align: center; color: var(--ink-faint); padding: 40px 0; }

/* ============ Drawer ============ */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 16, 0.45);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.drawer-backdrop.is-open { opacity: 1; }
.drawer {
  position: fixed;
  z-index: 100;
  inset: auto 0 0 0;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0.24, 1);
}
.drawer.is-open { transform: translateY(0); }
.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer__head h2 { font-size: 1.08rem; font-weight: 700; }
.drawer__meta { font-size: 0.8rem; color: var(--ink-faint); margin-top: 2px; }
.drawer__body { overflow-y: auto; padding: 16px 18px; flex: 1; }

.compare { display: grid; gap: 18px; }
.compare__col h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.compare__col h3 svg { width: 15px; height: 15px; }

.original {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 0.9rem;
  display: grid;
  gap: 10px;
}
.original__meta { font-size: 0.75rem; color: var(--ink-faint); }
.original__bubble {
  background: #e9f8e6;
  border-radius: 4px 14px 14px 14px;
  padding: 10px 12px;
  line-height: 1.5;
}
.original__voice {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3f7d38;
  font-size: 0.8rem;
  background: #e9f8e6;
  border-radius: 14px;
  padding: 8px 12px;
  width: fit-content;
}
.original__voice svg { width: 14px; height: 14px; }
.voice-bars { display: flex; align-items: center; gap: 2px; }
.voice-bars i { width: 2.5px; height: 8px; border-radius: 2px; background: currentColor; opacity: 0.75; }
.voice-bars i:nth-child(2n) { height: 13px; }
.voice-bars i:nth-child(3n) { height: 16px; }
.original__doc {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
}

.parsed { list-style: none; display: grid; gap: 6px; }
.parsed li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.86rem;
  background: var(--surface);
}
.parsed li.is-warn { background: #fffcf5; border-color: #f3d9b7; }
.parsed li.is-redo { background: #fdf6f5; border-color: #ecc8c5; }
.parsed li.is-removed { opacity: 0.62; }
.parsed li.is-removed .p-name strong { text-decoration: line-through; }
.parsed .p-name { min-width: 0; }
.parsed .p-name strong { display: block; font-weight: 600; font-size: 0.86rem; }
.parsed .p-name small { color: var(--ink-faint); font-size: 0.72rem; }
.parsed .p-qty { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-weight: 500; }
.parsed .p-options { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.conf {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.conf--ok { background: var(--green-soft); color: var(--green); }
.conf--warn, .conf--check { background: var(--amber-soft); color: var(--amber); }
.conf--redo { background: var(--red-soft); color: var(--red); }
.conf--fixed { background: var(--green-soft); color: var(--green); box-shadow: inset 0 0 0 1px rgba(14, 95, 69, 0.28); }
.conf--removed { background: #eeedea; color: var(--ink-faint); }

.drawer__foot {
  border-top: 1px solid var(--line);
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
}
.drawer__erp {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--ink-faint);
}
.drawer__erp .status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot--ok { background: #2e9e6b; }
.status-dot--wait { background: var(--amber); }
.status-dot--err { background: var(--red); }
.drawer__btns { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 12px 18px;
  border-radius: 999px;
  min-height: 46px;
  transition: transform 0.12s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn--ghost { border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ink-faint); }
.btn--approve { background: var(--green); color: #fff; box-shadow: 0 2px 10px rgba(14, 95, 69, 0.3); }
.btn--approve:hover { background: var(--green-deep); }
.btn--approve:disabled { opacity: 0.6; cursor: default; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--dark);
  color: var(--on-dark);
  font-size: 0.88rem;
  font-weight: 500;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 120;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast { display: flex; align-items: center; justify-content: center; gap: 14px; }
.toast.has-undo { pointer-events: auto; }
.toast__undo { color: var(--lime); font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.toast__undo:hover { text-decoration: underline; }

/* ============ Tastiera ============ */
kbd {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--ink-soft);
}
.kbd-hint { display: none; text-align: center; font-size: 0.78rem; color: var(--ink-faint); margin-top: 16px; }
.kbd-hint kbd { margin-inline: 1px; }
.btn-kbd { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.35); color: #fff; margin-left: 2px; display: none; }

.kbd-help {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(12, 18, 16, 0.5);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.kbd-help[hidden] { display: none; }
.kbd-help__card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
}
.kbd-help__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kbd-help__head h2 { font-size: 1.02rem; }
.kbd-help dl { display: grid; gap: 9px; }
.kbd-help dl > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kbd-help dt { display: flex; align-items: center; gap: 4px; font-size: 0.8rem; color: var(--ink-soft); }
.kbd-help dd { color: var(--ink-soft); font-size: 0.86rem; text-align: right; }
.kbd-help__note { font-size: 0.78rem; color: var(--ink-faint); border-top: 1px solid var(--line); padding-top: 12px; }

/* ============ Pagine ============ */
.page { display: none; }
.page.is-active { display: block; animation: pageIn 0.25s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-lede {
  font-size: 0.92rem;
  color: var(--ink-soft);
  max-width: 640px;
  margin-bottom: 18px;
}

.pagebar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 16px;
  padding-bottom: 2px;
}
.pagebar::-webkit-scrollbar { display: none; }
.pagebar__btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
  min-height: 38px;
}
.pagebar__btn em {
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--red-soft);
  color: var(--red);
  border-radius: 999px;
  padding: 1px 7px;
}
.pagebar__btn.is-active { background: var(--dark); border-color: var(--dark); color: #fff; }

/* ============ Player audio ============ */
.player {
  background: #e9f8e6;
  border-radius: 4px 14px 14px 14px;
  padding: 10px 12px;
  display: grid;
  gap: 7px;
}
.player__label { font-size: 0.72rem; font-weight: 600; color: #3f7d38; }
.player__row { display: flex; align-items: center; gap: 10px; }
.player__btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.player__btn:hover { background: var(--green-deep); }
.player__btn:active { transform: scale(0.94); }
.player__btn svg { width: 16px; height: 16px; }
.player .pl-pause { display: none; }
.player.is-playing .pl-pause { display: block; }
.player.is-playing .pl-play { display: none; }
.player__wave {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  cursor: pointer;
  min-width: 0;
}
.player__wave i {
  flex: 1;
  height: var(--h);
  min-width: 2px;
  border-radius: 2px;
  background: #a7cfa0;
  transition: background 0.1s linear;
}
.player__wave i.is-played { background: var(--green); }
.player__time {
  font-size: 0.72rem;
  font-weight: 600;
  color: #3f7d38;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.player__rate {
  font-size: 0.7rem;
  font-weight: 700;
  color: #3f7d38;
  border: 1px solid #a7cfa0;
  border-radius: 999px;
  padding: 2px 8px;
  min-width: 40px;
  flex-shrink: 0;
}
.player__rate:hover { border-color: var(--green); color: var(--green); }

.drawer__client-link {
  font-weight: 600;
  color: var(--green);
  padding: 0;
  font-size: inherit;
}
.drawer__client-link:hover { text-decoration: underline; }

/* ============ Pagina Clienti / Autopilot ============ */
.ap-rule {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  background: var(--dark);
  color: var(--on-dark);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 18px;
}
.ap-rule__icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(205, 240, 95, 0.14);
  color: var(--lime);
  display: grid;
  place-items: center;
}
.ap-rule__icon svg { width: 20px; height: 20px; }
.ap-rule h2 { font-size: 1.02rem; margin-bottom: 4px; }
.ap-rule p { font-size: 0.84rem; color: var(--on-dark-soft); max-width: 560px; }
.ap-rule p strong { color: var(--on-dark); }
.ap-rule__stat {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 12px;
}
.ap-rule__stat strong { font-family: var(--font-display); font-size: 1.4rem; color: var(--lime); }
.ap-rule__stat span { font-size: 0.84rem; font-weight: 600; }
.ap-rule__stat em { font-style: normal; font-size: 0.78rem; color: var(--on-dark-soft); margin-left: auto; text-align: right; }

.client-list { display: grid; gap: 8px; }
.client-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  text-align: left;
  width: 100%;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.client-row:hover { border-color: #c9d6cf; box-shadow: var(--shadow-md); }
.client-row.is-learning { background: #fffdf9; }
.client-row.is-paused { opacity: 0.75; }

.cr-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2b6f5b, #0e5f45);
  color: #eaf6f0;
  display: grid;
  place-items: center;
  font-size: 0.76rem;
  font-weight: 700;
  flex-shrink: 0;
}
.cr-main { min-width: 0; display: grid; gap: 3px; }
.cr-name { font-weight: 600; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; min-width: 0; }
.cr-name__text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cr-chans { flex-shrink: 0; display: inline-flex; gap: 3px; font-size: 0.8rem; }
.cr-sub {
  font-size: 0.78rem;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cr-sub strong { color: var(--ink-soft); font-weight: 700; }
.cr-sub .is-over strong { color: var(--amber); }

.cr-ap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}
.cr-ap small { font-size: 0.73rem; font-weight: 600; color: var(--ink-faint); white-space: nowrap; }
.cr-ap--learning small { color: var(--amber); }
.cr-ap--paused { font-size: 0.78rem; font-weight: 600; color: var(--ink-faint); }
.cr-dots { display: flex; gap: 2px; }
.cr-dots i { width: 12px; height: 5px; border-radius: 3px; background: #efe3cd; }
.cr-dots i.is-done { background: var(--amber); }
.switch--sm { width: 34px; height: 20px; }
.switch--sm i { width: 15px; height: 15px; top: 2px; left: 2.5px; }
.switch--sm.is-on i { transform: translateX(14px); }

/* .ap-state: usato nel drawer di dettaglio cliente (versione estesa di .cr-ap) */
.ap-state {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.ap-state small { flex-basis: 100%; font-weight: 500; font-size: 0.73rem; color: var(--ink-faint); }
.ap-state .switch { background: #d8d6cd; }
.ap-state .switch.is-on { background: var(--green); }
.ap-state--learning { color: var(--amber); }
.ap-state--paused { color: var(--ink-faint); }
.ap-progress { display: flex; gap: 3px; }
.ap-progress i {
  width: 18px;
  height: 6px;
  border-radius: 3px;
  background: #efe3cd;
}
.ap-progress i.is-done { background: var(--amber); }

/* Scheda cliente */
.drawer--client { z-index: 105; }
.cd-section { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 16px; }
.cd-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.cd-section h3 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin-bottom: 10px;
}
.cd-ap .ap-state { border-top: none; padding-top: 0; }
.cd-note { font-size: 0.82rem; color: var(--ink-soft); margin-top: 8px; }
.cd-solito-meta { font-size: 0.78rem; color: var(--ink-faint); margin-bottom: 8px; }
.cd-list { list-style: none; display: grid; gap: 5px; }
.cd-list li {
  font-size: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}
.cd-event {
  margin-top: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-soft);
  border-radius: 8px;
  padding: 8px 10px;
}
.cd-dict { list-style: none; display: grid; gap: 5px; }
.cd-dict li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.82rem;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}
.cd-dict li:last-child { border-bottom: none; }
.cd-dict li span:first-child { font-weight: 600; }
.cd-dict li em { color: var(--ink-faint); flex-shrink: 0; }
.cd-dict li span:last-child { color: var(--ink-soft); }
.cd-orders { display: grid; gap: 6px; }
.cd-order {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.83rem;
  text-align: left;
  background: var(--surface);
}
.cd-order:hover { border-color: var(--green); }

.spark {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 72px;
  position: relative;
  padding-top: 4px;
}
.spark::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: var(--thr);
  border-top: 1.5px dashed var(--amber);
  opacity: 0.55;
}
.spark i {
  flex: 1;
  height: var(--h);
  min-height: 2px;
  border-radius: 4px 4px 2px 2px;
  background: var(--green);
  opacity: 0.85;
}
.spark i.is-over { background: var(--amber); }
.spark__legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--ink-faint);
  margin-top: 5px;
}

/* ============ Eccezioni ============ */
.exc-list { display: grid; gap: 10px; }
.exc {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}
.exc__icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}
.exc--erp { border-color: #ecc8c5; }
.exc--erp .exc__icon { background: var(--red-soft); }
.exc--anomaly { border-color: #f3d9b7; }
.exc--anomaly .exc__icon { background: var(--amber-soft); }
.exc--revision .exc__icon { background: var(--indigo-soft); }
.exc__main { display: grid; gap: 6px; min-width: 0; }
.exc__top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.exc__top strong { font-size: 0.92rem; }
.exc__kind {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  white-space: nowrap;
}
.exc__meta { font-size: 0.76rem; color: var(--ink-faint); }
.exc__main > p { font-size: 0.85rem; color: var(--ink-soft); }
.exc__actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.exc.is-done { opacity: 0.82; background: var(--green-soft); border-color: #cfe5da; }
.exc.is-done .exc__icon { background: var(--green); color: #fff; font-weight: 700; }
.exc.is-done p { color: var(--green); font-weight: 600; font-size: 0.83rem; }

/* ============ Panel (Analytics / ERP) ============ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.panel__head { margin-bottom: 14px; }
.panel__head h2 { font-size: 0.98rem; font-weight: 700; }
.panel__head p { font-size: 0.78rem; color: var(--ink-faint); margin-top: 2px; }
.panel__note { font-size: 0.76rem; color: var(--ink-faint); margin-top: 12px; }

.kpis--analytics { margin-bottom: 14px; }
.kpi--zero .kpi__value { color: var(--green); }

.weekbars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 150px;
}
.weekbar {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  row-gap: 4px;
  height: 100%;
  min-width: 0;
}
.weekbar i {
  align-self: end;
  width: 100%;
  max-width: 54px;
  height: var(--v);
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #cfe5da, #9cc5b3);
}
.weekbar strong { font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.weekbar small { font-size: 0.64rem; color: var(--ink-faint); white-space: nowrap; }
.weekbar.is-now i { background: linear-gradient(180deg, #2f8a6b, var(--green)); }
.weekbar.is-now strong { color: var(--green); }

.ovr-list { display: grid; gap: 9px; }
.ovr {
  display: grid;
  grid-template-columns: minmax(110px, 170px) 1fr 52px;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
}
.ovr > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); }
.ovr > strong { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.ovr__bar { position: relative; height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.ovr__bar i { position: absolute; inset: 0 auto 0 0; width: var(--v); background: var(--green); border-radius: 999px; }
.ovr__bar i.is-amber { background: var(--amber); }
.ovr__bar i.is-red { background: var(--red); }
.ovr__thr { position: absolute; top: -2px; bottom: -2px; left: 40%; border-left: 1.5px dashed var(--amber); opacity: 0.6; }

/* ============ ERP ============ */
.erp-conns { display: grid; gap: 10px; }
.erp-conn {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.erp-conn > div { flex: 1; min-width: 0; }
.erp-conn strong { display: block; font-size: 0.9rem; }
.erp-conn small { color: var(--ink-faint); font-size: 0.76rem; }
.erp-conn .status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.sync-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.sync-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 2px;
}
.sync-item strong { font-family: var(--font-display); font-size: 1.3rem; }
.sync-item span { font-size: 0.78rem; color: var(--ink-soft); font-weight: 600; }
.sync-item small { font-size: 0.72rem; color: var(--ink-faint); }

.trail { list-style: none; display: grid; gap: 0; }
.trail li {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  position: relative;
  padding: 0 0 16px 0;
}
.trail li::before {
  content: "";
  position: absolute;
  left: 84px;
  top: 8px;
  bottom: -2px;
  border-left: 2px solid var(--line);
}
.trail li:last-child::before { display: none; }
.trail li > div {
  position: relative;
  padding-left: 26px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.trail li > div::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1.5px var(--green);
}
.trail li.is-wait > div::before { background: var(--surface); box-shadow: 0 0 0 1.5px var(--amber); }
.trail li strong { color: var(--ink); }
.trail__t { font-size: 0.74rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; text-align: right; padding-top: 3px; }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-backdrop, .toast, .switch i, .page.is-active { transition: none; animation: none; }
}

/* ============ Tablet ≥ 700px ============ */
@media (min-width: 700px) {
  .main { padding: 22px 28px 40px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi--chart { grid-column: auto; grid-row: 1; grid-column: 4; display: none; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .search { display: flex; }
  .compare { grid-template-columns: 1fr 1fr; align-items: start; }
  .drawer__foot { grid-template-columns: 1fr auto; align-items: center; }
  .drawer__btns { grid-template-columns: auto auto; }
  .silences__row { grid-template-columns: repeat(3, 1fr); }
  .btn-kbd { display: inline-block; }
  .sync-grid { grid-template-columns: repeat(4, 1fr); }
  .kpis--analytics { grid-template-columns: repeat(4, 1fr); }
}

/* ============ Desktop ≥ 1080px ============ */
@media (min-width: 1080px) {
  .sidebar { display: flex; }
  .topbar__logo { display: none; }
  .main { padding: 26px 36px 48px; }
  .kpis { grid-template-columns: repeat(5, 1fr); gap: 12px; }
  .kpi--chart { display: block; grid-column: 5; }
  .topbar h1 { font-size: 1.5rem; }

  .drawer {
    inset: 0 0 0 auto;
    width: min(760px, 92vw);
    max-height: none;
    border-radius: 0;
    transform: translateX(105%);
  }
  .drawer.is-open { transform: translateX(0); }
  .drawer--client { width: min(560px, 92vw); }
  .kbd-hint { display: block; }
  .pagebar { display: none; }
}
