/* Light, warm, modern healthcare-inspired redesign */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg: #faf8f6;
  --surface: #ffffff;
  --surface2: #f5f2f0;
  --border: #e8e4e0;
  --accent: #1e8a77;
  --accent2: #5a9d8d;
  --danger: #c13030;
  --warn: #d06a2e;
  --text: #161210;
  --muted: #857f79;
  --sq-a: #2e6db5;
  --sq-b: #a34d84;
  --sq-c: #27924d;

  /* Typography Scale (1.25x modular ratio) */
  --text-xs: 0.8rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.125rem;
  --text-lg: 1.5rem;
  --text-xl: 2rem;

  /* Line Heights */
  --lh-tight: 1.1;
  --lh-snug: 1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.6;
  --lh-loose: 1.8;

  /* Font Weights */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Spacing Scale (8px base) */
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 2.5rem;
  --space-3xl: 3rem;

  /* Z-Index Scale */
  --z-hidden: -1;
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 900;
  --z-modal: 1000;
  --z-toast: 600;
  --z-tooltip: 700;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: var(--lh-normal);
  font-size: var(--text-base);
  font-weight: var(--fw-regular);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05)
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: auto;
  gap: 1rem;
  flex-wrap: wrap;
  overflow: visible
}

@media (min-width: 640px) {
  header {
    padding: 1rem 1.5rem
  }
}

/* Sync button animation */
@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

#sync-btn {
  font-size: .75rem;
  color: var(--accent2);
  background: none;
  border: 1px solid var(--accent2);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
  white-space: nowrap;
  font-family: 'Poppins', sans-serif;
}

#sync-btn .sync-icon {
  display: inline-block;
  margin-right: 0.25rem;
}

#sync-btn.loading {
  opacity: 0.7;
  cursor: not-allowed;
  pointer-events: none;
}

#sync-btn.loading .sync-icon {
  animation: spin 0.8s linear infinite;
}

/* Remote changes were just pulled in — blink a few times to draw the eye. */
#sync-btn.updated {
  color: var(--accent);
  border-color: var(--accent);
  animation: sync-pulse 0.6s ease-in-out 0s 3;
}

@keyframes sync-pulse {

  0%,
  100% {
    background: transparent;
  }

  50% {
    background: rgba(30, 138, 119, 0.30);
  }
}

/* A sync request failed — the app may be showing stale data. */
#sync-btn.offline {
  color: var(--warn);
  background: rgba(208, 106, 46, 0.14);
  border-color: var(--warn);
}

@media (prefers-reduced-motion: reduce) {
  #sync-btn.updated {
    animation: none;
    background: rgba(30, 138, 119, 0.22);
  }

  #sync-btn.loading .sync-icon {
    animation: none;
  }
}

.logo {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.05em;
  color: var(--text);
  text-decoration: none;
  flex: 0 0 auto
}

@media (min-width: 640px) {
  .logo {
    font-size: 1.5rem
  }
}

.logo span {
  color: var(--accent);
  font-weight: 800
}

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 1rem;
  overflow-x: auto;
  gap: 0.25rem;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth
}

@media (min-width: 640px) {
  nav {
    padding: 0 1.5rem;
    gap: 0.5rem
  }
}

nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Poppins', sans-serif;
  font-weight: var(--fw-medium);
  font-size: var(--text-xs);
  text-transform: none;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
  border-radius: 4px 4px 0 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  -webkit-user-select: none;
  user-select: none;
  line-height: var(--lh-tight)
}

@media (min-width: 640px) {
  nav button {
    font-size: var(--text-sm);
    padding: 0.75rem 1rem
  }
}

nav button.active {
  color: var(--surface);
  border-bottom-color: transparent;
  background: var(--accent);
  border-radius: 6px 6px 0 0
}

nav button:hover:not(.active) {
  color: var(--text);
  background: rgba(0, 0, 0, 0.04)
}

nav button:active {
  transform: scale(0.95)
}

main {
  padding: var(--space-md);
  max-width: 1400px;
  margin: 0 auto
}

@media (max-width: 640px) {
  main {
    padding: var(--space-sm)
  }
}

@media (min-width: 1024px) {
  main {
    padding: var(--space-xl)
  }
}

.page {
  display: none
}

.page.active {
  display: block
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-lg);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s;
  margin-bottom: var(--space-lg)
}

.card:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1)
}

