/* Stile pannello gestionale — dark theme coerente col frontend MRY */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --primary: #FFDE00;
  --primary-ink: #0a0a0a;
  --primary-dark: #e6c800;
  --accent: #e30513;
  --ink: #f1f1f3;
  --muted: #9a9aa6;
  --bg: #0b0b0e;
  --card: #15151a;
  --card-2: #1c1c22;
  --border: #2a2a32;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 18px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Struttura: sidebar laterale + area contenuto ────────────────────── */
.shell { display: flex; min-height: 100vh; align-items: flex-start; }

.sidebar {
  width: 256px; flex-shrink: 0; background: #000; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 150;
}
.sidebar-brand {
  padding: 18px 20px 16px; font-weight: 800; font-size: 16px; letter-spacing: .2px; color: var(--primary);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-close { display: none; background: none; border: 0; color: #888; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 12px 14px; }
.sidebar-openall {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 8px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); cursor: pointer;
  user-select: none;
}
.sidebar-openall input { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }
.nav-section { margin-bottom: 4px; }
.nav-section:last-child { margin-bottom: 4px; }
.nav-section-title {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  font-size: 11px; text-transform: uppercase; color: var(--primary); font-weight: 800; letter-spacing: .6px;
  padding: 10px 10px; background: none; border: 0; cursor: pointer; border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav-section-title:hover { background: rgba(255,222,0,.08); }
.nav-section-chevron {
  font-size: 14px; color: var(--muted); transition: transform .18s ease; transform: rotate(0deg); line-height: 1;
}
.nav-section.open .nav-section-chevron { transform: rotate(90deg); }
.nav-section-items { display: none; padding: 2px 0 8px; }
.nav-section.open .nav-section-items { display: block; }
.nav-section-flat .nav-section-items { display: block; padding: 0; }
.sidebar-nav a {
  display: block; color: #c4c7d4; font-size: 13.5px; font-weight: 600; padding: 9px 12px 9px 18px; border-radius: 8px;
  margin-bottom: 2px; transition: background .15s, color .15s;
}
.sidebar-nav a.active { background: var(--primary); color: var(--primary-ink); }
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-user {
  padding: 14px 20px; border-top: 1px solid var(--border); font-size: 12.5px; color: #b6bacb;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0;
}
.sidebar-user a { color: var(--accent); font-weight: 700; }
.sidebar-user a:hover { color: #ff5c5c; }

.main-area { flex: 1; min-width: 0; }

/* Barra superiore visibile solo su mobile/tablet (brand + pulsante menu) */
.topbar-mobile {
  display: none; background: #000; color: #fff; padding: 12px 16px; border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 140;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.topbar-mobile .brand { font-weight: 800; font-size: 16px; color: var(--primary); }

.burger-btn {
  background: var(--card-2); border: 1px solid var(--border); border-radius: 8px;
  width: 42px; height: 38px; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 0; flex-shrink: 0;
}
.burger-btn span { display: block; width: 20px; height: 2px; background: #fff; border-radius: 2px; transition: transform .15s, opacity .15s; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 149; }
.sidebar-backdrop.open { display: block; }

.container { max-width: 1220px; margin: 0 auto; padding: 28px 24px 70px; }
.page-title { font-size: 24px; font-weight: 800; margin: 4px 0 24px; letter-spacing: -.3px; color: #fff; }

@media (max-width: 900px) {
  .topbar-mobile { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 280px; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: 6px 0 24px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .container { padding: 24px 16px 60px; }
}

/* Cards / tabelle */
.card { background: var(--card); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table th, table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); color: var(--ink); }
table th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; background: var(--card-2); }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--card-2); }

/* Form */
label { display: block; font-size: 12.5px; font-weight: 700; margin: 12px 0 6px; color: #cfcfd6; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13.5px; font-family: inherit; background: var(--card-2); color: var(--ink); transition: border-color .15s;
}
input::placeholder, textarea::placeholder { color: #6b6b75; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

button, .btn {
  display: inline-block; background: var(--primary); color: var(--primary-ink); border: 0; padding: 10px 18px;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: all .15s;
}
button:hover, .btn:hover { background: var(--primary-dark); text-decoration: none; color: var(--primary-ink); transform: translateY(-1px); }
.btn-secondary { background: var(--card-2); color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #26262e; color: var(--ink); }
.btn-danger { background: rgba(227,5,19,.15); color: #ff6b6b; border: 1px solid rgba(227,5,19,.3); }
.btn-danger:hover { background: rgba(227,5,19,.25); color: #ff8080; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 7px; }

/* Badges */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .2px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13.5px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: rgba(46,204,113,.1); color: #4ade80; border-color: rgba(46,204,113,.25); }
.alert-error { background: rgba(227,5,19,.1); color: #ff6b6b; border-color: rgba(227,5,19,.25); }
.alert-info { background: rgba(255,222,0,.08); color: #FFDE00; border-color: rgba(255,222,0,.25); }

/* Grid stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-card .label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; font-weight: 700; letter-spacing: .4px; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; color: #fff; }

/* Product grid */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.product-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.product-img { width: 100%; height: 140px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: 10px; background: var(--card-2); }
.product-card .name { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; color: #fff; }
.product-card .cat { font-size: 11px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .3px; }
.product-card .price { font-size: 17px; font-weight: 800; color: var(--primary); margin: 8px 0; }
.product-card form { display: flex; gap: 6px; }
.product-card input[type=number] { width: 60px; }

.tabs { display: flex; gap: 4px; border-bottom: 1.5px solid var(--border); margin-bottom: 20px; }
.tabs a { padding: 10px 16px; font-size: 13.5px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1.5px; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }

.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }

/* ── Modale (Nuovo/Modifica) ─────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 1000;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 720px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: modalIn .18s ease; overflow: hidden;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between; padding: 20px 26px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); z-index: 2;
}
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 800; color: #fff; }
.modal-close { background: none; border: 0; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--card-2); color: var(--ink); }
.modal-body { padding: 22px 26px; max-height: 70vh; overflow-y: auto; }
.modal-footer { padding: 16px 26px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; background: var(--card-2); }
.btn-launcher { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 11px 20px; }

/* ── Editor ricco (Quill) ─────────────────────────────────────────────── */
.rich-editor-wrap .ql-toolbar { border-radius: 8px 8px 0 0; border-color: var(--border); background: var(--card-2); filter: invert(1) hue-rotate(180deg); }
.rich-editor-wrap .ql-container { border-radius: 0 0 8px 8px; border-color: var(--border); font-family: inherit; font-size: 13.5px; min-height: 160px; background: var(--card-2); color: var(--ink); }
.rich-editor-wrap .ql-editor { min-height: 160px; color: var(--ink); }

/* ── Tabs con badge conteggio ─────────────────────────────────────────── */
.tab-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.tab-pill {
  padding: 9px 18px; border-radius: 30px; font-size: 13px; font-weight: 700; background: var(--card-2); color: var(--muted);
  border: 1.5px solid transparent; cursor: pointer;
}
.tab-pill.active { background: var(--primary); color: var(--primary-ink); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Righe elenco entità (prodotto/corso/regola) ─────────────────────── */
.entity-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 10px; background: var(--card-2);
}
.entity-row img.thumb, .entity-row div.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--card); flex-shrink: 0; }
.entity-row .entity-main { flex: 1 1 200px; min-width: 200px; }
.entity-row .entity-main .title { font-weight: 700; font-size: 14px; color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.entity-row .entity-main .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; word-break: break-word; }
.entity-row .entity-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }

.rule-sentence { font-size: 14px; }
.rule-sentence b { color: #fff; }
.rule-sentence .accent { color: var(--primary); font-weight: 700; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .ic { font-size: 34px; margin-bottom: 10px; }

/* scrollbar dark */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

@media (max-width: 700px) {
  table { font-size: 12px; }

  /* Tabelle: scroll orizzontale dentro la card invece di rompere il layout */
  .card { overflow-x: auto; }

  /* Form/filtri: gli input con larghezza fissa inline diventano full-width */
  .card input, .card select { min-width: 0 !important; width: 100%; }
  .flex-between > form { width: 100%; }

  /* Righe entità (prodotti/categorie/corrieri/regole): contenuto sopra, azioni sotto a tutta larghezza */
  .entity-row { align-items: flex-start; }
  .entity-row .entity-main { order: 3; flex: 1 1 100%; width: 100%; }
  .entity-row .entity-actions {
    order: 4; flex: 1 1 100%; width: 100%; margin-top: 4px; padding-top: 10px;
    border-top: 1px solid var(--border);
  }
  .entity-row .entity-actions .btn-sm { flex: 1 1 auto; text-align: center; min-width: 90px; }

  /* Modali a schermo intero su mobile */
  .modal-overlay { padding: 0; }
  .modal-box { max-width: 100%; width: 100%; min-height: 100%; border-radius: 0; }
  .modal-body { max-height: calc(100vh - 130px); }

  /* Gruppi di card/stat affiancate: una sotto l'altra */
  .stat-grid, .form-row { grid-template-columns: 1fr; }
}
