/* ============================================================
   Kawaii Gestione — CSS
   Porta fedele di static/gestione.css (Flask) per Cloudflare Pages.
   Palette terracotta/kawaii, Playfair Display + Nunito,
   sidebar desktop + drawer/hamburger su mobile.
   ============================================================ */

:root {
  --color-primary:    #c97d4e;
  --color-primary-dk: #a85e30;
  --color-bg:         #faf6f1;
  --color-surface:    #ffffff;
  --color-dark:       #3a2e28;
  --color-muted:      #8a7a70;
  --color-border:     #e8ddd4;
  --color-success:    #5a9e6e;
  --color-danger:     #c0392b;
  --color-warning:    #e67e22;
  --color-info:       #2980b9;
  --sidebar-w:        220px;
  --radius:           12px;
  --radius-sm:        8px;
  --shadow:           0 2px 12px rgba(58,46,40,.10);
  --shadow-md:        0 4px 24px rgba(58,46,40,.14);
  --font-display:     'Playfair Display', Georgia, serif;
  --font-body:        'Nunito', system-ui, sans-serif;
  --transition:       .2s ease;
}

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

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

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-dark);
  min-height: 100vh;
  display: flex;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo-emoji { font-size: 1.6rem; }

.sidebar-brand {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--color-primary);
  font-weight: 700;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1.25rem;
  font-size: .95rem;
  font-weight: 500;
  color: var(--color-muted);
  border-left: 3px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
  background: none;
  border-top: none; border-right: none; border-bottom: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--color-primary);
  background: rgba(201,125,78,.06);
}

.nav-item.active {
  color: var(--color-primary);
  background: rgba(201,125,78,.10);
  border-left-color: var(--color-primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.sidebar-user {
  font-size: .85rem;
  color: var(--color-muted);
  font-weight: 500;
}

.btn-logout {
  font-size: .85rem;
  color: var(--color-danger);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
  background: none;
  border: none;
  text-align: left;
  padding: 0;
}

.btn-logout:hover { opacity: .7; }

/* ============================================================
   TOPBAR (mobile)
   ============================================================ */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  z-index: 300;
}

.topbar-brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--color-primary);
  font-weight: 700;
}

.hamburger {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: .25rem;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-dark);
  border-radius: 2px;
  transition: all var(--transition);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 150;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 2rem 2.5rem;
  min-height: 100vh;
}

.main-content.full-width {
  margin-left: 0;
  padding: 0;
}

.page-header {
  margin-bottom: 2rem;
}

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

.page-title {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--color-dark);
  font-weight: 700;
}

.page-subtitle {
  color: var(--color-muted);
  margin-top: .25rem;
  font-size: .95rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: 50px;
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dk); }

.btn-success {
  background: var(--color-success);
  color: #fff;
}
.btn-success:hover { opacity: .85; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { opacity: .85; }

.btn-warning {
  background: var(--color-warning);
  color: #fff;
}
.btn-warning:hover { opacity: .85; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--color-border);
  color: var(--color-dark);
}
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }

.btn-sm {
  padding: .35rem .8rem;
  font-size: .82rem;
}

.btn-full { width: 100%; }

.btn:disabled { opacity: .35; cursor: not-allowed; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

/* ============================================================
   STAT / KPI CARDS
   ============================================================ */
.stats-grid, .kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2.5rem;
}

.kpi-grid { grid-template-columns: repeat(3, 1fr); margin-bottom: 1rem; }

.stat-card, .kpi-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  border-left: 4px solid var(--color-primary);
  transition: box-shadow var(--transition);
}
.kpi-card { padding: 1.75rem 1.5rem; }

.stat-card:hover, .kpi-card:hover { box-shadow: var(--shadow-md); }

.stat-card.green  { border-left-color: var(--color-success); }
.stat-card.red    { border-left-color: var(--color-danger); }
.stat-card.orange { border-left-color: var(--color-warning); }

.stat-label, .kpi-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  margin-bottom: .5rem;
}

.stat-value, .kpi-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-dark);
  line-height: 1;
}
.kpi-value { font-size: 2.2rem; }

.stat-sub, .kpi-sub {
  font-size: .8rem;
  color: var(--color-muted);
  margin-top: .4rem;
}

.secondary-stats {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  font-size: .85rem;
  color: var(--color-muted);
  margin-bottom: 2rem;
  padding: .75rem 1.25rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.secondary-stats span strong { color: var(--color-dark); }

/* ============================================================
   CHART SECTION
   ============================================================ */
.chart-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.chart-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin-bottom: 1.25rem;
  color: var(--color-dark);
}