@media (min-width: 640px) {
  .card {
    padding: var(--space-xl)
  }
}

.card-title {
  font-family: 'Poppins', sans-serif;
  font-weight: 700;
  font-size: var(--text-base);
  text-transform: none;
  color: var(--text);
  margin-bottom: 1.2rem;
  letter-spacing: -0.02em;
  line-height: var(--lh-snug)
}

.shift-banner {
  border-radius: 14px;
  padding: var(--space-xl) var(--space-2xl);
  margin-bottom: var(--space-2xl);
  border: none;
  border-left: 6px solid;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.2s
}

.shift-banner:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.13);
  transform: translateY(-2px)
}

.sb-a {
  border-color: var(--sq-a);
  background: rgba(46, 109, 181, 0.08)
}

.sb-b {
  border-color: var(--sq-b);
  background: rgba(163, 77, 132, 0.08)
}

.sb-c {
  border-color: var(--sq-c);
  background: rgba(39, 146, 77, 0.08)
}

.banner-title {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1;
  letter-spacing: -0.04em
}

.sb-a .banner-title {
  color: var(--sq-a)
}

.sb-b .banner-title {
  color: var(--sq-b)
}

.sb-c .banner-title {
  color: var(--sq-c)
}

.banner-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.3rem
}

/* Low-prominence chip on the on-duty banner: signals that an alternante
   colleague is covering this week. Demoted from the old full-width alert —
   the per-card badges already flag it per slot. */
/* Colors mirror the per-card status pills (.p-alt/.p-ext/.p-ok/.p-crit) so the
   banner chip reads as the same signal. Default tone = alternante (blue). */
.banner-badge {
  align-self: center;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  white-space: nowrap
}

.banner-badge.bb-ok {
  background: #16a34a
}

.banner-badge.bb-ext {
  background: #d97706
}

.banner-badge.bb-crit {
  background: #dc2626
}

.roster-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-3xl)
}

@media (min-width: 640px) {
  .roster-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg)
  }
}

@media (min-width: 1024px) {
  .roster-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg)
  }
}

.roster-day-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  width: 100%;
  margin-bottom: var(--space-3xl)
}

@media (min-width: 640px) {
  .roster-day-grid {
    grid-template-columns: repeat(3, 1fr)
  }
}

@media (min-width: 1024px) {
  .roster-day-grid {
    grid-template-columns: repeat(5, 1fr)
  }
}

.day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
  transition: box-shadow 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm)
}

.day-card:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, .1);
  transform: translateY(-2px)
}

.day-card-past {
  opacity: .6
}

/* Mobile-only control: hidden on desktop, revealed at the mobile breakpoint */
.mobile-only {
  display: none
}

@media (max-width: 640px) {
  .mobile-only {
    display: inline-flex
  }

  /* On mobile, past days are hidden so the today card surfaces first.
     The toggle adds .show-past to #d-roster to reveal them again. */
  #d-roster:not(.show-past) .day-card-past {
    display: none
  }
}

.day-card.dc-ok {
  border-top: 4px solid #16a34a
}

.day-card.dc-alt {
  border-top: 4px solid #2563eb
}

.day-card.dc-ext {
  border-top: 4px solid #d97706
}

.day-card.dc-crit {
  border-top: 4px solid #dc2626
}

.day-card-today {
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18)
}

.day-card-today .day-card-name {
  font-weight: var(--fw-bold);
  text-decoration: underline
}

.day-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px
}

.day-card-name {
  font-weight: var(--fw-bold);
  font-size: var(--text-sm)
}

.day-card-date {
  font-size: var(--text-xs);
  color: var(--muted)
}

.day-role-row {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border)
}

.day-role-row:last-child {
  border-bottom: none;
  padding-bottom: 0
}

.day-role-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px
}

.day-role-label {
  font-size: var(--text-xs);
  color: var(--muted)
}

.day-role-name {
  font-weight: var(--fw-medium);
  margin-bottom: 1px
}

.day-role-phone {
  font-size: .7rem;
  color: var(--muted);
  margin-bottom: 2px
}

.day-role-phone a {
  color: inherit;
  text-decoration: none
}

.day-role-phone a:hover {
  text-decoration: underline
}

.day-role-meta {
  font-size: .7rem;
  color: var(--muted);
  margin-bottom: 3px
}

.pill-chain {
  position: relative;
  display: inline-block;
  margin-top: 3px;
  z-index: 1
}

