/* =============================================================
   CRM Samyadei Colori — Mobile-first design system
   Approccio: stili di default = mobile, @media min-width = desktop
   ============================================================= */

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

/* ── Tabelle globali ────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.lista-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}

.lista-table th {
  background: #f1f5f9;
  padding: .7rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.lista-table th:last-child {
  border-right: none;
}

.lista-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text);
}

.lista-table td:last-child {
  border-right: none;
}

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

.lista-table tbody tr {
  cursor: pointer;
}

.lista-table tbody tr:hover {
  background: #e0e7ef;
}

.lista-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.lista-table tbody tr:nth-child(even):hover {
  background: #e0e7ef;
}

/* ── Toolbar liste ──────────────────────────────────────────── */
.lista-toolbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary:hover {
  opacity: .88;
}

.btn-edit {
  display: inline-flex;
  align-items: center;
  font-size: .83rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: .4rem .75rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  white-space: nowrap;
}

.btn-edit:hover {
  background: #fdf2f4;
}

/* ── Paginazione ────────────────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  height: 2.4rem;
  padding: 0 .65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  color: var(--text);
  text-decoration: none;
  background: #fff;
  cursor: pointer;
  transition: background .15s;
}

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

.pag-btn.pag-disabled {
  opacity: .35;
  cursor: default;
  pointer-events: none;
}

.pag-info {
  font-size: .9rem;
  color: var(--text);
  padding: 0 .5rem;
  font-weight: 500;
}

@media (max-width: 768px) {
  .lista-toolbar {
    gap: .45rem;
  }

  .btn-primary {
    padding: .6rem 1.2rem;
    font-size: .9rem;
  }

  .btn-edit {
    padding: .45rem .8rem;
    font-size: .85rem;
  }

  .pag-btn {
    min-width: 2.6rem;
    height: 2.6rem;
    font-size: 1rem;
  }

  .pag-info {
    font-size: .88rem;
  }
}

/* ── Variabili ──────────────────────────────────────────────── */
:root {
  --sidebar-w: 240px;
  --bnav-h: 58px;
  --sidebar-bg: #16213e;
  --sidebar-hover: #0f3460;
  --accent: #e94560;
  --accent2: #0f3460;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0, 0, 0, .08);
  --green: #22c55e;
  --orange: #f97316;
  --blue: #3b82f6;
  --red: #ef4444;
  --purple: #a855f7;
  --yellow: #eab308;
}

html,
body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* ── LAYOUT MOBILE (default) ───────────────────────────────── */

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sidebar: drawer nascosto su mobile */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar.open {
  transform: translateX(0);
}

/* Overlay scuro quando sidebar è aperta */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 299;
}

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

/* Contenuto principale */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--bnav-h);
  min-height: 100vh;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .65rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: .3rem;
  color: var(--text);
  display: flex;
  align-items: center;
  border-radius: 6px;
}

.sidebar-toggle:hover {
  background: var(--bg);
}

.topbar__title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: .4rem;
}

.topbar__actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: .3rem;
  border-radius: 6px;
  color: var(--text-muted);
}

.topbar__actions button:hover {
  background: var(--bg);
}

/* ── BOTTOM NAVIGATION (mobile only) ───────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bnav-h);
  background: var(--sidebar-bg);
  display: flex;
  z-index: 100;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, .45);
  font-size: .58rem;
  font-weight: 500;
  gap: 3px;
  text-decoration: none;
  padding: 6px 0 4px;
  cursor: pointer;
  background: none;
  border: none;
  transition: color .15s;
}

.bottom-nav__item.active {
  color: var(--accent);
}

.bottom-nav__item:hover {
  color: rgba(255, 255, 255, .8);
}

.bottom-nav__item svg {
  width: 21px;
  height: 21px;
}

/* ── STATS BAR ──────────────────────────────────────────────── */
.stats-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: .35rem .75rem;
  white-space: nowrap;
  scrollbar-width: none;
}

.stats-bar::-webkit-scrollbar {
  display: none;
}

.stats-bar__item {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .25rem .5rem;
  font-size: .72rem;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.stats-bar__item:last-child {
  border-right: none;
}

.stats-bar__item strong {
  color: var(--text);
  font-weight: 700;
}

.stats-bar__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green {
  background: var(--green);
}

.dot-orange {
  background: var(--orange);
}

.dot-red {
  background: var(--red);
}

.dot-blue {
  background: var(--blue);
}

.dot-purple {
  background: var(--purple);
}

/* ── PAGE CONTENT ───────────────────────────────────────────── */
.page-content {
  padding: .85rem 1rem;
  flex: 1;
}

/* ── PERIOD FILTERS ─────────────────────────────────────────── */
.period-filters {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin-bottom: 1.25rem;
  padding-bottom: 2px;
}

.period-filters::-webkit-scrollbar {
  display: none;
}

.period-filters button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .28rem .75rem;
  font-size: .75rem;
  cursor: pointer;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all .15s;
}

