/* =========================================================
   Campaign UI — design tokens
   ========================================================= */
:root {
  /* Surfaces */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #171a21;
  --ink-2: #3b4252;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;

  /* Brand */
  --brand: #1f4067;
  --brand-ink: #ffffff;
  --brand-hover: #17324f;

  /* Intent */
  --accent: #c5522c;
  --accent-hover: #a8451f;
  --success: #1f7a4d;
  --success-bg: #e6f3ec;
  --warning: #b45309;
  --warning-bg: #fdf2dc;
  --danger: #a82922;
  --danger-bg: #fbe9e7;

  /* Layout */
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 8px; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
p { margin: 0 0 8px; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* =========================================================
   Shell layout — sidebar + content
   ========================================================= */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink);
  color: #dbe0ea;
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 6px; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.brand strong { display: block; color: white; font-size: 15px; font-weight: 600; }
.brand small { display: block; color: #9aa3b2; font-size: 12px; margin-top: 2px; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: #c5cbd6;
  transition: background-color 0.12s, color 0.12s;
}
.nav-link .nav-label { display: block; font-weight: 600; font-size: 14px; }
.nav-link small { display: block; color: #7b8494; font-size: 12px; margin-top: 2px; }
.nav-link:hover { background: rgba(255, 255, 255, 0.05); color: white; }
.nav-link.is-active {
  background: rgba(255, 255, 255, 0.09);
  color: white;
}
.nav-link.is-active small { color: #9aa3b2; }

.logout-form { margin-top: auto; }
.ghost-button {
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  color: #9aa3b2;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.ghost-button:hover { background: rgba(255, 255, 255, 0.05); color: white; }

.content {
  padding: 28px 32px 60px;
  max-width: 1200px;
  width: 100%;
}

/* =========================================================
   Page head
   ========================================================= */
.page-head {
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; }
.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* =========================================================
   Panels
   ========================================================= */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.panel > h2:first-child { margin-top: 0; }
.hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

/* =========================================================
   Buttons
   ========================================================= */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s, border-color 0.12s;
  white-space: nowrap;
  min-height: 40px;
}
.button:hover { background: var(--surface-2); border-color: var(--ink-2); }
.button.primary { background: var(--brand); border-color: var(--brand); color: white; }
.button.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.button.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.button.danger:hover { background: var(--danger-bg); }
.button.subtle { border-color: transparent; background: transparent; color: var(--muted); }
.button.subtle:hover { background: var(--surface-2); color: var(--ink); }
.button.small { padding: 6px 10px; font-size: 13px; min-height: 32px; }

/* =========================================================
   Forms — filters + inline add
   ========================================================= */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}
.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filters label.grow { grid-column: span 2; }
.filters span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
}
.filters input, .filters select,
.add-fields input, .add-fields select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
}
.filters input:focus, .filters select:focus,
.add-fields input:focus, .add-fields select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 64, 103, 0.12);
}
.filter-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}
.filter-actions .button {
  width: 100%;
  height: 42px;
  min-height: 42px;
  padding-top: 0;
  padding-bottom: 0;
}

/* =========================================================
   Sezioni — list + action bar
   ========================================================= */
.sections-panel { padding: 0; overflow: hidden; }
.sections-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.select-all {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.select-all input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--brand); }
.sections-header .hint { margin: 6px 0 0 28px; }