.pill-chain[open] {
  z-index: 1000
}

.day-card:has(.pill-chain[open]) {
  position: relative;
  z-index: 1000
}

.pill-chain>summary {
  list-style: none;
  cursor: pointer
}

.pill-chain>summary::-webkit-details-marker {
  display: none
}

.pill-chain-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--space-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .15);
  min-width: 220px;
  white-space: nowrap
}

.roster-slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.2s
}

.roster-slot:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px)
}

@media (min-width: 640px) {
  .roster-slot {
    padding: var(--space-xl)
  }
}

.slot-label {
  font-size: var(--text-xs);
  text-transform: none;
  color: var(--muted);
  margin-bottom: 0.75rem;
  font-weight: var(--fw-medium);
  line-height: var(--lh-tight)
}

.slot-name {
  font-family: 'Poppins', sans-serif;
  font-weight: var(--fw-bold);
  font-size: var(--text-sm);
  margin-bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--accent);
  gap: var(--space-sm);
  flex-wrap: wrap;
  line-height: var(--lh-snug)
}

@media (min-width: 640px) {
  .slot-name {
    font-size: var(--text-base)
  }
}

.slot-phone a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  min-height: 44px;
  display: flex;
  align-items: center
}

@media (min-width: 640px) {
  .slot-phone a {
    font-size: 0.85rem
  }
}

.slot-phone a:hover {
  text-decoration: underline
}

.card-actions {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.card-actions summary {
  list-style: none;
  cursor: pointer;
  font-size: .72rem;
  color: var(--muted);
  padding: .15rem .4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  line-height: 1;
  user-select: none;
  font-weight: 600;
}

.card-actions summary::-webkit-details-marker {
  display: none;
}

.card-actions summary:hover {
  color: var(--text);
  border-color: var(--accent);
}

.card-actions[open] summary {
  color: var(--accent);
  border-color: var(--accent);
}

/* Lift the whole card above its siblings while the action menu is open, mirroring
   the .pill-chain[open] pattern — otherwise a sibling card that forms a stacking
   context (open pill-chain at z-index:1000, or a hovered card's transform) paints
   over the popover. */
.card-actions[open] {
  z-index: 1001;
}

.day-card:has(.card-actions[open]) {
  position: relative;
  z-index: 1001;
}

.card-popover {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: auto;
  z-index: 1001;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  min-width: 150px;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-popover-title {
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--text);
  padding: 2px 2px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px
}

.card-actions-disabled {
  opacity: .38;
  pointer-events: none;
}

.slot-from {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.5rem
}

@media (min-width: 640px) {
  .slot-from {
    font-size: 0.8rem
  }
}

.pill {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  text-transform: none;
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  line-height: var(--lh-tight)
}

@media (min-width: 640px) {
  .pill {
    font-size: var(--text-sm);
    padding: 0.25rem 0.75rem
  }
}

.p-ok {
  background: #16a34a;
  color: #fff;
  font-weight: var(--fw-semibold);
  box-shadow: 0 1px 6px rgba(22, 163, 74, 0.35)
}

.p-alt {
  background: #2563eb;
  color: #fff;
  font-weight: var(--fw-semibold);
  box-shadow: 0 1px 6px rgba(37, 99, 235, 0.35)
}

.p-ext {
  background: #d97706;
  color: #fff;
  font-weight: var(--fw-semibold);
  box-shadow: 0 1px 6px rgba(217, 119, 6, 0.35)
}

.p-crit {
  background: #dc2626;
  color: #fff;
  font-weight: var(--fw-bold);
  box-shadow: 0 1px 6px rgba(220, 38, 38, 0.4)
}

.p-off {
  background: rgba(139, 134, 128, 0.2);
  color: #4a4440;
  font-weight: var(--fw-semibold)
}

.chain {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  font-size: 0.8rem
}

.chain-title {
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 600
}

.chain-row {
  display: grid;
  grid-template-columns: 1.2em 1fr auto;
  align-items: baseline;
  column-gap: 0.4em;
  margin-top: 0.3rem;
  line-height: 1.4
}

.cr-icon {
  text-align: center
}

.cr-label {
  color: var(--muted);
  font-size: 0.75em;
  white-space: nowrap
}

.cr-ok {
  color: var(--accent2)
}

.cr-alt {
  color: var(--accent)
}

.cr-ext {
  color: var(--sq-a)
}

.cr-no {
  color: var(--danger);
  opacity: .55
}

.cr-skip {
  color: var(--muted);
  opacity: .45
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-3xl)
}

