/* ============================================================
   Joni Family Dashboard — "מורשת" redesign
   Editorial, warm-heritage look. Frank Ruhl Libre + Assistant.
   Light = parchment & terracotta · Dark = espresso & amber.
   ============================================================ */

:root {
  color-scheme: light;

  --font-display: "Frank Ruhl Libre", "Times New Roman", serif;
  --font-body: "Assistant", "Noto Sans Hebrew", Arial, sans-serif;

  --bg: #f3eee4;
  --bg-glow-1: rgba(179, 80, 46, 0.07);
  --bg-glow-2: rgba(78, 110, 90, 0.08);
  --surface: #fdfbf5;
  --surface-2: #f5efe3;
  --surface-3: #efe7d7;
  --border: #e2d8c5;
  --border-strong: #cdbfa4;
  --text: #2b2118;
  --muted: #8b7c67;
  --heading: #241b12;

  --accent: #b3502e;
  --accent-strong: #8f3d1f;
  --accent-soft: #f4e0d5;
  --accent-contrast: #fff;

  --green: #4e6e5a;
  --green-soft: #e3ebe2;
  --gold: #a67b24;
  --gold-soft: #f3e7cb;
  --blue: #4a6b8a;
  --blue-soft: #e0e8ee;
  --purple: #7d5ba6;
  --purple-soft: #eae3f2;
  --danger: #a63a2e;
  --danger-soft: #f7ded7;
  --danger-border: #e6bcae;

  --shadow: 0 18px 40px rgba(67, 48, 27, 0.1);
  --shadow-soft: 0 8px 22px rgba(67, 48, 27, 0.07);
  --radius: 16px;
  --radius-sm: 10px;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1a1510;
  --bg-glow-1: rgba(217, 126, 82, 0.09);
  --bg-glow-2: rgba(143, 181, 154, 0.06);
  --surface: #261f17;
  --surface-2: #2f271d;
  --surface-3: #382f23;
  --border: #3e3527;
  --border-strong: #554833;
  --text: #efe5d4;
  --muted: #a3937b;
  --heading: #f6ecdb;

  --accent: #d97e52;
  --accent-strong: #e89468;
  --accent-soft: #3d2a1d;
  --accent-contrast: #1a1510;

  --green: #8fb59a;
  --green-soft: #283227;
  --gold: #d9b05f;
  --gold-soft: #3a3120;
  --blue: #8aa9c4;
  --blue-soft: #263039;
  --purple: #ab8fd1;
  --purple-soft: #322a3d;
  --danger: #e0785f;
  --danger-soft: #3e241c;
  --danger-border: #5b3527;

  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 8px 22px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 85% -80px, var(--bg-glow-1), transparent 70%),
    radial-gradient(720px 380px at 8% -60px, var(--bg-glow-2), transparent 70%),
    var(--bg);
  transition: background 0.35s ease, color 0.35s ease;
}

