/* ============================================================
   Admin Panel CSS — Sviluppo Web Chieri
   Semplice, funzionale, coerente con il sito pubblico
   ============================================================ */

:root {
  --clr-primary:   #1a3a5c;
  --clr-accent:    #e85d26;
  --clr-bg:        #f0f2f5;
  --clr-white:     #ffffff;
  --clr-text:      #1f2937;
  --clr-muted:     #6b7280;
  --clr-border:    #e5e7eb;
  --clr-sidebar:   #111827;
  --clr-sidebar-hover: #1f2937;

  --sidebar-w: 240px;
  --topbar-h:  58px;

  --radius:    8px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);

  /* Status colors */
  --clr-success: #059669;
  --clr-warning: #d97706;
  --clr-danger:  #dc2626;
  --clr-info:    #2563eb;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Source Sans 3', 'Segoe UI', Arial, sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.6;
}

a { color: var(--clr-primary); text-decoration: none; }
a:hover { color: var(--clr-accent); }

/* ---- LAYOUT ---- */
.admin-wrap { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--clr-sidebar);
  color: rgba(255,255,255,.85);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  text-decoration: none;
}

.sidebar__brand-icon {
  width: 32px; height: 32px;
  background: var(--clr-accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .9rem; color: #fff;
  flex-shrink: 0;
}

.sidebar__brand-text {
  font-size: .85rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar__brand-text span { display: block; font-size: .7rem; color: rgba(255,255,255,.45); font-weight: 400; }

.sidebar__nav { padding: .75rem 0; flex: 1; }

.sidebar__section-label {
  font-size: .65rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  padding: .85rem 1.25rem .3rem;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem 1.25rem;
  font-size: .88rem;
  color: rgba(255,255,255,.7);
  transition: background .15s, color .15s;
  border-radius: 0;
}
.sidebar__link:hover,
.sidebar__link.active {
  background: var(--clr-sidebar-hover);
  color: #fff;
}
.sidebar__link.active { border-left: 3px solid var(--clr-accent); }
.sidebar__link .icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar__footer {
  padding: .85rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: .8rem;
  color: rgba(255,255,255,.4);
}

/* Main content */
.admin-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--clr-white);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.topbar__title { font-size: 1rem; font-weight: 700; color: var(--clr-primary); }

.topbar__user {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .85rem;
}

.topbar__avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .75rem;
}

/* Page content */
.page-content { padding: 1.5rem; flex: 1; }

/* ---- COMPONENTS ---- */