@media (min-width: 640px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg)
  }
}

@media (min-width: 1024px) {
  .stats-row {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg)
  }
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden
}

@media (min-width: 640px) {
  .stat-box {
    padding: var(--space-xl)
  }
}

.stat-val {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: clamp(2.2rem, 5vw, 3rem);
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--text)
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: none;
  margin-top: 0.6rem;
  font-weight: var(--fw-medium);
  line-height: var(--lh-tight)
}

@media (min-width: 640px) {
  .stat-label {
    font-size: var(--text-sm)
  }
}

.btn {
  font-family: 'Poppins', sans-serif;
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  border: 1px solid;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  line-height: var(--lh-tight)
}

@media (max-width: 640px) {
  .btn {
    font-size: var(--text-xs);
    padding: 0.65rem 1rem
  }
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: var(--fw-bold);
  letter-spacing: 0.01em;
  box-shadow: 0 3px 12px rgba(30, 138, 119, 0.35)
}

.btn-primary:hover {
  background: #177a6a;
  border-color: #177a6a;
  box-shadow: 0 6px 20px rgba(30, 138, 119, 0.45);
  transform: translateY(-2px)
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(30, 138, 119, 0.25)
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  transition: all 0.2s
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(90, 157, 142, 0.08);
  box-shadow: 0 2px 8px rgba(90, 157, 142, 0.1)
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
  border-width: 2px;
  font-weight: var(--fw-semibold)
}

.btn-danger:hover {
  background: rgba(199, 66, 66, 0.15);
  box-shadow: 0 2px 8px rgba(199, 66, 66, 0.2)
}

.btn-success {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #ffffff;
  font-weight: var(--fw-bold);
  box-shadow: 0 2px 8px rgba(143, 176, 157, 0.25)
}

.btn-success:hover {
  background: #7fa491;
  box-shadow: 0 4px 12px rgba(143, 176, 157, 0.35);
  transform: translateY(-1px)
}

.btn-tg {
  background: #0088cc;
  border-color: #0088cc;
  color: #ffffff
}

.btn-tg:hover {
  background: #006daa;
  box-shadow: 0 2px 6px rgba(0, 136, 204, 0.3)
}

.btn-tg:disabled {
  opacity: .6;
  cursor: not-allowed;
  pointer-events: none
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: var(--text-xs)
}

/* Square icon-only button: equal padding + 1:1 ratio so it never wraps and
   stays inline with the other controls. min-height (44px from .btn) keeps it
   a comfortable touch target on mobile. */
.btn-icon {
  padding: 0.4rem;
  aspect-ratio: 1;
  font-size: 1rem
}

.chev {
  font-size: 1.35em;
  line-height: 1;
  vertical-align: -0.08em;
  margin-right: 0.1em;
  margin-left: 0.1em;
}

.btn-warning {
  background: transparent;
  border-color: #d97706;
  color: #b45309;
  border-width: 2px;
  font-weight: var(--fw-semibold)
}

.btn-warning:hover {
  background: rgba(217, 119, 6, 0.13);
  box-shadow: 0 2px 8px rgba(217, 119, 6, 0.2)
}

/* Coverage confirmation (Proposal 010): a second axis, deliberately kept off
   the ok/alt/ext/crit quality palette so the two signals don't blur. */
.banner-badges {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap
}

.banner-badge.bb-pending {
  background: #6366f1
}

.cr-pending {
  color: #d97706;
  font-weight: var(--fw-semibold)
}

.conf-mark {
  margin-top: 0.3rem;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold)
}

.conf-pending {
  color: #b45309
}

.conf-confirmed {
  color: var(--accent2)
}

.conf-default {
  color: var(--muted)
}

/* Group the two action intents (coverage vs absence) inside the card popover. */
.popover-cap {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--fw-semibold);
  color: var(--muted);
  margin: 0.15rem 0 0.1rem
}

.popover-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0 0
}

.fg {
  margin-bottom: var(--space-lg)
}

.fl {
  display: block;
  font-size: var(--text-sm);
  color: var(--text);
  text-transform: none;
  margin-bottom: var(--space-sm);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug)
}