.period-filters button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.period-filters button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── SECTION ────────────────────────────────────────────────── */
.section {
  margin-bottom: 1.5rem;
}

.section__header {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .65rem;
}

.section__header svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

/* ── CARDS (2 colonne di default su mobile) ─────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .6rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem .85rem;
  box-shadow: var(--shadow);
  position: relative;
}

.card__icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: .45rem;
}

.card__icon svg {
  width: 14px;
  height: 14px;
}

.card__icon.green {
  background: #dcfce7;
  color: var(--green);
}

.card__icon.orange {
  background: #ffedd5;
  color: var(--orange);
}

.card__icon.blue {
  background: #dbeafe;
  color: var(--blue);
}

.card__icon.red {
  background: #fee2e2;
  color: var(--red);
}

.card__icon.purple {
  background: #f3e8ff;
  color: var(--purple);
}

.card__icon.yellow {
  background: #fef9c3;
  color: var(--yellow);
}

.card__value {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.1;
}

.card__label {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

.card__period {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.card__info {
  position: absolute;
  top: .6rem;
  right: .6rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

/* ── TREND ──────────────────────────────────────────────────── */
.trend {
  display: inline-flex;
  align-items: center;
  gap: .15rem;
  font-size: .68rem;
  font-weight: 600;
  margin-top: .25rem;
}

.trend.up {
  color: var(--green);
}

.trend.down {
  color: var(--red);
}

/* ── FLASH MESSAGES ─────────────────────────────────────────── */
.messages {
  list-style: none;
  margin-bottom: 1rem;
}

.messages li {
  padding: .6rem 1rem;
  border-radius: 6px;
  margin-bottom: .4rem;
  font-size: .82rem;
}

.messages li.error {
  background: #fee2e2;
  color: var(--red);
  border: 1px solid #fca5a5;
}

.messages li.success {
  background: #dcfce7;
  color: #16a34a;
  border: 1px solid #86efac;
}

.messages li.warning {
  background: #fef9c3;
  color: #ca8a04;
  border: 1px solid #fde047;
}

/* ── SIDEBAR CONTENT ────────────────────────────────────────── */
.sidebar__logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem 1rem;
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .3px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar__logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  color: #fff;
  font-weight: 900;
  flex-shrink: 0;
}

.sidebar__nav {
  flex: 1;
  padding: .6rem 0;
  overflow-y: auto;
}

.sidebar__nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  color: rgba(255, 255, 255, .65);
  text-decoration: none;
  border-radius: 6px;
  margin: .1rem .5rem;
  font-size: .88rem;
  transition: background .15s, color .15s;
}

.sidebar__nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar__nav a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.sidebar__nav a svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar__nav .nav-section {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .3);
  letter-spacing: .08em;
  padding: .75rem 1rem .3rem;
}

.sidebar__user {
  border-top: 1px solid rgba(255, 255, 255, .08);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-shrink: 0;
}

.sidebar__avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .78rem;
  flex-shrink: 0;
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-info small {
  display: block;
  color: rgba(255, 255, 255, .4);
  font-size: .68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-name {
  color: rgba(255, 255, 255, .85);
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.sidebar__user-role {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  margin-top: 2px;
}

.sidebar__logout {
  color: rgba(255, 255, 255, .4);
  text-decoration: none;
  padding: .3rem;
  border-radius: 4px;
  display: flex;
  background: transparent;
  border: none;
  cursor: pointer;
}

.sidebar__logout:hover {
  color: #fff;
  background: rgba(255, 255, 255, .08);
}

/* ── DESKTOP (min-width: 768px) ─────────────────────────────── */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
    position: fixed;
  }

  .bottom-nav {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }

  .main {
    margin-left: var(--sidebar-w);
    padding-bottom: 0;
  }

  .topbar {
    padding: .75rem 1.5rem;
  }

  .topbar__title {
    font-size: 1.2rem;
  }

  .page-content {
    padding: 1.25rem 1.5rem;
  }

  .stats-bar {
    padding: .5rem 1.5rem;
  }

  .cards {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: .85rem;
  }

  .card {
    padding: 1rem 1.1rem;
  }

  .card__icon {
    width: 34px;
    height: 34px;
    margin-bottom: .65rem;
  }

  .card__icon svg {
    width: 18px;
    height: 18px;
  }

  .card__value {
    font-size: 1.6rem;
  }

  .card__label {
    font-size: .78rem;
  }

  .card__period {
    font-size: .7rem;
  }

  .card__info {
    width: 16px;
    height: 16px;
    top: .75rem;
    right: .75rem;
  }

  .section__header {
    font-size: .9rem;
    margin-bottom: .85rem;
  }

  .section {
    margin-bottom: 1.75rem;
  }
}