:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-alt: #f0f1f4;
  --border: #dfe2e8;
  --text: #1b1e24;
  --text-muted: #6b7280;
  --primary: #2f6fed;
  --primary-contrast: #ffffff;
  --danger: #d9463c;
  --success: #1d9e75;
  --warning: #ef9f27;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-alt: #262a32;
  --border: #333844;
  --text: #ecedf0;
  --text-muted: #9aa1ac;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1d2026;
    --surface-alt: #262a32;
    --border: #333844;
    --text: #ecedf0;
    --text-muted: #9aa1ac;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: var(--safe-bottom);
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 0.9em; }

a { color: var(--primary); }

/* ---------- Form basics ---------- */

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85em;
  color: var(--text-muted);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 16px; /* evita zoom automatico su iOS */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button {
  font-family: inherit;
  font-size: 0.95em;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 10px 16px;
  background: var(--surface-alt);
  color: var(--text);
  min-height: 40px;
}
button.block { width: 100%; }
button.primary { background: var(--primary); color: var(--primary-contrast); }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; border-color: var(--border); }
button.icon-btn { position: relative; min-width: 40px; padding: 8px; background: transparent; border: none; font-size: 1.1em; }
button.link-btn { background: none; border: none; color: var(--primary); padding: 4px; min-height: auto; font-size: 0.85em; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.error {
  color: var(--danger);
  min-height: 1.2em;
  font-size: 0.9em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.auth-card {
  max-width: 380px;
  margin: 10vh auto;
}
.auth-card h1 { font-size: 1.3em; margin-top: 0; }

/* ---------- Screens ---------- */

.screen { min-height: 100%; padding: 16px; }
#app-view { padding: 0; }

/* ---------- Header & nav ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-left, .header-right { display: flex; align-items: center; gap: 6px; }
.brand { font-size: 1.15em; font-weight: 800; letter-spacing: 0.2px; line-height: 1; white-space: nowrap; }
.user-chip { display: flex; align-items: center; gap: 6px; font-size: 0.85em; }
.badge {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.75em;
  text-transform: capitalize;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: calc(var(--header-h) + var(--safe-top));
  z-index: 15;
}
.tab {
  white-space: nowrap;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 10px;
  color: var(--text-muted);
  min-height: 36px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }

/* ---------- Toolbars & filters ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.toolbar h2 { margin: 0; font-size: 1.1em; }

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters select, .filters input { width: auto; min-width: 140px; flex: 1 1 140px; margin-top: 0; }

/* ---------- Dashboard ---------- */

.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 720px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1040px) {
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
}
.dash-card h3 { margin: 0 0 10px; font-size: 0.95em; }
.dash-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9em; }
.dash-item:last-child { border-bottom: none; }
.dash-empty { color: var(--text-muted); font-size: 0.9em; }