.fc {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Poppins', sans-serif;
  font-size: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  outline: none;
  transition: all 0.2s;
  min-height: 44px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none
}

@media (min-width: 640px) {
  .fc {
    font-size: 0.95rem
  }
}

.fc:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(90, 157, 142, 0.15);
  outline: none
}

.tw {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: -1.5rem -1rem 0 -1rem;
  padding: 0 1rem
}

@media (min-width: 1024px) {
  .tw {
    margin: 0;
    padding: 0
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 600px;
  font-variant-numeric: tabular-nums
}

@media (min-width: 640px) {
  table {
    font-size: var(--text-base);
    min-width: 100%
  }
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-family: 'Poppins', sans-serif;
  font-size: var(--text-xs);
  text-transform: none;
  color: var(--text);
  font-weight: var(--fw-semibold);
  border-bottom: 2px solid var(--accent);
  white-space: nowrap;
  line-height: var(--lh-snug);
  background: rgba(90, 157, 142, 0.05)
}

@media (min-width: 640px) {
  th {
    font-size: var(--text-sm)
  }
}

td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
  line-height: var(--lh-normal)
}

@media (max-width: 640px) {
  td {
    padding: 0.75rem 1rem;
    font-size: var(--text-sm)
  }
}

tr:last-child td {
  border-bottom: none
}

tr:hover td {
  background: var(--surface2)
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-top: 1rem
}

.cal-hdr {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.5rem;
  text-transform: none;
  font-weight: 600
}

.cal-day {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  min-height: 70px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem
}

.cal-day:hover {
  border-color: var(--accent);
  background: rgba(90, 157, 142, 0.04)
}

.cal-day.today {
  border-color: var(--accent);
  background: rgba(90, 157, 142, 0.12);
  font-weight: var(--fw-semibold)
}

.cal-day.empty {
  background: transparent;
  border-color: transparent;
  cursor: default
}

.cal-num {
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text);
  font-size: 0.8rem
}

.cal-today-num {
  color: var(--accent)
}

.cal-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  display: inline-block
}

.cb-a {
  background: rgba(107, 141, 184, 0.2);
  color: var(--sq-a)
}

.cb-b {
  background: rgba(200, 169, 184, 0.2);
  color: var(--sq-b)
}

.cb-c {
  background: rgba(124, 167, 138, 0.2);
  color: var(--sq-c)
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-modal-backdrop);
  align-items: center;
  justify-content: center
}

.overlay.open {
  display: flex
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--space-lg);
  width: 95%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.14);
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: var(--z-modal)
}

@media (min-width: 640px) {
  .modal {
    width: 90%;
    padding: var(--space-xl);
    max-height: 88vh
  }
}

.modal-title {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  margin-bottom: var(--space-lg);
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.1
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
  flex-wrap: wrap
}

.alert {
  padding: var(--space-md) var(--space-lg);
  border-radius: 6px;
  font-size: var(--text-sm);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  border-left: 4px solid;
  line-height: var(--lh-normal);
  font-weight: var(--fw-medium)
}

.a-ok {
  background: rgba(143, 176, 157, 0.12);
  border-color: var(--accent2);
  color: #1a4d3f
}

.a-warn {
  background: rgba(217, 126, 79, 0.12);
  border-color: var(--warn);
  color: #6b3d1f
}

.a-crit {
  background: rgba(199, 66, 66, 0.15);
  border-color: var(--danger);
  color: #5a1f1f;
  border-width: 2px;
  font-weight: var(--fw-semibold);
  box-shadow: 0 2px 8px rgba(199, 66, 66, 0.15)
}

.a-info {
  background: rgba(90, 157, 142, 0.12);
  border-color: var(--accent);
  color: #1a4d3f
}

.sh {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2xl);
  flex-wrap: wrap;
  gap: var(--space-sm)
}

.st {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  color: var(--text);
  letter-spacing: -0.04em;
  line-height: 1
}

.gap {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap
}

.badge {
  display: inline-block;
  font-size: var(--text-xs);
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  text-transform: none;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight)
}

.ba {
  background: rgba(107, 141, 184, 0.15);
  color: var(--sq-a)
}

.bb {
  background: rgba(200, 169, 184, 0.15);
  color: var(--sq-b)
}

.bc {
  background: rgba(124, 167, 138, 0.15);
  color: var(--sq-c)
}

