:root {
  --brand: #8b1a2b;
  --brand-dark: #6e1422;
  --ink: #2b2b2e;
  --ink-2: #5c5c63;
  --muted: #85858c;
  --line: #e2e2e6;
  --bg: #f6f6f7;
  --card: #ffffff;
  --ok: #2f7d4f;
  --warn: #a6670c;
  --soft: #f3e8ea;
  --focus: #1d5fbf;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; font-size: 16px; line-height: 1.45; }
a { color: var(--brand); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand img { height: 26px; display: block; }
.app-name { font-weight: 600; color: var(--ink-2); border-left: 1px solid var(--line); padding-left: 10px; }
.top-nav { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; text-decoration: none;
  border: 1px solid var(--line); color: var(--ink-2); background: var(--card); font-weight: 600; cursor: pointer;
}
.user-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--brand); color: #fff; font-weight: 600;
  cursor: pointer; font-size: 14px;
}
.menu {
  position: fixed; right: 12px; top: calc(56px + env(safe-area-inset-top)); z-index: 20; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px;
}
.menu-who { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--ink-2); }
.menu-item { display: block; padding: 12px 14px; text-decoration: none; color: var(--ink); }

main { max-width: 880px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
h1 { font-size: 22px; margin: 4px 0 4px; }
h2 { font-size: 17px; margin: 22px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.pad { padding: 32px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none;
  color: var(--ink); font-weight: 500;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.big { min-height: 56px; font-size: 17px; width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.danger { color: #a3202f; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.btn-grid .btn.big { grid-column: 1 / -1; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin: 8px 0; }
.item {
  display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; text-decoration: none; color: var(--ink);
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--bg); flex: none; }
.item input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--brand); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.badge.da_leggere { background: #fdf0dc; color: var(--warn); }
.badge.da_confermare { background: #fdf0dc; color: var(--warn); }
.badge.confermato { background: #e3f3ea; color: var(--ok); }
.badge.private { background: var(--soft); color: var(--brand); }

label { display: block; font-size: 14px; color: var(--ink-2); margin: 10px 0 4px; }
input[type=text], input[type=date], input[type=search], input:not([type]), textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px;
}
textarea { min-height: 44px; resize: vertical; overflow: hidden; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.field-grid .wide { grid-column: 1 / -1; }
@media (max-width: 560px) { .field-grid { grid-template-columns: 1fr; } }

.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-slot {
  aspect-ratio: 1.6; border: 1px dashed var(--line); border-radius: 10px; display: grid; place-items: center;
  background: var(--bg); overflow: hidden; color: var(--muted); font-size: 14px; cursor: pointer; position: relative;
}
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .tag { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; }

.private-box { border-color: #e6c9ce; background: #fffafb; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.notice { padding: 10px 12px; border-radius: 10px; background: #fdf0dc; color: #6b4507; font-size: 14px; margin: 10px 0; }
.notice.ok { background: #e3f3ea; color: #1f5a37; }
.suggest { border-left: 3px solid var(--brand); padding-left: 10px; margin: 8px 0; white-space: pre-wrap; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: var(--card); padding: 8px 12px; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--brand); color: #fff; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg); font-weight: 600; white-space: nowrap; }
td.pre { white-space: pre-wrap; min-width: 180px; }

.selbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30;
  background: #2b2b2e; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); font-size: 15px;
}
.toast.err { background: #a3202f; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.9); display: grid; place-items: center; }
.lightbox img { max-width: 100%; max-height: 100%; }

.login { max-width: 420px; margin: 12vh auto; padding: 24px 16px; text-align: center; }
.login-logo { width: 220px; max-width: 80%; }
.login form { text-align: left; margin-top: 16px; }
.login .btn { width: 100%; margin-top: 12px; }
.help h2 { margin-top: 24px; }
.help li { margin: 6px 0; }
.foot { margin-top: 32px; font-size: 13px; color: var(--muted); text-align: center; }