.sections-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.section-row { border-bottom: 1px solid var(--line); }
.section-row:last-child { border-bottom: 0; }
.section-row-content {
  display: grid;
  grid-template-columns: auto 44px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 20px;
  transition: background-color 0.1s;
}
.section-row-content:hover { background: var(--surface-2); }
.section-row.is-assigned .section-row-content { background: rgba(31, 122, 77, 0.04); }
.section-row.is-assigned .section-row-content:hover { background: rgba(31, 122, 77, 0.08); }
.section-row input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--brand); }
.section-num {
  display: grid; place-items: center;
  width: 44px; height: 40px;
  border-radius: 8px;
  background: #eef1f6;
  color: var(--brand);
  font-weight: 700;
  font-size: 14px;
}
.section-row.is-assigned .section-num { background: var(--success-bg); color: var(--success); }
.section-meta strong { display: block; font-size: 14px; font-weight: 600; }
.section-meta small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.section-owner { text-align: right; font-size: 13px; }
.section-owner .owner-name { font-weight: 600; color: var(--ink-2); }
.section-owner small { display: block; color: var(--muted); margin-top: 2px; }
.assignment-pairs {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.assignment-card {
  display: inline-flex;
  align-items: stretch;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.assignment-stack {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.assignment-person {
  display: inline-grid;
  gap: 1px;
  min-width: 120px;
  padding: 5px 8px;
  border: 1px solid rgba(31, 64, 103, 0.16);
  border-radius: 8px;
  background: rgba(31, 64, 103, 0.04);
  text-align: left;
}
.assignment-person small {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.assignment-person strong { color: var(--brand); font-size: 12px; }
.assignment-person.delegated {
  border-color: rgba(31, 122, 77, 0.18);
  background: var(--success-bg);
}
.assignment-person.delegated strong { color: var(--success); }
.assignment-remove {
  display: grid;
  place-items: center;
  width: 28px;
  min-height: 100%;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
}
.assignment-remove:hover { background: var(--danger-bg); color: var(--danger); }
.remove-assignment-form { display: none; }

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

/* Action bar (fixed footer when items selected) */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 260px;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 0;
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  z-index: 10;
  box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.1);
}
.action-bar.visible { transform: translateY(0); }

/* Give the page breathing room so last rows aren't hidden by the fixed bar */
.sections-panel { padding-bottom: 0; }
body.has-action-bar { padding-bottom: 120px; }
.action-bar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  flex-wrap: wrap;
}
.action-bar-left { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.action-bar-left strong { font-size: 18px; color: var(--brand); }
.action-bar-right { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.action-bar-right select {
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  min-width: 180px;
  min-height: 40px;
}

/* =========================================================
   Empty-first-run (no referenti yet)
   ========================================================= */
.empty-first-run {
  text-align: center;
  padding: 40px 20px;
  background: var(--warning-bg);
  border-color: #f3dbb0;
}
.empty-first-run h2 { color: var(--warning); }
.empty-first-run .button { margin-top: 8px; }

/* =========================================================
   Referenti page
   ========================================================= */
.add-kind-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.radio-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.12s, background-color 0.12s;
}
.radio-card:has(input:checked) {
  border-color: var(--brand);
  background: rgba(31, 64, 103, 0.04);
}
.radio-card input[type="radio"] { accent-color: var(--brand); margin-top: 2px; }
.radio-card span { display: block; }
.radio-card strong { display: block; font-size: 14px; font-weight: 600; }
.radio-card small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.radio-card input:disabled + span { opacity: 0.4; }

.add-fields {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.add-fields label { display: flex; flex-direction: column; gap: 4px; }
.add-fields label span { font-size: 12px; font-weight: 600; color: var(--muted); }
.add-fields .grow { grid-column: auto; }
.add-fields .parent-field { grid-column: 1 / -1; }
.add-fields button { grid-column: -1 / auto; white-space: nowrap; }

.team-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.team-search {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  margin: 12px 0 16px;
}
.team-search label { display: grid; gap: 4px; }
.team-search label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.team-search input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
}
.team-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
}
.team-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.team-head strong { font-weight: 600; }
.team-head small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.team-stats { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.delete-person-form { display: inline-flex; }
.delete-person-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
}
.delete-person-button:hover { background: var(--danger-bg); color: var(--danger); }
.team-title-block { min-width: 0; }
.team-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.team-inline-sections { display: inline-flex; gap: 5px; flex-wrap: wrap; }
.team-sections {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.section-chip-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-right: 2px;
}
.section-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(31, 64, 103, 0.08);
  color: var(--brand);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}