.note-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--space-lg);
  font-size: var(--text-sm);
  color: var(--text);
  line-height: var(--lh-relaxed);
  margin-bottom: var(--space-xl)
}

.note-box strong {
  color: var(--text);
  font-weight: var(--fw-semibold)
}

.notif-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.1rem;
  font-size: var(--text-sm);
  white-space: pre-wrap;
  color: var(--text);
  line-height: var(--lh-relaxed);
  margin-bottom: 1rem;
  min-height: 140px;
  font-family: 'Poppins', sans-serif
}

.rot-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  flex-wrap: wrap
}

.rot-row:last-child {
  border-bottom: none
}

.rot-cur {
  background: var(--surface2);
  border-radius: 4px
}

.rot-wk {
  width: 80px;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-size: 0.9rem
}

.members-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-top: var(--space-lg)
}

@media (min-width: 640px) {
  .members-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg)
  }
}

.member-group {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--space-lg)
}

.mg-title {
  font-size: var(--text-sm);
  text-transform: none;
  color: var(--text);
  margin-bottom: 0.75rem;
  font-family: 'Poppins', sans-serif;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug)
}

.mg-title.cc {
  color: var(--accent)
}

.mg-title.ac1 {
  color: var(--accent2)
}

.mg-title.ac2 {
  color: var(--sq-a)
}

.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
  line-height: var(--lh-normal)
}

.member-item:last-child {
  border-bottom: none
}

/* SETTINGS PAGE */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--space-xl);
  margin-bottom: var(--space-2xl);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06)
}

.settings-title {
  font-family: 'Poppins', sans-serif;
  font-weight: 800;
  font-size: var(--text-lg);
  margin-bottom: var(--space-lg);
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: var(--lh-snug);
  padding-bottom: var(--space-sm);
  border-bottom: 2px solid var(--border);
  display: block
}

.email-preview {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.1rem;
  font-size: var(--text-sm);
  white-space: pre-wrap;
  line-height: var(--lh-relaxed);
  color: var(--text);
  min-height: 180px;
  margin-top: 0.75rem;
  font-family: 'Poppins', sans-serif
}

/* CONFIRM MODAL */
.confirm-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.8rem;
  align-items: start
}

.confirm-key {
  color: var(--muted);
  font-size: var(--text-sm);
  white-space: nowrap;
  line-height: var(--lh-normal)
}

.confirm-val {
  font-size: var(--text-sm);
  line-height: var(--lh-normal)
}

.mail-btn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border)
}

/* GAS-specific UI (repurposed for our backend) */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 248, 246, 0.95);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem
}

#loading-overlay.hidden {
  display: none
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite
}

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

.loading-text {
  font-family: 'Poppins', sans-serif;
  font-weight: var(--fw-semibold);
  font-size: var(--text-base);
  color: var(--text);
  line-height: var(--lh-snug)
}

#sync-indicator {
  position: fixed;
  bottom: 1.25rem;
  right: 1rem;
  z-index: 500;
  font-size: var(--text-xs);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid;
  display: none;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s;
  opacity: 0;
  pointer-events: none;
  font-family: 'Poppins', sans-serif;
  line-height: var(--lh-tight)
}

@media (min-width: 640px) {
  #sync-indicator {
    bottom: 1.5rem;
    right: 1.5rem;
    font-size: var(--text-sm);
    padding: 0.5rem 1rem
  }
}

#sync-indicator.saving {
  opacity: 1;
  border-color: var(--accent);
  background: rgba(90, 157, 142, 0.1);
  color: var(--accent)
}

#sync-indicator.saved {
  opacity: 1;
  border-color: var(--accent2);
  background: rgba(143, 176, 157, 0.1);
  color: var(--accent2)
}

#sync-indicator.error {
  opacity: 1;
  border-color: var(--danger);
  background: rgba(199, 66, 66, 0.1);
  color: var(--danger)
}

#toast {
  position: fixed;
  top: 0.65rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  font-size: var(--text-sm);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  border: 1px solid;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
  font-family: 'Poppins', sans-serif;
  line-height: var(--lh-tight)
}

#toast.show {
  opacity: 1
}

#toast.ok {
  border-color: var(--accent2);
  background: #1a4d3f;
  color: #fff;
  font-weight: var(--fw-semibold)
}

#toast.warn {
  border-color: var(--warn);
  background: #6b3d1f;
  color: #fff;
  font-weight: var(--fw-semibold)
}