h1, h2, h3,
.stat-value,
.pie-total {
  font-family: var(--font-display);
  color: var(--heading);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

a:hover {
  color: var(--accent-strong);
}

::selection {
  background: var(--accent-soft);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 8px;
  background: var(--border-strong);
  background-clip: content-box;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Shell & top bar ---------- */

.app-shell {
  min-height: 100vh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 30px clamp(16px, 3vw, 40px) 60px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h1,
.empty-state h1 {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 40px);
  font-weight: 900;
  line-height: 1.1;
}

.topbar h1::after {
  content: "";
  display: block;
  width: 54px;
  height: 4px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.topbar p,
.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(320px, 32vw);
  min-width: 210px;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: border-color 0.2s ease;
}

.searchbox:focus-within {
  border-color: var(--accent);
}

.searchbox span {
  color: var(--muted);
}

.searchbox input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(179, 80, 46, 0.32);
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.secondary-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

.text-button,
.link-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  min-height: 42px;
  padding: 0 8px;
  border-radius: 8px;
}

.text-button:hover,
.link-button:hover {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button {
  display: block;
  margin: 14px auto 0;
}

.session-pill,
.role-pill {
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  min-height: 36px;
  padding: 4px 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-pill.super {
  border-color: var(--purple);
  background: var(--purple-soft);
  color: var(--purple);
}

/* ---------- Clock strip ---------- */

.clock-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.clock-strip span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.clock-time {
  min-width: 88px;
  justify-content: center;
  direction: ltr;
  font-variant-numeric: tabular-nums;
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: var(--accent-contrast) !important;
}

.clock-hebrew {
  border-color: var(--gold-soft) !important;
  background: var(--gold-soft) !important;
  color: var(--gold) !important;
}

/* ---------- Stats ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card,
.panel,
.person-drawer,
.settings-modal,
.empty-state,
.template-card,
.community-card,
.empty-directory,
.auth-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: background 0.35s ease, border-color 0.35s ease;
}

.stat-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 94px;
  padding: 16px 18px;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 14px;
  bottom: 14px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
  opacity: 0.85;
}

.stat-card.branches::before { background: var(--green); }
.stat-card.events::before { background: var(--gold); }
.stat-card.mail::before { background: var(--blue); }
.stat-card.issues::before { background: var(--danger); }
.stat-card.admin::before { background: var(--purple); }

.stat-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
}

.stat-card.branches .stat-icon { background: var(--green-soft); color: var(--green); }
.stat-card.events .stat-icon { background: var(--gold-soft); color: var(--gold); }
.stat-card.mail .stat-icon { background: var(--blue-soft); color: var(--blue); }
.stat-card.issues .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat-card.admin .stat-icon { background: var(--purple-soft); color: var(--purple); }

.stat-value {
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}

.stat-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13.5px;
}

/* ---------- Tabs ---------- */

.tabs-nav {
  display: flex;
  gap: 2px;
  max-width: 100%;
  margin-bottom: 22px;
  padding: 0 4px;
  overflow-x: auto;
  border-bottom: 2px solid var(--border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tabs-nav button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.tabs-nav button::after {
  content: "";
  position: absolute;
  inset-inline: 12px;
  bottom: -2px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.22s ease;
}

.tabs-nav button:hover {
  color: var(--heading);
}

.tabs-nav button.active {
  color: var(--accent);
}

.tabs-nav button.active::after {
  transform: scaleX(1);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 800;
}

/* ---------- Layout ---------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 20px;
  align-items: start;
}

.dashboard-grid.single {
  grid-template-columns: 1fr;
}

.main-column {
  display: grid;
  gap: 20px;
}

.main-column > *,
.stats-grid > * {
  animation: rise 0.55s cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
}

.stats-grid > *:nth-child(2) { animation-delay: 0.04s; }
.stats-grid > *:nth-child(3) { animation-delay: 0.08s; }
.stats-grid > *:nth-child(4) { animation-delay: 0.12s; }
.stats-grid > *:nth-child(5) { animation-delay: 0.16s; }
.stats-grid > *:nth-child(6) { animation-delay: 0.2s; }
.main-column > *:nth-child(2) { animation-delay: 0.07s; }
.main-column > *:nth-child(3) { animation-delay: 0.14s; }
.main-column > *:nth-child(4) { animation-delay: 0.21s; }
.main-column > *:nth-child(5) { animation-delay: 0.28s; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .main-column > *,
  .stats-grid > * {
    animation: none;
  }
}

.panel {
  padding: 22px;
}

.panel h2,
.settings-modal h2,
.person-drawer h2 {
  margin: 0 0 14px;
  font-size: 21px;
  font-weight: 700;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 13.5px;
}

/* ---------- Bar list (legacy) ---------- */

.bar-list {
  display: grid;
  gap: 11px;
}

.bar-row {
  display: grid;
  grid-template-columns: 78px minmax(80px, 1fr) 34px;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 5px;
  background: var(--surface-3);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

/* ---------- Pie charts ---------- */

.pies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.pie-layout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
}

.pie-svg {
  flex: none;
  width: 150px;
  height: 150px;
  filter: drop-shadow(0 6px 14px rgba(67, 48, 27, 0.16));
}

html[data-theme="dark"] .pie-svg {
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.4));
}

.pie-slice {
  stroke: var(--surface);
  stroke-width: 2;
  transition: opacity 0.15s ease;
}

.pie-slice.clickable {
  cursor: pointer;
}

.pie-slice.clickable:hover {
  opacity: 0.8;
}

.pie-hole {
  fill: var(--surface);
}

.pie-total {
  font-size: 21px;
  font-weight: 900;
  fill: var(--heading);
}

.pie-center-label {
  font-family: var(--font-body);
  font-size: 8.5px;
  fill: var(--muted);
}

.pie-legend {
  display: grid;
  flex: 1;
  min-width: 130px;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pie-legend li {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
}

.pie-legend li.clickable {
  cursor: pointer;
}

.pie-legend li.clickable:hover .legend-label {
  color: var(--accent);
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.legend-label {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-legend strong {
  font-weight: 800;
}

.pie-legend small {
  min-width: 36px;
  color: var(--muted);
  text-align: left;
}

/* ---------- Upcoming events ---------- */

.upcoming-list {
  display: grid;
  gap: 10px;
}

.upcoming-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.upcoming-days {
  display: grid;
  place-items: center;
  gap: 0;
  width: 58px;
  min-height: 58px;
  padding: 6px 4px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  text-align: center;
}

.upcoming-days strong {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.upcoming-days small {
  font-size: 11px;
  font-weight: 700;
}

.upcoming-days.today {
  background: var(--accent);
  color: var(--accent-contrast);
}

.upcoming-item h3 {
  margin: 0;
  font-size: 16px;
}

.upcoming-item p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.upcoming-empty {
  margin: 0;
  color: var(--muted);
}

.upcoming-date-filter {
  margin-bottom: 12px;
}

.upcoming-date-filter button {
  min-height: 32px;
  font-size: 13px;
}

/* ---------- Quality strip (overview) ---------- */

.quality-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
}

.quality-strip.ok {
  border-color: var(--green);
  background: var(--green-soft);
}

.quality-strip.bad {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.quality-strip strong {
  font-family: var(--font-display);
  font-size: 20px;
}

.quality-strip.ok strong { color: var(--green); }
.quality-strip.bad strong { color: var(--danger); }

.quality-strip p {
  flex: 1;
  min-width: 180px;
  margin: 0;
  color: var(--text);
}

/* ---------- Tables ---------- */

.table-panel {
  padding-bottom: 12px;
}

.table-scroll {
  overflow: auto;
  max-height: 540px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  text-transform: none;
}

td strong {
  display: block;
  margin-bottom: 2px;
}

td small {
  color: var(--muted);
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: var(--surface-2);
}

tbody tr.selected {
  box-shadow: inset 3px 0 0 var(--accent);
}

/* ---------- Timeline / events ---------- */

.timeline {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-inline-start: 2px;
}

.event-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 14px;
}

.event-filter button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  transition: all 0.15s ease;
}

.event-filter button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.event-filter button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.timeline-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.timeline-date {
  display: grid;
  gap: 3px;
}

.timeline-date strong {
  font-variant-numeric: tabular-nums;
}

.timeline-date span,
.timeline-item p,
.branch-card small,
.issue span {
  color: var(--muted);
  font-size: 13px;
}

.timeline-item h3,
.branch-card h3 {
  margin: 0;
  font-size: 16px;
}

.timeline-item p {
  margin: 3px 0 0;
}

.tag {
  min-width: 88px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tag.birthday {
  background: var(--blue-soft);
  color: var(--blue);
}

.tag.anniversary {
  background: var(--gold-soft);
  color: var(--gold);
}

/* ---------- Communication ---------- */

.communication-panel {
  display: grid;
  gap: 14px;
}

.communication-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.communication-summary article {
  display: grid;
  gap: 2px;
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.communication-summary strong {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 800;
}

.communication-summary span {
  color: var(--muted);
  font-size: 13px;
}

.communication-table {
  max-height: 430px;
}

.ready-pill,
.missing-pill,
.minor-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.ready-pill {
  background: var(--green-soft);
  color: var(--green);
}

.missing-pill {
  background: var(--gold-soft);
  color: var(--gold);
}

.minor-pill {
  background: var(--surface-3);
  color: var(--muted);
}

/* ---------- Message preview ---------- */

.message-preview-panel {
  display: grid;
  gap: 14px;
}

.message-preview-panel .panel-title-row p {
  margin: 4px 0 0;
  color: var(--muted);
}

.preview-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-controls label,
.relationship-filter {
  margin-bottom: 0;
}

.preview-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.queue-result {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--green);
}

.relationship-filter {
  max-width: 320px;
}

.preview-table {
  max-height: 520px;
}

.message-cell {
  min-width: 300px;
  max-width: 520px;
  line-height: 1.5;
  white-space: normal;
}

/* ---------- Branches ---------- */

.branch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.branch-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.branch-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.branch-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.branch-card p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
}

.branch-open {
  justify-self: start;
  min-height: 38px;
}

.branch-menu-button {
  white-space: nowrap;
}

.marriage-badge,
.marriage-years {
  color: var(--gold);
  font-weight: 800;
}

.marriage-badge {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  font-size: 13px;
}

.marriage-years {
  margin-top: 5px;
}

.branch-detail {
  display: grid;
  gap: 16px;
}

.branch-detail .panel-title-row h2 {
  margin-bottom: 2px;
}

.branch-detail .panel-title-row p,
.muted {
  margin: 0;
  color: var(--muted);
}

.branch-family-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}

.branch-family-grid h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.mini-person-list,
.child-family-list {
  display: grid;
  gap: 10px;
}

.mini-person-list button,
.child-family-card {
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: right;
}

.mini-person-list button {
  display: grid;
  gap: 3px;
  transition: border-color 0.15s ease;
}

.mini-person-list button:hover {
  border-color: var(--accent);
}

.mini-person-list span,
.child-family-card span,
.child-family-card p {
  color: var(--muted);
  font-size: 13px;
}

.child-family-card {
  display: grid;
  gap: 8px;
}

.child-family-card p {
  margin: 0;
}

.child-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.branch-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.branch-chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  transition: all 0.15s ease;
}

.branch-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ---------- Issues (legacy) ---------- */

.issue-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
}

.issue {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
}

.issue div {
  display: grid;
  gap: 2px;
}

/* ---------- Data quality ---------- */

.quality-panel {
  display: grid;
  gap: 14px;
}

.quality-note {
  margin: -6px 0 0;
  line-height: 1.5;
}

.quality-summary {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quality-summary .quality-ok {
  border-color: var(--green);
  background: var(--green-soft);
}

.quality-summary .quality-ok strong {
  color: var(--green);
}

.quality-summary .quality-bad {
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.quality-summary .quality-bad strong {
  color: var(--danger);
}

.quality-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.quality-issue {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
}

.quality-issue-head {
  display: grid;
  gap: 2px;
}

.quality-issue-head strong {
  color: var(--danger);
}

.quality-issue-head small {
  color: var(--muted);
}

.missing-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.missing-fields span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.quality-issue .text-button {
  justify-self: start;
  min-height: 34px;
}

.quality-all-good {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
}

/* ---------- Person drawer ---------- */

.person-drawer {
  position: sticky;
  top: 18px;
  min-height: 420px;
  padding: 22px;
}

.person-drawer.empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.drawer-head h2 {
  margin-bottom: 0;
}

.person-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.person-meta span,
.relationship-list span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

.drawer-section {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.drawer-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--muted);
}

.drawer-section p {
  margin: 4px 0;
}

.relationship-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.channel-link {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.channel-link:hover {
  text-decoration: underline;
}

.whatsapp-link {
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
}

.whatsapp-link:hover {
  text-decoration: underline;
}

.primary-channel-pill {
  display: inline-flex;
  align-items: center;
  margin-inline-start: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

/* ---------- Telegram invite ---------- */

.telegram-invite-box {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.invite-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.invite-title-row h3 {
  margin: 0;
}

.invite-title-row span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.telegram-invite-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.primary-button.wide,
.wide {
  width: 100%;
}

.invite-result {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.invite-result small {
  color: var(--muted);
}

.invite-link {
  display: block;
  direction: ltr;
  padding: 10px;
  border-radius: 8px;
  background: var(--heading);
  color: var(--bg);
  font-size: 14px;
  font-weight: 800;
  text-align: left;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.invite-link:hover {
  opacity: 0.9;
  color: var(--bg);
}

/* ---------- Directory ---------- */

.directory-shell {
  display: grid;
  gap: 18px;
}

.directory-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}

.directory-head h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
}

.directory-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.template-grid,
.community-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.template-card {
  display: grid;
  gap: 10px;
  min-height: 190px;
  padding: 20px;
  color: var(--text);
  text-align: right;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.template-card:hover,
.community-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-3px);
}

.template-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px;
}

.template-card strong {
  font-family: var(--font-display);
  font-size: 22px;
}

.template-card > span:not(.template-icon) {
  color: var(--muted);
}

.template-metrics,
.community-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: auto;
}

.template-metrics span,
.community-metrics span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.community-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.community-card h2 {
  margin: 0 0 4px;
  font-size: 21px;
}

.community-card p {
  margin: 0;
  color: var(--muted);
  direction: ltr;
  text-align: right;
}

.community-card .primary-button {
  justify-self: start;
  min-width: 108px;
}

.community-metrics strong {
  margin-inline-start: 4px;
}

.empty-directory {
  padding: 28px;
  text-align: center;
}

.empty-directory h2 {
  margin: 0 0 8px;
}

.empty-directory p {
  margin: 0;
  color: var(--muted);
}

.back-button {
  white-space: nowrap;
}

/* ---------- Forms & modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 16, 8, 0.5);
  backdrop-filter: blur(3px);
}

.settings-modal {
  width: min(620px, 100%);
  padding: 24px;
  box-shadow: var(--shadow);
}

.edit-modal {
  width: min(820px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: var(--text);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  margin-bottom: 0;
}

.form-section-title {
  margin: 18px 0 12px;
  font-size: 17px;
}

.preferred-channel-field {
  max-width: 380px;
}

.preferred-channel-field small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-top: 18px;
}

input,
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: 0;
  background: var(--surface);
  color: var(--text);
  direction: ltr;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------- Banners & auth ---------- */

.error-banner {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
}

.success-banner {
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  background: var(--green-soft);
  color: var(--green);
}

.auth-warning {
  margin-bottom: 14px;
  padding: 11px 12px;
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--gold);
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: calc(100vh - 56px);
  margin: 28px;
  padding: 28px;
  text-align: center;
}

.empty-state p {
  max-width: 560px;
  margin-bottom: 20px;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
}

.auth-card {
  width: min(460px, 100%);
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 900;
}

.auth-card h1 {
  margin: 0;
  font-size: 26px;
}

.auth-card p {
  margin: 8px 0 18px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.compact {
  margin: 0 0 12px;
}

.spin {
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .branch-family-grid {
    grid-template-columns: 1fr;
  }

  .person-drawer {
    position: static;
  }
}

/* ---------- Building dashboard ---------- */

.building-shell {
  --accent: #315f58;
  --accent-strong: #234943;
  --accent-soft: #dcebe7;
}

.building-main {
  display: grid;
  gap: 24px;
}

.building-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.building-welcome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--surface), var(--green-soft));
  box-shadow: var(--shadow-soft);
}