.section-chip:hover { background: rgba(31, 64, 103, 0.14); }
.section-chip.total {
  background: rgba(197, 82, 44, 0.1);
  color: var(--accent);
}
.section-chip.total:hover { background: rgba(197, 82, 44, 0.16); }
.section-chip.delegated {
  background: var(--success-bg);
  color: var(--success);
}
.section-chip.delegated:hover { background: #d4ecdf; }
.section-chip.empty-chip {
  min-width: auto;
  background: #eef1f6;
  color: var(--muted);
  font-weight: 600;
}

.team-sub-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0 0 0 20px;
  border-left: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.team-sub-item {
  padding: 8px 0;
}
.team-sub-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.team-sections.delegated { margin-top: 8px; }

/* =========================================================
   Voters page
   ========================================================= */
.voters-panel { padding: 0; overflow: hidden; }
.voters-list { list-style: none; margin: 0; padding: 0; }
.voter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.voter-row:last-child { border-bottom: 0; }
.voter-row:hover { background: var(--surface-2); }
.voter-main strong { display: block; font-weight: 600; font-size: 14px; }
.voter-main small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.voter-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.voter-side .owner-name { font-weight: 600; font-size: 13px; color: var(--ink-2); }
.voter-assignments { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.voter-assignments .owner-name {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(31, 64, 103, 0.08);
  color: var(--brand);
}

/* =========================================================
   Tags & chips
   ========================================================= */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--success-bg);
  color: var(--success);
}
.tag-muted { background: #eef1f6; color: var(--ink-2); }

/* =========================================================
   Empty state
   ========================================================= */
.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

/* =========================================================
   Messages / alerts
   ========================================================= */
.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.message {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(31, 122, 77, 0.2);
}
.message.error { background: var(--danger-bg); color: var(--danger); border-color: rgba(168, 41, 34, 0.2); }
.message.warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(180, 83, 9, 0.2); }

/* =========================================================
   Pagination
   ========================================================= */
.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}
.pagination a {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 600;
}
.pagination a:hover { background: var(--line); }

/* =========================================================
   Login card (unchanged behavior, new look)
   ========================================================= */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 18px; background: var(--bg); }
.login-card {
  width: min(440px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 28px; margin-bottom: 8px; }
.login-card p { color: var(--muted); margin-bottom: 18px; }
.login-card label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card label input { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px; font: inherit; margin-top: 4px; min-height: 40px; }
.login-card button { width: 100%; }

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 20;
    height: auto; min-height: 0;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    flex-direction: row;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
  }
  .brand { flex: 0 0 auto; margin: 0; }
  .brand > div { display: none; }
  .brand-mark { width: 34px; height: 34px; font-size: 13px; }
  .sidebar nav {
    flex: 1 1 auto;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 4px;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 8px 12px; flex: 0 0 auto; }
  .nav-link small { display: none; }
  .nav-link .nav-label { font-size: 13px; }
  .logout-form { margin: 0; flex: 0 0 auto; }
  .ghost-button { padding: 8px 12px; width: auto; font-size: 13px; }
  .content { padding: 18px 16px 80px; }

  h1 { font-size: 22px; }

  .filters { grid-template-columns: 1fr; }
  .filters label.grow { grid-column: auto; }
  .filter-actions { flex-direction: column; }
  .filter-actions .button { width: 100%; }

  .section-row-content {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "check  meta"
      "check  owner";
    gap: 4px 12px;
    padding: 12px 16px;
  }
  .section-row input[type="checkbox"] { grid-area: check; align-self: center; }
  .section-num { display: none; }
  .section-meta { grid-area: meta; }
  .section-owner { grid-area: owner; text-align: left; }
  .assignment-pairs { justify-content: flex-start; }
  .assignment-stack { justify-content: flex-start; }
  .assignment-person { min-width: 0; }

  .action-bar { left: 0; }
  .action-bar-inner { flex-direction: column; align-items: stretch; gap: 8px; }
  .action-bar-right { flex-direction: column; margin-left: 0; }
  .action-bar-right select, .action-bar-right button { width: 100%; }

  .add-kind-row { grid-template-columns: 1fr; }
  .add-fields { grid-template-columns: 1fr; }
  .add-fields label, .add-fields .parent-field, .add-fields button { grid-column: auto; }
  .add-fields button { width: 100%; }
  .team-search { grid-template-columns: 1fr; }
  .team-search .button { width: 100%; }

  .voter-row { padding: 12px 16px; }
  .voter-side { width: 100%; justify-content: flex-start; }
}