#toast.err {
  border-color: var(--danger);
  background: #5a1f1f;
  color: #fff;
  font-weight: var(--fw-bold);
  box-shadow: 0 2px 12px rgba(199, 66, 66, 0.25)
}

/* User badge in header */
.user-badge {
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: var(--lh-tight)
}

.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent)
}

/* Absence search dropdown */
.abs-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12)
}

.abs-search-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s
}

.abs-search-item:last-child {
  border-bottom: none
}

.abs-search-item:hover {
  background: var(--surface2)
}

.abs-search-item.abs-search-empty {
  color: var(--muted);
  cursor: default;
  justify-content: center;
  font-style: italic
}

.abs-search-name {
  font-weight: var(--fw-semibold)
}

.abs-search-meta {
  font-size: var(--text-xs);
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.3rem
}

/* Taller modal for absence creation (search dropdown needs room) */
#abs-modal .modal,
#edit-abs-modal .modal,
#cal-day-modal .modal {
  max-height: 95vh;
  overflow-y: visible
}

/* Week pills in assenze table */
.week-pills-cell {
  white-space: nowrap
}

.week-pill {
  position: relative;
  display: inline-block;
  padding: 0.15rem 0.45rem;
  margin: 0.1rem 0.15rem;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  cursor: default;
  white-space: nowrap;
  vertical-align: middle
}

.week-pill.wp-c0 {
  background: #2a3a5e;
  border-color: #3d5a8a;
  color: #a8c8ff
}

.week-pill.wp-c1 {
  background: #3a2a5e;
  border-color: #5a3d8a;
  color: #cca8ff
}

.week-pill.wp-c2 {
  background: #2a5e4a;
  border-color: #3d8a6a;
  color: #a8ffd8
}

.week-pill.wp-c3 {
  background: #5e4a2a;
  border-color: #8a6a3d;
  color: #ffd8a8
}

.week-pill.wp-c4 {
  background: #5e2a3a;
  border-color: #8a3d5a;
  color: #ffa8c8
}

.week-pill.wp-c5 {
  background: #2a5e5e;
  border-color: #3d8a8a;
  color: #a8ffff
}

.week-pill:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent)
}

.week-pill::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.35rem 0.7rem;
  font-size: var(--text-xs);
  font-weight: var(--fw-normal);
  white-space: nowrap;
  background: #1a1a2e;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: var(--z-tooltip)
}

.week-pill:hover::after {
  opacity: 1
}

/* Assenze table scrolls horizontally on mobile (base .tw overflow-x:auto applies).
   The row action popover would be clipped by that scroll container, so it's
   re-anchored with position:fixed via JS (positionAbsPopover) when opened. */
#page-assenze .card-popover {
  position: fixed;
}

/* Leading action column: shrink to the ⋮ button instead of a wide, mostly-empty
   cell, and tighten its padding so it sits near the edge (notably on mobile). */
#page-assenze th:first-child,
#page-assenze td:first-child {
  width: 1%;
  white-space: nowrap;
  padding-left: 0.5rem;
  padding-right: 0.4rem;
}

/* Bleed the Assenze table to the card edges: the base .tw assumes a 1rem card
   gutter, but .card pads 1.5rem (mobile) / 2rem (tablet), leaving the table
   over-inset. Match the negative margin to the real card padding + a small gutter. */
@media (max-width: 1023px) {
  #page-assenze .tw {
    margin-left: calc(-1 * var(--space-lg));
    margin-right: calc(-1 * var(--space-lg));
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  #page-assenze .tw {
    margin-left: calc(-1 * var(--space-xl));
    margin-right: calc(-1 * var(--space-xl));
  }
}

/* Segmented control */
.seg-ctrl {
  display: flex;
  gap: 0;
  margin-bottom: var(--space-md);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden
}

.seg-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  background: var(--surface);
  color: var(--muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s
}

.seg-btn:not(:last-child) {
  border-right: 1px solid var(--border)
}

.seg-btn.seg-active {
  background: var(--accent);
  color: #fff
}

.seg-btn:hover:not(.seg-active) {
  background: var(--surface2);
  color: var(--fg)
}

/* Calendar day modal absence list */
.cal-day-abs-item {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm)
}

.cal-day-abs-item:last-child {
  border-bottom: none
}

/* Absence pagination */
.abs-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: var(--space-md);
  border-top: 1px solid var(--border)
}