.building-welcome h2,
.building-welcome p {
  margin: 4px 0;
}

.building-welcome p {
  color: var(--muted);
}

.eyebrow {
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.building-floors {
  display: grid;
  gap: 26px;
}

.floor-section {
  display: grid;
  gap: 14px;
}

.floor-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 0 4px;
}

.floor-heading h2 {
  margin: 0;
  font-size: 24px;
}

.floor-heading span {
  color: var(--muted);
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.unit-card {
  display: flex;
  min-height: 230px;
  flex-direction: column;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.unit-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.unit-card-head h3 {
  margin: 0;
  font-size: 20px;
}

.unit-card-head > div > span {
  color: var(--muted);
  font-size: 13px;
}

.resident-count,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.resident-list {
  display: grid;
  gap: 12px;
  padding: 16px 0;
}

.resident-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.resident-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.resident-main {
  display: grid;
  min-width: 0;
}

.resident-main span,
.resident-contact {
  color: var(--muted);
  font-size: 13px;
}

.resident-contact a {
  overflow-wrap: anywhere;
}

.add-resident-button {
  width: 100%;
  min-height: 40px;
  margin-top: auto;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.add-resident-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.coming-soon {
  min-height: 300px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.coming-soon h2,
.coming-soon p {
  margin: 5px 0;
}

.coming-soon p {
  max-width: 560px;
  color: var(--muted);
}

.coming-icon {
  color: var(--accent);
  font-size: 44px;
}

.resident-modal {
  width: min(620px, calc(100vw - 32px));
}

.check-label {
  display: flex !important;
  grid-template-columns: auto 1fr !important;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.check-label input {
  width: 18px;
  height: 18px;
}

.auth-footnote {
  display: block;
  margin-top: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .unit-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .building-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .unit-grid,
  .building-stats {
    grid-template-columns: 1fr;
  }

  .building-welcome {
    align-items: stretch;
    flex-direction: column;
    padding: 22px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px 14px 40px;
  }

  .topbar,
  .directory-head {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .searchbox {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    min-height: 76px;
    padding: 12px 14px;
  }

  .stat-value {
    font-size: 26px;
  }

  .split-grid,
  .form-grid,
  .communication-summary,
  .preview-controls,
  .preview-summary,
  .pies-grid,
  .quality-summary,
  .quality-list {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 1fr;
  }

  .pie-layout {
    justify-content: center;
  }

  .tabs-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
  }

  .panel {
    padding: 16px;
  }
}
