:root {
  --gold: #b5850b;
  --gold-dark: #8f6907;
  --gold-light: #f4e9c8;
  --gold-bar: #d8ab1f;
  --ink: #1f2a37;
  --ink-soft: #5b6672;
  --line: #e6e2d6;
  --bg: #faf7ef;
  --card: #ffffff;
  --shadow: 0 1px 3px rgba(31, 42, 55, 0.08), 0 6px 20px rgba(31, 42, 55, 0.06);
  --shadow-lg: 0 10px 40px rgba(31, 42, 55, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --verde: #2e7d32;
  --giallo: #f9a825;
  --rosso: #c62828;
  --danger: #c62828;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); min-height: 100vh; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--gold-dark); text-decoration: none; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 10px 16px; font-size: 15px; font-weight: 600; line-height: 1;
  background: #eef0f3; color: var(--ink); transition: filter .15s, background .15s, transform .05s; }
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-dark); filter: none; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: #fff; color: var(--danger); border-color: #eccdcd; }
.btn-danger:hover { background: #fdecec; filter: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 40; background: var(--card); border-bottom: 1px solid var(--line); border-top: 4px solid var(--gold-bar); }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--ink); }
.brand .logo { font-size: 22px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
.spacer { flex: 1; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.nav a.active { background: var(--gold-light); color: var(--gold-dark); }
.nav a:hover:not(.active) { background: #f4f2ea; }

.usermenu { position: relative; }
.usermenu-btn { display: flex; align-items: center; gap: 8px; background: #f4f2ea; border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 10px 6px 6px; font-weight: 600; font-size: 13px; color: var(--ink); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--gold); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.usermenu-panel { position: absolute; right: 0; top: calc(100% + 8px); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 210px; padding: 8px; z-index: 50; }
.usermenu-panel[hidden] { display: none; }
.usermenu-panel .uinfo { padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.usermenu-panel .uinfo strong { display: block; }
.usermenu-panel a, .usermenu-panel button { width: 100%; text-align: left; background: none; border: none;
  padding: 9px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--ink); display: block; }
.usermenu-panel a:hover, .usermenu-panel button:hover { background: #f4f2ea; }
.role-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 999px;
  font-weight: 700; background: var(--gold-light); color: var(--gold-dark); }
.reparto-bar { background: var(--gold-light); color: var(--gold-dark); font-size: 13px; font-weight: 600;
  border-top: 1px solid #eadcae; padding: 7px 16px; text-align: center; }
.reparto-bar strong { font-weight: 800; }

/* Layout */
.container { max-width: 1080px; margin: 0 auto; padding: 18px 16px 60px; }
.mobile-nav { display: none; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 800; line-height: 1; }
.stat .l { font-size: 12px; color: var(--ink-soft); margin-top: 6px; text-transform: uppercase; letter-spacing: .04em; }
.stat.alert .n { color: var(--rosso); }

/* Toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .search { flex: 1; min-width: 180px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.date-filter { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.date-filter input[type="date"] { width: auto; padding: 8px 10px; font-size: 14px; }

/* Cards / list */
.cards { display: grid; gap: 12px; }
.rcard { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); transition: box-shadow .15s, transform .05s; display: block; color: var(--ink); }
.rcard:hover { box-shadow: var(--shadow-lg); }
.rcard:active { transform: translateY(1px); }
.rcard.p-rosso { border-left-color: var(--rosso); }
.rcard.p-giallo { border-left-color: var(--giallo); }
.rcard.p-verde { border-left-color: var(--verde); }
.rcard-head { display: flex; align-items: flex-start; gap: 10px; }
.rcard-head h3 { margin: 0; font-size: 16px; flex: 1; }
.rcard-id { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.rcard-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.rcard-meta span { display: inline-flex; align-items: center; gap: 5px; }
.rcard-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; color: #fff; text-transform: uppercase; letter-spacing: .03em; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .95; }
.badge-soft { background: #eef0f3; color: var(--ink-soft); }

.empty { text-align: center; padding: 50px 20px; color: var(--ink-soft); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* Forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.form-card { max-width: 680px; margin: 0 auto; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 7px; font-size: 14px; }
.field .req { color: var(--rosso); }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; color: var(--ink); }
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(181,133,11,.15); }
.radio-list { display: grid; gap: 8px; }
.radio-item { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; }
.radio-item:hover { border-color: var(--gold); }
.radio-item.checked { border-color: var(--gold); background: var(--gold-light); }
.radio-item input { width: auto; }
.radio-altro-input { margin-top: 8px; }

.priority-select { display: grid; gap: 8px; }
.priority-opt { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.priority-opt .pdot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.priority-opt.checked { box-shadow: 0 0 0 2px currentColor inset; }
.priority-opt input { width: auto; }

/* Photo uploader */
.uploader { border: 2px dashed var(--line); border-radius: var(--radius-sm); padding: 16px; text-align: center; }
.uploader-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.uploader .uploader-btn { display: inline-flex; align-items: center; gap: 7px; padding: 11px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--gold-dark);
  font-weight: 700; font-size: 14px; cursor: pointer; }
.uploader .uploader-btn:hover { background: var(--gold-light); border-color: var(--gold); }
.uploader .uploader-btn:active { transform: translateY(1px); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background: #f2f2f2; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .rm { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0,0,0,.6);
  color: #fff; border: none; font-size: 14px; line-height: 1; display: grid; place-items: center; }

/* Detail */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.detail-head a.back { font-size: 22px; color: var(--ink-soft); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 14px 0; }
.detail-grid .full { grid-column: 1 / -1; }
.dl dt { color: var(--ink-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.dl dd { margin: 0; font-weight: 600; font-size: 14.5px; word-break: break-word; }
.timing { background: #faf9f4; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }

.block-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); margin: 20px 0 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo-grid a { display: block; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; }

.timeline { position: relative; margin-left: 6px; padding-left: 20px; border-left: 2px solid var(--line); }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item::before { content: ""; position: absolute; left: -27px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.tl-item.done::before { background: var(--verde); }
.tl-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-when { font-size: 12px; color: var(--ink-soft); }
.tl-who { font-weight: 700; font-size: 13.5px; }
.tl-note { margin: 6px 0 0; font-size: 14px; white-space: pre-wrap; }
.tl-photos { margin-top: 8px; }

.action-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 18px; box-shadow: var(--shadow); }
.status-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 8px; margin-bottom: 12px; }
.status-opt { border: 1px solid var(--line); background: #fff; border-radius: var(--radius-sm); padding: 10px; font-weight: 700;
  font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 8px; cursor: pointer; }
.status-opt .dot { width: 10px; height: 10px; border-radius: 50%; }
.status-opt.sel { border-width: 2px; }
.status-opt input { display: none; }

/* Users table */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.users { width: 100%; border-collapse: collapse; min-width: 560px; }
table.users th, table.users td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.users th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #faf9f4; }
table.users tr:last-child td { border-bottom: none; }
.pill-off { background: #f3d9d9; color: #a11; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill-on { background: #d7ecd8; color: #2e7d32; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* Impostazioni (elenchi) */
.setting-list { display: flex; flex-direction: column; gap: 6px; }
.setting-row { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; }
.setting-val { flex: 1; font-weight: 600; word-break: break-word; }
.setting-actions { display: flex; align-items: center; gap: 6px; }
.setting-actions form { display: inline; }
.iconbtn-sm { width: 30px; height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: #fff; color: var(--ink-soft); font-size: 15px; line-height: 1; cursor: pointer; }
.iconbtn-sm:hover { background: var(--gold-light); border-color: var(--gold); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #fbf6e6, #f3ead0 60%, #efe4c4); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; }
.login-top { background: var(--gold-bar); height: 8px; }
.login-inner { padding: 32px 28px; }
.login-inner .logo { font-size: 40px; text-align: center; }
.login-inner h1 { text-align: center; font-size: 22px; margin: 8px 0 2px; }
.login-inner p.sub { text-align: center; color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--ink-soft); text-align: center; line-height: 1.6; }
.login-back { display: inline-block; margin-top: 16px; font-size: 13px; font-weight: 600; }

/* Scelta profilo */
.role-choice { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 12px; cursor: pointer; color: var(--ink); transition: border-color .15s, box-shadow .15s, transform .05s; }
.role-choice:hover { border-color: var(--gold); box-shadow: var(--shadow); }
.role-choice:active { transform: translateY(1px); }
.role-choice .role-ic { font-size: 26px; width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  background: var(--gold-light); border-radius: 12px; }
.role-choice .role-txt { flex: 1; display: flex; flex-direction: column; }
.role-choice .role-txt strong { font-size: 16px; }
.role-choice .role-txt small { color: var(--ink-soft); font-size: 12.5px; }
.role-choice .role-arrow { color: var(--gold-dark); font-size: 20px; font-weight: 700; }
.role-choice.role-op { border-color: var(--gold); background: linear-gradient(180deg, #fffdf5, #fff); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,24,30,.45); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal-overlay[hidden] { display: none; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(460px, 100%); padding: 22px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Flash / errors */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 600; margin-bottom: 16px; }
.flash.ok { background: #e3f2e4; color: #23632a; border: 1px solid #bfe0c2; }
.flash.warn { background: #fdf3d6; color: #8a6d00; border: 1px solid #eddca0; }
.inline-error { background: #fdecec; color: #a3231f; border: 1px solid #f3caca; border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.field-error { color: var(--rosso); font-size: 13px; margin-top: 5px; font-weight: 600; }

.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb0 { margin-bottom: 0; }

@media (max-width: 720px) {
  .nav { display: none; }
  .brand small { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .mobile-nav { display: flex; position: sticky; bottom: 0; z-index: 40; background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { flex: 1; padding: 8px 4px; font-size: 11px; font-weight: 600; color: var(--ink-soft); display: flex; flex-direction: column; align-items: center; gap: 3px; }
  .mobile-nav a .ic { font-size: 20px; }
  .mobile-nav a.active { color: var(--gold-dark); }
}
