/* Palette tipografia da https://www.integrabusiness.net/ */
:root {
  --black: #000000;
  --ink: #141414;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bg: #f5f5f5;
  --bg-2: #eeeeee;
  --panel: #ffffff;
  --gold: #f9b60f;
  --gold-deep: #fab715;
  --orange: #ec6608;
  --accent: #ec6608;
  --accent-2: #f9b60f;
  --danger: #c62828;
  --ok: #2e7d32;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  --radius: 4px;
  --font: "Manrope", "Helvetica Neue", Arial, sans-serif;
  --sans: "Tajawal", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(249, 182, 15, 0.12) 0%, transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(236, 102, 8, 0.08) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--gold-deep); text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  padding: 1.5rem 1.1rem;
  border-right: 1px solid #1a1a1a;
  background: var(--black);
  color: #fff;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand {
  display: block;
  margin: 0 0 .35rem;
  text-decoration: none;
  color: inherit;
}
.brand:hover { text-decoration: none; }
.brand img {
  display: block;
  width: 100%;
  max-width: 220px;
  height: auto;
}
.brand small {
  display: block;
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 300;
  color: #aeaeae;
  margin-top: .55rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.nav {
  margin-top: 1.35rem;
  display: flex;
  flex-direction: column;
  gap: .12rem;
}
.nav a {
  display: flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 .75rem;
  border-radius: 2px;
  color: #fff;
  text-decoration: none;
  font-family: var(--font);
  font-size: .92rem;
  font-weight: 500;
  letter-spacing: .05em;
  line-height: 1;
  text-transform: uppercase;
}
.nav a:hover, .nav a.active {
  background: rgba(236, 102, 8, 0.85);
  color: #fff;
  text-decoration: none;
}
.nav .section {
  display: flex;
  align-items: center;
  min-height: 1.85rem;
  margin: .9rem 0 0;
  padding: 0 .75rem;
  font-family: var(--font);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .1em;
  line-height: 1;
  text-transform: uppercase;
  color: var(--gold);
}
.nav .section:first-child { margin-top: 0; }
.userbox {
  margin-top: 2rem;
  padding: .8rem;
  border: 1px solid rgba(249, 182, 15, 0.35);
  border-radius: 2px;
  font-size: .95rem;
  color: #aeaeae;
}
.userbox strong { color: #fff; display: block; font-size: 1rem; }
.userbox a { color: var(--gold); }

.main { padding: 1.5rem 1.75rem 3rem; }
.mobile-bar { display: none; }
.menu-toggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 2.5rem;
  height: 2.5rem;
  padding: .55rem;
  border: 1px solid #333;
  border-radius: 2px;
  background: #111;
  cursor: pointer;
}
.menu-toggle span {
  display: block;
  height: 2px;
  background: var(--gold);
  border-radius: 1px;
}
.mobile-brand img { display: block; height: 36px; width: auto; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 40;
}
.sidebar-backdrop[hidden] {
  display: none !important;
}
.topbar { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.25rem; }
.topbar-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filter-bar { margin-bottom: 1rem; }
.inline-label {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .85rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.inline-label input,
.inline-label select {
  font-weight: 400;
  color: var(--ink);
}
.inline-label input[type="date"],
.toolbar select,
.toolbar input[name="q"] {
  min-width: 0;
}
.toolbar input[name="q"] { min-width: 220px; flex: 1; }
.filter-bar .toolbar { margin-bottom: 0; }
.topbar h1 {
  margin: 0;
  font-family: var(--font);
  font-weight: 600;
  font-size: clamp(1.75rem, 2.6vw, 2.35rem);
  letter-spacing: 0.02em;
  color: var(--ink);
}
.topbar p { margin: .4rem 0 0; color: var(--muted); font-size: 1.05rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.35rem;
  font-size: 1rem;
}
.panel + .panel { margin-top: 1rem; }
.panel h2, .panel h3 {
  margin: 0 0 .95rem;
  font-family: var(--font);
  font-weight: 600;
  font-size: 1.35rem;
}

.grid { display: grid; gap: 1rem; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat {
  padding: 1.15rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  border-top: 3px solid var(--gold);
}
.stat .label {
  color: var(--muted);
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-family: var(--font);
  font-weight: 600;
}
.stat .value {
  font-family: var(--font);
  font-size: 1.65rem;
  font-weight: 700;
  margin-top: .4rem;
  line-height: 1.2;
}
.stat.neg .value { color: var(--orange); }
.stat.pos .value { color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 1rem; }
th, td {
  padding: .8rem .6rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  line-height: 1.35;
}
th {
  font-family: var(--font);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #555;
  background: #fafafa;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:hover td { background: rgba(249, 182, 15, 0.08); }
.total-row td { font-weight: 700; background: rgba(249, 182, 15, 0.12); }

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 2.4rem;
  padding: 0 1.15rem;
  border: 1px solid var(--orange);
  background: var(--orange);
  color: #fff;
  border-radius: 2px;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  -webkit-appearance: none;
  appearance: none;
}
.btn:hover { background: var(--gold); border-color: var(--gold); color: #000; text-decoration: none; }
.btn.secondary { background: transparent; color: var(--orange); }
.btn.secondary:hover { background: var(--orange); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--orange); color: var(--orange); background: transparent; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .9rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: .35rem; font-size: .95rem; color: #888; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 2px;
  padding: .75rem .85rem;
  font-family: var(--sans);
  font-size: 1.05rem;
  color: var(--ink);
  background: #efefef;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(236, 102, 8, 0.35);
  border-color: var(--orange);
  background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.form-actions { margin-top: 1.2rem; display: flex; gap: .6rem; flex-wrap: wrap; }

.flash {
  margin-bottom: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  border: 1px solid;
}
.flash.success { background: #e8f5e9; border-color: #a5d6a7; color: var(--ok); }
.flash.error { background: #ffebee; border-color: #ef9a9a; color: var(--danger); }

.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar form { display: flex; gap: .5rem; flex-wrap: wrap; flex: 1; }
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  border-radius: 2px;
  background: rgba(249, 182, 15, 0.2);
  color: #8a5a00;
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge.admin { background: rgba(236, 102, 8, 0.18); color: var(--orange); }
.muted { color: var(--muted); font-size: 1rem; }
.pagination { display: flex; gap: .4rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: .45rem .75rem;
  border: 1px solid #ddd;
  border-radius: 2px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1rem;
}
.pagination a:hover { background: #eee; }
.pagination .current { background: var(--orange); color: #fff; border-color: var(--orange); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--black);
}
.login-card {
  width: min(420px, 100%);
  padding: 2.2rem;
  border-radius: 2px;
  border: 1px solid rgba(249, 182, 15, 0.45);
  background: #111;
  color: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.login-brand {
  margin: 0 0 1rem;
}
.login-brand img {
  display: block;
  width: min(260px, 100%);
  height: auto;
}
.login-card p { color: #aeaeae; margin: 0 0 1.4rem; font-size: 1.05rem; }
.login-card label { margin-bottom: .8rem; color: #aeaeae; }
.login-card input {
  background: #1a1a1a;
  border-color: #333;
  color: #fff;
}
.login-card input:focus {
  background: #222;
  border-color: var(--gold);
  outline-color: rgba(249, 182, 15, 0.35);
}
.login-card .flash.success { background: #1b3a22; border-color: #2e7d32; color: #a5d6a7; }
.login-card .flash.error { background: #3a1b1b; border-color: #c62828; color: #ef9a9a; }

.two-col { display: grid; grid-template-columns: 1.4fr .8fr; gap: 1rem; }
.scroll { overflow: auto; }

.twofa-setup {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  background: #fafafa;
}
.twofa-qr {
  display: block;
  width: 200px;
  height: 200px;
  background: #fff;
  border: 1px solid var(--line);
}
.twofa-secret {
  display: inline-block;
  margin-top: .35rem;
  padding: .55rem .75rem;
  background: #111;
  color: var(--gold);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.05rem;
  letter-spacing: .08em;
}

@media (max-width: 1100px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  /* +1pt tipografia mobile (~17px) */
  body { font-size: 17px; }
  .app-shell { grid-template-columns: 1fr; }
  .main { padding: 1rem 1rem 2.5rem; }
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: -1rem -1rem 1rem;
    padding: .75rem 1rem;
    background: var(--black);
    border-bottom: 1px solid #1a1a1a;
    position: sticky;
    top: 0;
    z-index: 30;
  }
  .menu-toggle {
    border-color: rgba(249, 182, 15, 0.45);
    background: #111;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: min(300px, 88vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 12px 0 40px rgba(0,0,0,.35);
  }
  .app-shell.nav-open .sidebar { transform: translateX(0); }
  .app-shell.nav-open .sidebar-backdrop {
    display: block;
  }
  body.nav-lock { overflow: hidden; }

  .form-grid { grid-template-columns: 1fr; }
  .grid.stats { grid-template-columns: 1fr; gap: .75rem; }
  .stat .label { font-size: .9rem; }
  .stat .value { font-size: 1.55rem; }
  .panel { padding: 1rem; }
  .panel h2, .panel h3 { font-size: 1.25rem; }
  .topbar h1 { font-size: 1.7rem; }
  .topbar p { font-size: 1rem; }
  table { font-size: 1rem; }
  th { font-size: .82rem; }
  .btn, button.btn { font-size: .92rem; min-height: 2.55rem; }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: .85rem;
  }
  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }
  .topbar-actions .btn { width: 100%; }

  /* Filtri: label sopra, campi a tutta larghezza */
  .filter-bar .toolbar,
  .toolbar form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .75rem;
    width: 100%;
  }
  .toolbar input[name="q"],
  .toolbar select,
  .toolbar input[type="date"],
  .inline-label input,
  .inline-label select {
    min-width: 0;
    width: 100%;
  }
  .inline-label {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: .35rem;
    width: 100%;
    white-space: normal;
    font-size: .95rem;
  }
  .filter-bar .btn,
  .toolbar .btn {
    width: 100%;
  }

  .scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .actions {
    flex-direction: column;
    align-items: stretch;
  }
  .actions .btn,
  .actions form,
  .actions button {
    width: 100%;
  }
}