/* Stats cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

.stat-card {
  background: var(--clr-white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--clr-primary);
}
.stat-card--accent { border-color: var(--clr-accent); }
.stat-card--warning { border-color: var(--clr-warning); }
.stat-card--danger { border-color: var(--clr-danger); }

.stat-card__label { font-size: .78rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }
.stat-card__value { font-size: 2rem; font-weight: 800; color: var(--clr-primary); line-height: 1; }

/* Card / Panel */
.card {
  background: var(--clr-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--clr-border);
}
.card__title { font-size: .95rem; font-weight: 700; color: var(--clr-primary); }
.card__body { padding: 1.25rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th { background: var(--clr-bg); padding: .6rem .85rem; text-align: left; font-weight: 700; font-size: .78rem; color: var(--clr-muted); text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--clr-border); }
tbody td { padding: .65rem .85rem; border-bottom: 1px solid var(--clr-border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(0,0,0,.02); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1.1rem; border-radius: var(--radius); font-size: .85rem; font-weight: 700; border: 2px solid transparent; cursor: pointer; transition: all .15s; text-decoration: none; }
.btn--sm { padding: .3rem .75rem; font-size: .8rem; }
.btn--primary { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }
.btn--primary:hover { background: #0f2a47; color: #fff; }
.btn--accent { background: var(--clr-accent); color: #fff; border-color: var(--clr-accent); }
.btn--accent:hover { background: #c44d1a; color: #fff; }
.btn--outline { background: transparent; border-color: var(--clr-border); color: var(--clr-text); }
.btn--outline:hover { border-color: var(--clr-primary); color: var(--clr-primary); }
.btn--danger { background: var(--clr-danger); color: #fff; border-color: var(--clr-danger); }
.btn--danger:hover { background: #b91c1c; color: #fff; }

/* Badges / Status */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 100px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.badge--green  { background: #d1fae5; color: #065f46; }
.badge--orange { background: #fed7aa; color: #9a3412; }
.badge--blue   { background: #dbeafe; color: #1e40af; }
.badge--gray   { background: #f3f4f6; color: #4b5563; }
.badge--red    { background: #fee2e2; color: #991b1b; }
.badge--yellow { background: #fef3c7; color: #92400e; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-group label { font-size: .83rem; font-weight: 700; color: var(--clr-primary); }
.form-group input,
.form-group select,
.form-group textarea {
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .55rem .85rem;
  font-size: .9rem;
  font-family: inherit;
  color: var(--clr-text);
  background: var(--clr-bg);
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 3px rgba(26,58,92,.1); }
.form-group textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; gap: 1rem; }
.form-row--2 { grid-template-columns: 1fr 1fr; }
.form-row--3 { grid-template-columns: 1fr 1fr 1fr; }

/* Alerts */
.alert { padding: .85rem 1.1rem; border-radius: var(--radius); font-size: .88rem; margin-bottom: 1rem; }
.alert--success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert--error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert--warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert--info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* Progress bar */
.progress { height: 8px; background: var(--clr-border); border-radius: 4px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--clr-accent); border-radius: 4px; transition: width .3s; }

/* Timeline */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 1rem; padding-bottom: 1.25rem; position: relative; }
.timeline-item::before { content: ''; position: absolute; left: 15px; top: 28px; bottom: 0; width: 2px; background: var(--clr-border); }
.timeline-item:last-child::before { display: none; }
.timeline-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--clr-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .75rem; flex-shrink: 0; z-index: 1; }
.timeline-content { flex: 1; background: var(--clr-bg); border-radius: var(--radius); padding: .85rem 1rem; font-size: .88rem; }
.timeline-meta { font-size: .75rem; color: var(--clr-muted); margin-bottom: .35rem; }

/* Vault unlock screen */
.vault-unlock { max-width: 380px; margin: 5rem auto; text-align: center; }
.vault-unlock__icon { font-size: 3rem; margin-bottom: 1rem; }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1a3a5c, #0f2a47); }
.login-box { background: var(--clr-white); border-radius: 12px; padding: 2.5rem; width: 100%; max-width: 380px; box-shadow: var(--shadow-md); }
.login-logo { text-align: center; margin-bottom: 1.75rem; }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--clr-muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--clr-muted); }
.breadcrumb a:hover { color: var(--clr-primary); }
.breadcrumb span { color: var(--clr-text); font-weight: 600; }

/* Pagination */
.pagination { display: flex; gap: .35rem; align-items: center; margin-top: 1rem; }
.pagination a, .pagination span { padding: .35rem .7rem; border-radius: var(--radius); font-size: .82rem; border: 1px solid var(--clr-border); }
.pagination a:hover { background: var(--clr-bg); }
.pagination .current { background: var(--clr-primary); color: #fff; border-color: var(--clr-primary); }

/* ============================================================
   RESPONSIVE ADMIN — Mobile first
   ============================================================ */

/* ---- Sidebar mobile: nascosta di default ---- */
@media (max-width: 767px) {

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 260px;
    z-index: 200;
  }

  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }

  /* Overlay scuro dietro la sidebar aperta */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 190;
  }
  .sidebar-overlay.is-open { display: block; }

  .admin-main {
    margin-left: 0;
  }

  /* Topbar mobile */
  .topbar {
    padding: 0 1rem;
  }

  .topbar__user span { display: none; } /* Nasconde il nome, tiene solo l'avatar */

  /* Hamburger visibile su mobile */
  .topbar-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1.5px solid var(--clr-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--clr-primary);
    margin-right: .5rem;
    flex-shrink: 0;
  }

  /* Page content */
  .page-content { padding: 1rem; }

  /* Stats grid: 2 colonne su mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Tabelle: scroll orizzontale */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table { min-width: 560px; }

  /* Form row: colonna singola */
  .form-row--2,
  .form-row--3 {
    grid-template-columns: 1fr;
  }

  /* Card header: wrap su mobile */
  .card__header {
    flex-wrap: wrap;
    gap: .5rem;
  }

  /* Modali: full screen su mobile */
  [id^="modal-"] > div {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh;
    border-radius: 0 !important;
    margin: 0;
    padding: 1.25rem !important;
  }

  /* Buttons nei form: full width */
  .apt-row { flex-direction: column; align-items: flex-start !important; }

  /* Calendario: celle più piccole */
  #cal-grid > div { min-height: 52px !important; }
  #cal-grid { gap: 1px !important; }

  /* Tabs progetti: scroll orizzontale */
  .tabs-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    white-space: nowrap;
  }

  /* Timeline: riduce padding */
  .timeline-content { padding: .65rem .85rem; }

  /* Sidebar layout split (requests, etc) */
  [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ---- Tablet: sidebar sempre visibile ---- */
@media (min-width: 768px) {
  .topbar-menu-btn { display: none; }
  .sidebar-overlay  { display: none !important; }
  .sidebar { transform: none !important; }
}

/* ---- Piccoli aggiustamenti tablet ---- */
@media (min-width: 768px) and (max-width: 1023px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-row--3 {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================================
   LAYOUT HELPERS — sostituiscono gli stili inline per il responsive
   ============================================================ */

/* Griglia 2 colonne → 1 su mobile */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}

/* Griglia main + sidebar stretta (es. ticket detail) */
.grid-main-aside {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.25rem;
  align-items: start;
}

/* Griglia dettaglio dati (es. mittente richiesta) */
.grid-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.25rem;
  background: var(--clr-bg);
  border-radius: 8px;
  padding: 1rem;
}

/* Calendario: header giorni settimana */
.cal-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 4px;
}

/* Tabs scroll orizzontale */
.tabs-row {
  display: flex;
  gap: .35rem;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--clr-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs-row::-webkit-scrollbar { display: none; }

.tab-link {
  padding: .6rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  color: var(--clr-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-link.active {
  font-weight: 700;
  color: var(--clr-primary);
  border-bottom-color: var(--clr-accent);
}
.tab-link .tab-badge {
  border-radius: 100px;
  font-size: .65rem;
  padding: .1rem .45rem;
  margin-left: .2rem;
  color: #fff;
}

/* ---- RESPONSIVE overrides ---- */
@media (max-width: 767px) {
  .grid-2,
  .grid-main-aside {
    grid-template-columns: 1fr;
  }
  .grid-detail {
    grid-template-columns: 1fr;
  }
  /* Calendario: celle ancora più compatte */
  .cal-header div {
    font-size: .6rem !important;
    padding: .25rem 0 !important;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .grid-main-aside {
    grid-template-columns: 1fr 240px;
  }
}

/* Calendario griglia */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

/* Intestazione progetto: wrap su mobile */
@media (max-width: 767px) {
  /* Cal grid celle */
  .cal-grid > div { min-height: 52px !important; }

  /* Apt row in lista */
  .apt-row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: .5rem !important;
  }

  /* Topbar: titolo più corto */
  .topbar__title {
    font-size: .85rem;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Breadcrumb */
  .breadcrumb { flex-wrap: wrap; }

  /* Stats grid: 2 col anche se ci sono 4 items */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Vault: tabella azioni su mobile */
  .table-wrap table { min-width: 480px; }

  /* Login box: full width con padding ridotto */
  .login-box {
    padding: 1.5rem 1.25rem !important;
    border-radius: 0 !important;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Form row 2/3 → 1 colonna */
  .form-row--2,
  .form-row--3 {
    grid-template-columns: 1fr !important;
  }

  /* Bottoni affiancati → wrap */
  [style*="display:flex"][style*="gap:.5rem"],
  [style*="display:flex"][style*="gap:.75rem"] {
    flex-wrap: wrap;
  }

  /* Card header con pulsanti */
  .card__header .btn { font-size: .75rem; padding: .35rem .7rem; }

  /* Modali: altezza auto, non full screen su tablet grande */
  [id^="modal-"] > div {
    overflow-y: auto;
    max-height: 100vh;
  }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .sidebar { width: 200px; }
  .admin-main { margin-left: 200px; }
}