/* ============================================================
   MOVIMENTI (ultime vendite)
   ============================================================ */
.movimenti-list { display: flex; flex-direction: column; }
.movimento-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .88rem;
  padding: .55rem .25rem;
  border-bottom: 1px solid var(--color-border);
}
.movimento-row:last-child { border-bottom: none; }
.mov-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: .72rem;
  font-weight: 700;
  flex-shrink: 0;
  background: rgba(90,158,110,.15);
  color: var(--color-success);
}
.mov-nome    { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov-details { font-size: .78rem; color: var(--color-muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mov-time    { font-size: .78rem; color: var(--color-muted); white-space: nowrap; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  margin-bottom: 1.25rem;
}

label {
  display: block;
  font-size: .88rem;
  font-weight: 600;
  color: var(--color-dark);
  margin-bottom: .4rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: .65rem .9rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--color-dark);
  background: var(--color-bg);
  transition: border-color var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
}

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

.form-hint {
  font-size: .78rem;
  color: var(--color-muted);
  margin-top: .3rem;
}

/* Star / difficulty radio */
.difficulty-group {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.difficulty-group input[type="radio"] { display: none; }

.difficulty-group label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  margin: 0;
  color: var(--color-muted);
}

.difficulty-group input[type="radio"]:checked + label {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.difficulty-group label:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Add form layout */
.add-form-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  align-items: start;
}

/* Price preview card */
.preview-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: sticky;
  top: 1.5rem;
}

.preview-img-wrap {
  height: 180px;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  border-bottom: 1px solid var(--color-border);
}

.preview-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-body {
  padding: 1.25rem;
}

.preview-name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: .5rem;
  min-height: 1.4rem;
  color: var(--color-dark);
}

.preview-price {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .75rem;
}

.preview-breakdown {
  font-size: .78rem;
  color: var(--color-muted);
  line-height: 1.6;
  border-top: 1px solid var(--color-border);
  padding-top: .75rem;
}

.preview-breakdown span {
  display: block;
}

/* File input */
.file-input-wrap {
  position: relative;
}

.file-input-wrap input[type="file"] {
  opacity: 0;
  position: absolute;
  inset: 0;
  cursor: pointer;
}

.file-input-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem .9rem;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  color: var(--color-muted);
  cursor: pointer;
  transition: border-color var(--transition);
  background: var(--color-bg);
}

.file-input-wrap:hover .file-input-label {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.filter-bar {
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
}

.filter-bar input,
.filter-bar select {
  width: auto;
  flex: 1;
  min-width: 140px;
  max-width: 260px;
  padding: .5rem .8rem;
  font-size: .88rem;
}

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

thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-muted);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(201,125,78,.04); }

td {
  padding: .75rem 1rem;
  font-size: .9rem;
  vertical-align: middle;
}

.td-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--color-bg);
}

.td-thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  border: 1px solid var(--color-border);
}

.chip {
  display: inline-block;
  padding: .25rem .7rem;
  border-radius: 50px;
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
}

.chip-green {
  background: rgba(90,158,110,.15);
  color: var(--color-success);
}

.chip-gray {
  background: rgba(138,122,112,.12);
  color: var(--color-muted);
}

.action-group {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-muted);
}

.empty-state p { margin-top: .5rem; font-size: .9rem; }