/* ---------- Legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.85em;
  color: var(--text-muted);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- Calendario a griglia mensile ---------- */

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-label { font-weight: 600; min-width: 140px; text-align: center; }

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 8px;
}
.month-grid .weekday-head {
  text-align: center;
  font-size: 0.75em;
  color: var(--text-muted);
  padding-bottom: 4px;
}
.day-cell {
  position: relative;
  min-height: 58px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.day-cell.outside { opacity: 0.35; }
.day-cell.today { border-color: var(--primary); }
.day-cell.weekend { background: var(--surface-alt); }
.day-cell .day-num { font-size: 0.8em; color: var(--text-muted); }
.day-dots { display: flex; flex-wrap: wrap; gap: 2px; }
.day-dots .dot { width: 8px; height: 8px; }
.day-more { font-size: 0.7em; color: var(--text-muted); }

@media (max-width: 480px) {
  .day-cell { min-height: 42px; padding: 3px; border-radius: 6px; }
  .month-grid { gap: 3px; }
}

/* ---------- Liste di richieste / utenti (card responsive) ---------- */

.request-list { display: flex; flex-direction: column; gap: 8px; }
.request-row, .user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.request-row .main-line { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 160px; overflow-wrap: anywhere; }
.request-row .who { font-weight: 600; }
.request-row .detail { font-size: 0.85em; color: var(--text-muted); }
.request-row .actions, .user-row .actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.status { display: inline-flex; align-items: center; justify-content: center; line-height: 1.2; padding: 4px 11px; border-radius: 999px; font-size: 0.78em; font-weight: 600; white-space: nowrap; }
.status-pending { background: rgba(239,159,39,0.18); color: #a4650f; }
.status-approved { background: rgba(29,158,117,0.18); color: #12654a; }
.status-rejected { background: rgba(217,70,60,0.18); color: #8f2b23; }
:root[data-theme="dark"] .status-pending { color: #f3c473; }
:root[data-theme="dark"] .status-approved { color: #6fd6b3; }
:root[data-theme="dark"] .status-rejected { color: #f0968e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .status-pending { color: #f3c473; }
  :root:not([data-theme="light"]) .status-approved { color: #6fd6b3; }
  :root:not([data-theme="light"]) .status-rejected { color: #f0968e; }
}

.empty-state { color: var(--text-muted); text-align: center; padding: 24px 12px; }

/* ---------- Skeleton loading ---------- */

.skeleton-block { display: flex; flex-direction: column; gap: 8px; }
.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--border) 37%, var(--surface-alt) 63%);
  background-size: 400% 100%;
  animation: skeleton-shine 1.4s ease infinite;
}
@keyframes skeleton-shine {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------- Modali ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin-top: 0; font-size: 1.1em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; margin: 0; }

@media (max-width: 480px) {
  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(20px + var(--safe-bottom));
  }
  .modal-actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; }
}

/* ---------- Notifiche ---------- */

.notif-wrap { position: relative; }
.badge-dot {
  position: absolute;
  top: 2px;
  right: 0;
  background: var(--danger);
  color: #fff;
  font-size: 0.65em;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.dropdown-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(340px, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
}
.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9em;
}
.dropdown-body { padding: 4px; }
.notif-item { padding: 10px; border-radius: 8px; font-size: 0.85em; cursor: pointer; }
.notif-item:hover { background: var(--surface-alt); }
.notif-item.unread { background: rgba(47,111,237,0.08); font-weight: 600; }
.notif-time { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.85em; margin-top: 2px; }

/* ---------- Toast ---------- */

.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: min(360px, 92vw);
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9em;
  text-align: center;
  animation: toast-in 0.2s ease;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Responsive nav (mobile) ---------- */

.header-left { min-width: 0; flex: 1 1 auto; }
.header-right { flex: 0 0 auto; }
.brand { overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 640px) {
  .user-chip span:first-child { display: none; } /* nasconde il nome, resta il ruolo, per fare spazio */
  main { padding: 12px; }
  .toolbar h2 { font-size: 1em; }
  .app-header { padding-left: 8px; padding-right: 8px; gap: 4px; }
  .header-right { gap: 2px; }
  .brand { max-width: 34vw; font-size: 0.9em; }
  #logout-btn { padding: 6px 10px; min-height: 36px; }
  /* il pannello notifiche occupa la larghezza dello schermo invece di uscire dal bordo sinistro */
  .notif-wrap { position: static; }
  .dropdown-panel {
    position: fixed;
    left: 8px;
    right: 8px;
    width: auto;
    top: calc(var(--header-h) + var(--safe-top) + 4px);
    max-height: 65vh;
  }
}

@media (max-width: 400px) {
  .brand { display: none; }
  .user-chip .badge { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- Extra sicurezza/UX (nessuno stile inline: compatibile con CSP) ---------- */
.mt-24 { margin-top: 24px; }
button.chip-btn { background: transparent; border: none; padding: 4px 6px; min-height: 36px; color: inherit; }
button.chip-btn .badge::after { content: " \25BE"; }


/* ========================================================================
   Popeyes visual refresh — mantiene invariata la logica dell'app
   ======================================================================== */
:root {
  --bg: #101214;
  --surface: #1a1d22;
  --surface-alt: #22262d;
  --border: #303640;
  --text: #f1f2f4;
  --text-muted: #9ba2ad;
  --primary: #ff7a00;
  --primary-contrast: #111214;
  --danger: #e84b43;
  --success: #20a982;
  --warning: #f2ad22;
  --radius: 14px;
  --shadow: 0 10px 28px rgba(0,0,0,.20);
}

:root[data-theme="light"] {
  --bg: #f7f7f5;
  --surface: #fff;
  --surface-alt: #f1f2f3;
  --border: #d9dce1;
  --text: #17191d;
  --text-muted: #69717c;
  --primary: #f47700;
  --primary-contrast: #fff;
}

body {
  background:
    radial-gradient(circle at 50% -10%, rgba(255,122,0,.07), transparent 32%),
    var(--bg);
  font-size: 16px;
}

button, input, select, textarea { border-radius: 14px; }
button { min-height: 44px; }
button.primary {
  background: linear-gradient(135deg, #ff8a00, #f56d00);
  box-shadow: 0 6px 16px rgba(255,122,0,.16);
  font-weight: 650;
}
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; border-color: var(--border); }
button.danger { background: #e94b43; }
input, select, textarea {
  background: #1b1e23;
  border-color: #343a45;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(255,122,0,.85);
  border-color: #ff7a00;
}

/* Login */
#login-view, #setup-view {
  padding: 28px 18px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
}
.login-brand {
  color: #ff7a00;
  font-weight: 900;
  letter-spacing: -2px;
  font-size: clamp(42px, 12vw, 68px);
  line-height: .9;
  margin-bottom: 22px;
}
.auth-card {
  width: min(100%, 440px);
  max-width: 440px;
  margin: 0;
  padding: 28px;
  border-radius: 20px;
  background: linear-gradient(145deg, #1d2026, #17191d);
  border: 1px solid #303640;
  box-shadow: 0 22px 60px rgba(0,0,0,.35);
}
.auth-card h1 { font-size: 1.45em; }
.product-mark { font-size: 1.7em; font-weight: 800; margin-bottom: 24px; letter-spacing: -.5px; }
.product-mark span { color: var(--text); }
.product-mark strong { color: var(--primary); }
.auth-card label { font-size: .9em; }
.auth-card input { min-height: 52px; }
.auth-card .block { min-height: 52px; margin-top: 8px; font-size: 1.02em; }

/* Header / navigation */
.app-header {
  height: calc(76px + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  background: rgba(25,28,33,.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand-lockup { display:flex; align-items:baseline; gap:10px; min-width:0; }
.brand-popeyes {
  color: #ff7a00;
  font-size: 1.28em;
  font-weight: 950;
  letter-spacing: -1.1px;
}
.brand-product { color: var(--text); font-size: .85em; font-weight: 700; opacity: .92; }
.brand-product::first-letter { color: var(--primary); }
.header-right { gap: 6px; }
.icon-btn { color: var(--text); }
.user-chip { border-radius: 999px !important; padding: 6px 10px !important; background: #22262d !important; }
.badge { border-color: #3a404b; background: #252a31; }

.tabs {
  padding: 0 14px;
  min-height: 64px;
  gap: 2px;
  background: rgba(25,28,33,.96);
  backdrop-filter: blur(14px);
}
.tab {
  min-height: 64px;
  padding: 10px 18px;
  font-size: 1em;
  border-bottom-width: 3px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

main { padding: 24px 18px 48px; max-width: 1180px; }

/* Dashboard cards */
.dash-grid { gap: 18px; }
.dash-card {
  border-radius: 18px;
  padding: 24px;
  background: linear-gradient(145deg, #1c2026, #191c21);
  border-color: #303640;
  box-shadow: var(--shadow);
}
.dash-card h3 { font-size: 1.05em; margin-bottom: 14px; }
.dash-item { padding: 12px 0; }

/* Toolbars / controls */
.toolbar { margin-bottom: 18px; }
.toolbar h2 { font-size: 1.25em; }
.filters { gap: 10px; margin-bottom: 18px; }
.filters select, .filters input { min-height: 48px; }

/* Calendar */
.calendar-nav { gap: 10px; }
.month-label { font-size: 1.15em; }
.month-grid { gap: 6px; margin-top: 12px; }
.day-cell {
  min-height: 68px;
  border-radius: 11px;
  background: #1a1e24;
  border-color: #303640;
  padding: 7px;
}
.day-cell.weekend { background: #23272f; }
.day-cell.today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.day-cell .day-num { font-size: .85em; }
.legend { gap: 16px; margin: 14px 0; font-size: .9em; }
.dot { width: 11px; height: 11px; }

/* User/request rows */
.request-list { gap: 12px; }
.request-row, .user-row {
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(145deg, #1c2026, #191c21);
  border-color: #303640;
  box-shadow: 0 5px 18px rgba(0,0,0,.12);
}
.user-row .who, .request-row .who { font-size: 1.05em; }
.user-row .detail { color: var(--text-muted); margin-top: 3px; }
.user-row .actions { gap: 8px; }
.status-approved { background: rgba(32,169,130,.18); }
.status-rejected { background: rgba(232,75,67,.18); }

/* Dropdowns / modals */
.dropdown-panel, .modal-card {
  border-radius: 18px;
  border-color: #343a45;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal { background: rgba(5,7,9,.68); backdrop-filter: blur(4px); }

@media (max-width: 640px) {
  .app-header { height: calc(76px + var(--safe-top)); }
  .brand-product { display: none; }
  .brand-popeyes { font-size: 1.08em; }
  .tabs { min-height: 62px; }
  .tab { min-height: 62px; padding-inline: 14px; }
  main { padding: 18px 12px 42px; }
  .dash-card { padding: 20px; }
  .user-row, .request-row { padding: 16px; }
}

@media (max-width: 480px) {
  .day-cell { min-height: 50px; padding: 5px; }
  .month-grid { gap: 4px; }
  .auth-card { padding: 24px 20px; }
}


/* Popeyes assets: use the supplied brand artwork instead of text approximations. */
#login-view {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 12%, rgba(255,122,0,.12), transparent 30%),
    #101214;
}
#login-view > * { position: relative; z-index: 2; }
.login-backdrop {
  position: absolute !important;
  z-index: 0 !important;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.login-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(16,18,20,.08), rgba(16,18,20,.72) 58%, #101214 92%);
}
.login-backdrop img {
  position: absolute;
  width: min(82vw, 560px);
  height: auto;
  right: -18vw;
  top: 7vh;
  opacity: .18;
  filter: drop-shadow(0 0 36px rgba(255,122,0,.16));
}
.login-brand {
  width: min(78vw, 430px);
  height: auto;
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-brand img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,.24));
}
.auth-card {
  position: relative;
  z-index: 3;
  backdrop-filter: blur(10px);
  background: linear-gradient(145deg, rgba(29,32,38,.94), rgba(18,20,24,.94));
}
.brand-popeyes-logo {
  display: block;
  width: 118px;
  max-width: 28vw;
  height: auto;
  object-fit: contain;
}
.brand-lockup { align-items: center; }

@media (max-width: 520px) {
  .login-brand { width: min(76vw, 330px); margin-bottom: 18px; }
  .login-backdrop img { width: 78vw; right: -26vw; top: 13vh; opacity: .15; }
  .auth-card { padding: 24px 20px; }
  .brand-popeyes-logo { width: 92px; }
}