/* Filtri categoria (prodotti) */
.cat-tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; align-items:center; }
.cat-tab { padding:6px 16px; border-radius:20px; border:1px solid var(--color-border); font-size:13px; text-decoration:none; color:var(--color-muted); background:transparent; transition:all .15s; cursor: pointer; }
.cat-tab:hover { border-color:var(--color-primary); color:var(--color-primary); }
.cat-tab.active { background:var(--color-primary); color:#fff; border-color:var(--color-primary); }
.cat-tab-status.active { background:var(--color-success); border-color:var(--color-success); }
.cat-tab-status:hover { border-color:var(--color-success); color:var(--color-success); }
.filters-wrap { padding:1rem 1.25rem; border-bottom:1px solid var(--color-border); display:flex; flex-direction:column; gap:.6rem; }
.filters-wrap .cat-tabs { margin-bottom:0; }
.filters-wrap .filter-bar { padding:0; border-bottom:none; border-radius:0; background:none; box-shadow:none; }
.search-compact { width:150px; flex:none; padding:.4rem .8rem; font-size:.88rem; border:1px solid var(--color-border); border-radius:var(--radius-sm); background:var(--color-bg); color:inherit; }
.search-compact:focus { outline:none; border-color:var(--color-primary); }

.table-expand-bar { display:none; padding:6px 1.25rem; }
.btn-expand-cols { background:none; border:1px solid var(--color-border); border-radius:20px; padding:4px 12px; font-size:12px; color:var(--color-muted); cursor:pointer; transition:all .15s; }
.btn-expand-cols:hover { border-color:var(--color-primary); color:var(--color-primary); }
.btn-expand-cols.active { background:var(--color-primary); color:#fff; border-color:var(--color-primary); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 1.5rem;
  width: 100%;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.login-logo-text {
  font-size: 3.5rem;
  text-align: center;
  margin-bottom: .5rem;
}

.login-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  text-align: center;
  color: var(--color-dark);
  margin-bottom: 2rem;
  line-height: 1.3;
}

.login-title span {
  color: var(--color-primary);
  font-size: 1rem;
  font-weight: 400;
}

/* ============================================================
   TOAST / FLASH MESSAGES
   ============================================================ */
.flash-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 340px;
}

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  gap: 1rem;
  background: var(--color-surface);
  box-shadow: var(--shadow-md);
  animation: modalIn .18s ease;
}

.flash-error   { color: var(--color-danger); border-left: 3px solid var(--color-danger); }
.flash-success { color: var(--color-success); border-left: 3px solid var(--color-success); }
.flash-info    { color: var(--color-info); border-left: 3px solid var(--color-info); }
.flash-warning { color: var(--color-warning); border-left: 3px solid var(--color-warning); }

.flash-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  opacity: .6;
  flex-shrink: 0;
}

.flash-close:hover { opacity: 1; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(58,46,40,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  animation: modalIn .18s ease;
  max-height: 90vh;
  overflow-y: auto;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-muted);
  line-height: 1;
  padding: .2rem;
  border-radius: 4px;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--color-dark); }

.modal-body {
  padding: 1.25rem 1.5rem;
}

.modal-product-name {
  font-size: .9rem;
  color: var(--color-muted);
  margin-bottom: 1.1rem;
  font-style: italic;
}

.modal-price-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .4rem;
}

.modal-price-row span {
  font-size: 1.2rem;
  color: var(--color-muted);
  font-weight: 600;
}

.modal-price-row input {
  font-size: 1.3rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--color-primary);
  max-width: 160px;
  text-align: right;
}

.modal-hint {
  font-size: .78rem;
  color: var(--color-muted);
  margin-bottom: 1.25rem;
}

.modal-footer {
  display: flex;
  gap: .75rem;
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--color-border);
  justify-content: flex-end;
}

/* ============================================================
   SECTION TITLE
   ============================================================ */
.section-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--color-dark);
  margin: 2rem 0 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--color-border);
}

/* ============================================================
   CATEGORY CARDS (dashboard)
   ============================================================ */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.cat-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--transition);
}

.cat-card:hover { box-shadow: var(--shadow-md); }

.cat-card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1.1rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.cat-icon { font-size: 1.3rem; }

.cat-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-dark);
  flex: 1;
}

.cat-count {
  font-size: .78rem;
  font-weight: 700;
  color: var(--color-muted);
  background: var(--color-border);
  padding: .15rem .55rem;
  border-radius: 50px;
}

.cat-rows {
  padding: .9rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.cat-row-total {
  padding-top: .45rem;
  border-top: 1px solid var(--color-border);
  margin-top: .1rem;
}

.cat-row-label {
  font-size: .82rem;
  color: var(--color-muted);
  cursor: default;
}

.cat-row-value {
  font-size: .9rem;
  font-weight: 700;
  color: var(--color-dark);
}

.cat-row-value.green { color: var(--color-success); }
.cat-row-value.red   { color: var(--color-danger); }

/* ============================================================
   TABS (impostazioni)
   ============================================================ */
.tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0;
  flex-wrap: wrap;
}

.tab-btn {
  padding: .6rem 1.2rem;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: .9rem;
  font-weight: 600;
  color: var(--color-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all var(--transition);
}

.tab-btn:hover { color: var(--color-primary); background: rgba(201,125,78,.06); }

.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: rgba(201,125,78,.07);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   TIMELINE (cronologia)
   ============================================================ */
.timeline {
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: .6rem;
  top: .5rem;
  bottom: .5rem;
  width: 2px;
  background: var(--color-border);
}

.timeline-item {
  position: relative;
  margin-bottom: 1.1rem;
}

.timeline-dot {
  position: absolute;
  left: -1.62rem;
  top: .85rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--color-surface);
  box-shadow: 0 0 0 1px var(--color-border);
}

.timeline-card {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: .85rem 1.1rem;
  transition: box-shadow var(--transition);
}

.timeline-card:hover { box-shadow: var(--shadow-md); }

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .4rem;
  gap: .5rem;
  flex-wrap: wrap;
}

.timeline-badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 50px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.timeline-time {
  font-size: .78rem;
  color: var(--color-muted);
  white-space: nowrap;
}

.timeline-body {
  font-size: .9rem;
  color: var(--color-dark);
  line-height: 1.5;
}

.timeline-details {
  font-size: .78rem;
  color: var(--color-muted);
  margin-top: .3rem;
  font-style: italic;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%;
  background: rgba(20,14,10,.88);
  z-index: 600;
  overflow: hidden;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 1rem;
}

.lightbox-backdrop.open {
  display: flex;
  animation: fadeIn .18s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.lightbox-img {
  max-width: 92vw;
  max-height: 82vh;
  max-height: 82svh;
  max-height: 82dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  display: block;
  flex-shrink: 1;
}

.lightbox-caption {
  color: rgba(255,255,255,.75);
  font-size: .9rem;
  font-family: var(--font-display);
  text-align: center;
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.lightbox-close:hover { background: rgba(255,255,255,.25); }

/* ============================================================
   GALLERIA — griglia foto stile "galleria del telefono" +
   visualizzatore a schermo intero con swipe tra le foto
   ============================================================ */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

@media (min-width: 600px) {
  .gallery-grid { grid-template-columns: repeat(6, 1fr); gap: 4px; }
}
@media (min-width: 900px) {
  .gallery-grid { grid-template-columns: repeat(8, 1fr); }
}

.gallery-item {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 6px;
  background: var(--color-border);
  overflow: hidden;
  cursor: pointer;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(10,8,6,.96);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gallery-viewer.open {
  display: flex;
  animation: fadeIn .18s ease;
}

.gallery-viewer-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.gallery-viewer-img {
  max-width: 94vw;
  max-height: 78vh;
  max-height: 78svh;
  max-height: 78dvh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  user-select: none;
  -webkit-user-drag: none;
  touch-action: pan-y;
  will-change: transform, opacity;
}

.gallery-viewer-close {
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  z-index: 2;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.gallery-viewer-close:hover { background: rgba(255,255,255,.25); }

.gallery-nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.gallery-nav-arrow:hover { background: rgba(255,255,255,.25); }
.gallery-nav-arrow:disabled { opacity: .25; cursor: default; }
.gallery-nav-prev { left: .75rem; }
.gallery-nav-next { right: .75rem; }

.gallery-viewer-info {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 1.25rem 1.5rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0,0,0,.8), transparent);
  text-align: center;
  pointer-events: none;
}

.gallery-viewer-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: .2rem;
}

.gallery-viewer-price {
  font-size: .95rem;
  font-weight: 600;
  color: var(--color-primary-light);
}

.gallery-viewer-status {
  margin-top: .3rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-success);
}
.gallery-viewer-status-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--color-success);
  color: #fff;
  font-size: .62rem;
  margin-right: .15rem;
}

@media (max-width: 768px) {
  .gallery-nav-arrow { width: 34px; height: 34px; font-size: 1rem; }
  .gallery-nav-prev { left: .4rem; }
  .gallery-nav-next { right: .4rem; }
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .topbar {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 5rem 1rem 1.5rem;
  }

  .add-form-grid {
    grid-template-columns: 1fr;
  }

  .preview-card {
    position: static;
  }

  .stats-grid, .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar input,
  .filter-bar select {
    max-width: none;
  }

  table { font-size: .82rem; }
  td, th { padding: .5rem .4rem; }

  .table-expand-bar { display: block; }
  .table-wrap.cols-expanded .table-prodotti th,
  .table-wrap.cols-expanded .table-prodotti td { display: table-cell !important; }

  .td-thumb, .td-thumb-placeholder { width: 32px; height: 32px; font-size: .9rem; }
  .table-prodotti td:nth-child(2) { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Pulsanti Vendi/Modifica/Rimuovi: solo icona, pillola piccola e circolare
     — le righe erano troppo larghe con le etichette per esteso. */
  .action-group { gap: .3rem; flex-wrap: nowrap; }
  .btn-icon-action {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .btn-icon-action .btn-label { display: none; }
  .btn-icon-action .btn-icon { font-size: .85rem; line-height: 1; }

  /* Pulsante "Aggiungi": ben visibile, centrato sotto il titolo invece di
     stare compresso a destra sulla stessa riga. */
  .page-header-flex { flex-direction: column; align-items: flex-start; }
  .page-header-flex #toggleFormBtn { align-self: flex-start; }

  /* Il filtro si applica già in automatico mentre si scrive: la lente non serve. */
  #searchBtn { display: none; }

  .cat-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .cat-tab { white-space: nowrap; flex-shrink: 0; }

  .filter-bar { flex-direction: row; flex-wrap: wrap; }
  .filter-bar input[type="text"] { flex: 1; min-width: 0; max-width: none; }
  .filter-bar .search-compact { flex: none; width: 150px; }

  .flash-container { left: 1rem; right: 1rem; max-width: none; }

  /* ── Dashboard: card KPI unica (Profitto netto in evidenza), grafico
       orizzontale compatto, card categoria più piccole ── */
  .secondary-stats { display: none; }

  /* #kpiGrid ora contiene una sola card (.kpi-hero): a piena larghezza,
     non più divisa in 2 colonne come quando c'erano 3-4 card KPI. */
  .kpi-grid { grid-template-columns: 1fr; }

  .kpi-hero { padding: 1.1rem 1.1rem 1rem; }
  .kpi-hero-label {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-muted);
  }
  .kpi-hero-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    margin: .3rem 0 .15rem;
  }
  .kpi-hero-sub { font-size: .75rem; color: var(--color-muted); margin-bottom: .9rem; }
  .kpi-hero-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
    padding-top: .75rem;
    border-top: 1px solid var(--color-border);
  }
  .kpi-hero-stat { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
  .kpi-hero-stat-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .02em; color: var(--color-muted); }
  .kpi-hero-stat-value { font-size: .88rem; font-weight: 700; color: var(--color-dark); overflow-wrap: break-word; }

  #chartMensileWrap { height: 220px; width: calc(100% - 76px); margin: 0 auto; overflow: hidden; }
  #chartMensileWrap canvas { max-height: 220px; }
  .chart-section { padding: 1rem .75rem .5rem; overflow: hidden; }
  .chart-title { font-size: .95rem; margin-bottom: .15rem; }

  /* Card categoria: 2 colonne, più piccole (ma sempre una card per categoria). */
  .cat-grid { grid-template-columns: 1fr; gap: .75rem; }
  .cat-card { min-width: 0; }
  .cat-card-header { padding: .6rem .75rem; gap: .4rem; }
  .cat-icon { font-size: 1.05rem; }
  .cat-name { font-size: .85rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cat-count { font-size: .68rem; padding: .1rem .4rem; flex-shrink: 0; }
  .cat-rows { padding: .6rem .75rem; gap: .3rem; }
  .cat-row-label { font-size: .72rem; }
  .cat-row-value { font-size: .78rem; }

  /* Ultime vendite: nome+orario sulla prima riga, dettaglio sotto a riga
     intera invece che troncato in linea — meno largo, niente scorrimento. */
  .movimento-row { flex-wrap: wrap; }
  .mov-nome {
    order: 0;
    flex: 1 1 auto;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .mov-time { order: 1; }
  .mov-details {
    order: 2;
    flex: 1 0 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    margin-top: .15rem;
  }
}

@media (max-width: 768px) {
  /* Colonne nascoste per default (secondarie): Categoria, Costo mat.,
     Magazzino (il dato disp/tot è ora dentro il chip Stato), Ricavo,
     Aggiunto. Restano sempre visibili: Nome, Prezzo vendita, Stato e —
     soprattutto — Azioni (Vendi/Modifica/Rimuovi). */
  .table-prodotti th:nth-child(3),
  .table-prodotti th:nth-child(5),
  .table-prodotti th:nth-child(6),
  .table-prodotti th:nth-child(7),
  .table-prodotti th:nth-child(8),
  .table-prodotti td:nth-child(3),
  .table-prodotti td:nth-child(5),
  .table-prodotti td:nth-child(6),
  .table-prodotti td:nth-child(7),
  .table-prodotti td:nth-child(8) { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.6rem; }
  /* .kpi-grid (dashboard) resta 2x2 anche sotto i 480px: vedi @media 768px sopra. */
}

@media (max-width: 768px) {
  .lightbox-img {
    max-width: 95vw;
    max-height: 65vh;
    max-height: 65svh;
    max-height: 65dvh;
  }
  .lightbox-backdrop { padding: .5rem; }
  .lightbox-caption { font-size: .8rem; }
}
