:root {
  /* macOS Tahoe / iOS 26 Palette */
  --bg-primary: #f5f5f7;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-solid: rgba(255, 255, 255, 0.88);
  --glass-border: rgba(255, 255, 255, 0.6);
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --surface-strong: rgba(255, 255, 255, 0.95);
  --surface-border: rgba(0, 0, 0, 0.1);
  
  /* Neutral accent */
  --accent: #1d1d1f;
  --accent-hover: #3a3a3c;
  
  /* Semantic */
  --danger: #ff3b30;
  --success: #30d158;
  
  /* Glass effects */
  --blur-heavy: blur(60px) saturate(180%);
  --blur-medium: blur(40px) saturate(160%);
  --blur-light: blur(20px) saturate(140%);
  
  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  
  /* Transitions */
  --ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

body.dark {
  --bg-primary: #0c0c0e;
  --glass-bg: rgba(24, 24, 30, 0.6);
  --glass-bg-solid: rgba(30, 30, 36, 0.92);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f5f5f7;
  --text-secondary: #b0b3ba;
  --text-tertiary: #6f7278;
  --accent: #0a84ff;
  --accent-hover: #2f9bff;
  --surface-strong: rgba(16, 16, 22, 0.96);
  --surface-border: rgba(255, 255, 255, 0.08);
}

.icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
  margin-right: 6px;
}

.icon-moon {
  display: none;
  fill: currentColor;
  stroke: none;
}

.icon-lock,
.icon-unlock {
  display: none;
}

.btn .btn-label {
  margin-left: 6px;
}

#themeToggle .icon-sun,
#themeToggle .icon-moon,
#lockBtn .icon-lock,
#lockBtn .icon-unlock {
  display: inline-block;
}

#themeToggle .icon-moon {
  display: none;
}

body.dark #themeToggle .icon-sun {
  display: none;
}

body.dark #themeToggle .icon-moon {
  display: inline-block;
}

#lockBtn[data-locked="true"] .icon-lock {
  display: none;
}

#lockBtn[data-locked="true"] .icon-unlock {
  display: inline-block;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  /* iOS 26 / macOS Tahoe style - subtle warm/cool gradient */
  background: linear-gradient(
    160deg,
    #f8f6fa 0%,
    #f5f5f7 30%,
    #f2f4f8 60%,
    #f5f5f7 100%
  );
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.01em;
}

body.dark {
  background: radial-gradient(120% 120% at 15% 15%, rgba(60, 80, 140, 0.18), transparent 45%),
    radial-gradient(120% 120% at 85% 10%, rgba(80, 60, 140, 0.12), transparent 42%),
    linear-gradient(150deg, #0d0d12 0%, #101019 35%, #0b0b11 100%);
  color: var(--text-primary);
}

body.gate-open {
  overflow: hidden;
}

/* Ambient glow - very subtle */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(ellipse 80% 60% at 10% 10%, rgba(210, 200, 230, 0.25) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 90% 20%, rgba(200, 215, 235, 0.2) 0%, transparent 45%),
    radial-gradient(ellipse 70% 50% at 50% 90%, rgba(215, 225, 240, 0.18) 0%, transparent 50%);
  z-index: -1;
  pointer-events: none;
}

body.dark::before {
  background:
    radial-gradient(ellipse 75% 60% at 15% 20%, rgba(46, 74, 140, 0.28) 0%, transparent 55%),
    radial-gradient(ellipse 60% 55% at 90% 15%, rgba(80, 55, 140, 0.26) 0%, transparent 50%),
    radial-gradient(ellipse 70% 60% at 50% 85%, rgba(30, 80, 120, 0.22) 0%, transparent 55%);
}

/* Glass card base */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: var(--blur-heavy);
  -webkit-backdrop-filter: var(--blur-heavy);
  border: 0.5px solid rgba(255, 255, 255, 0.7);
  box-shadow: 
    0 1px 3px rgba(0, 0, 0, 0.02),
    0 8px 32px rgba(0, 0, 0, 0.03);
  position: relative;
  overflow: hidden;
}

.glass-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 30%);
}

body.dark .glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow:
    0 1px 6px rgba(0, 0, 0, 0.4),
    0 18px 48px rgba(0, 0, 0, 0.35);
}

body.dark .glass-card::after {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 30%);
}

/* Input styling */
.glass-input {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--text-primary);
  transition: all 0.2s var(--ease-out);
  font-family: inherit;
  font-size: 15px;
}

.glass-input::placeholder {
  color: var(--text-tertiary);
}

.glass-input:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(0, 0, 0, 0.12);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.03);
}

body.dark .glass-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

body.dark .glass-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

body.dark .glass-input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.18);
}

.glass-input:focus-visible,
.btn:focus-visible,
.segment-btn:focus-visible,
.nav-arrow:focus-visible {
  outline: 1px solid #0a84ff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.18);
}

/* ============================================
   HEADER - Floating transparent bar
   ============================================ */
.glass-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(50px) saturate(180%);
  -webkit-backdrop-filter: blur(50px) saturate(180%);
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.04);
  padding: 0;
  box-shadow: 
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 1px 2px rgba(0, 0, 0, 0.02),
    0 4px 12px rgba(0, 0, 0, 0.03);
}

body.dark .glass-header {
  background: rgba(14, 14, 18, 0.82);
  border-bottom: 0.5px solid rgba(255, 255, 255, 0.04);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 10px 28px rgba(0, 0, 0, 0.4);
}

.header-wrap {
  max-width: 100%;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand-sub {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 13px;
  margin-left: 6px;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  justify-content: center;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-input {
  width: 200px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ============================================
   SEGMENTED CONTROL - Apple style
   ============================================ */
.segmented-control {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 1px;
}

.segment-btn {
  position: relative;
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s var(--ease-out);
  will-change: transform, box-shadow;
  z-index: 1;
}

.segment-btn:hover {
  color: var(--text-primary);
}

.segment-btn[aria-current="true"] {
  background: white;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 
    0 1px 2px rgba(0, 0, 0, 0.04),
    0 1px 3px rgba(0, 0, 0, 0.06);
}

body.dark .segmented-control {
  background: rgba(255, 255, 255, 0.06);
}

body.dark .segment-btn {
  color: var(--text-secondary);
}

body.dark .segment-btn[aria-current="true"] {
  background: rgba(255, 255, 255, 0.14);
  color: var(--text-primary);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ============================================
   BUTTONS - Clean Apple style
   ============================================ */
.btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: all 0.15s var(--ease-out);
  will-change: transform, box-shadow;
}

.btn:hover {
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.6), rgba(230, 236, 248, 0.5));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.btn:active {
  background: rgba(0, 0, 0, 0.1);
  transform: scale(0.98);
}

body.dark .btn {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05);
}

body.dark .btn:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 6px 16px rgba(0, 0, 0, 0.35);
}

body.dark .btn:active {
  background: rgba(255, 255, 255, 0.18);
}

.header-tools .btn:not(.btn-danger),
.header-tools .btn-ghost {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.6);
}

.header-tools .btn:not(.btn-danger):hover,
.header-tools .btn-ghost:hover {
  background: linear-gradient(150deg, rgba(10, 132, 255, 0.08), rgba(90, 200, 250, 0.12));
  border-color: rgba(10, 132, 255, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    0 5px 12px rgba(10, 132, 255, 0.1);
}

.header-tools .btn:not(.btn-danger):active,
.header-tools .btn-ghost:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 3px 8px rgba(10, 132, 255, 0.14);
}

body.dark .header-tools .btn:not(.btn-danger),
body.dark .header-tools .btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

body.dark .header-tools .btn:not(.btn-danger):hover,
body.dark .header-tools .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 6px 16px rgba(0, 0, 0, 0.35);
}

body.dark .header-tools .btn:not(.btn-danger):active,
body.dark .header-tools .btn-ghost:active {
  background: rgba(255, 255, 255, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 3px 8px rgba(0, 0, 0, 0.45);
}

.btn-accent {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-accent:active {
  background: #2c2c2e;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.04);
}

.btn-danger {
  background: rgba(255, 59, 48, 0.08);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.12);
}

.btn-small {
  padding: 4px 8px;
  font-size: 12px;
}

/* ============================================
   CALENDAR CONTAINER
   ============================================ */
.hero-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 46px);
  height: calc(100dvh - 46px);
  padding: 10px;
  overflow: hidden;
  align-items: center;
}

.calendar-hero {
  width: min(1040px, 94vw);
  height: 100%;
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.9), rgba(236, 240, 248, 0.82));
  backdrop-filter: var(--blur-heavy);
  -webkit-backdrop-filter: var(--blur-heavy);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 
    0 2px 10px rgba(0, 0, 0, 0.03),
    0 10px 36px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    inset 0 0 0 1px rgba(0, 0, 0, 0.03);
  animation: fadeIn 0.4s var(--ease-out);
}

body.dark .calendar-hero {
  background: linear-gradient(150deg, rgba(20, 20, 28, 0.92), rgba(24, 28, 36, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.5),
    0 12px 42px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

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

/* ============================================
   MONTH NAVIGATION
   ============================================ */
.month-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
  flex-shrink: 0;
}

.month-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.month-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.03em;
}

.nav-arrow {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.03);
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s var(--ease-out);
  will-change: transform, box-shadow;
}

.nav-arrow:hover {
  background: rgba(0, 0, 0, 0.06);
}

.nav-arrow:active {
  transform: scale(0.94) translateY(0.5px);
  background: rgba(0, 0, 0, 0.08);
}

.nav-arrow svg {
  width: 18px;
  height: 18px;
}

.nav-arrow svg path {
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.dark .nav-arrow {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.dark .nav-arrow:hover {
  background: rgba(255, 255, 255, 0.12);
}

body.dark .nav-arrow:active {
  background: rgba(255, 255, 255, 0.18);
}

header svg path,
.header-tools svg path {
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ============================================
   CALENDAR GRID
   ============================================ */
.calendar-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.calendar-wrapper::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 32px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(0,0,0,0.05));
}

#billList {
  position: relative;
}

#billList::after {
  content: '';
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 24px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(0,0,0,0.04));
}

.dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  padding: 0 2px;
  flex-shrink: 0;
}

.dow > div {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 0;
}

body.dark .dow > div {
  color: rgba(255, 255, 255, 0.45);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 4px;
  padding: 0 2px;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.calendar-grid::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: calc(var(--radius-md) + 2px);
  background: repeating-linear-gradient(
    to bottom,
    rgba(10, 132, 255, 0.028),
    rgba(10, 132, 255, 0.028) calc(100% / 6),
    transparent calc(100% / 6),
    transparent calc(2 * 100% / 6)
  );
  z-index: 0;
}

.calendar-cell {
  border-radius: var(--radius-md);
  border: 0.5px solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.82);
  padding: 6px;
  position: relative;
  transition: all 0.15s var(--ease-out);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  position: relative;
  z-index: 1;
}

.calendar-cell:hover {
  background: rgba(255, 255, 255, 0.97);
  border-color: rgba(255, 255, 255, 1);
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  z-index: 2;
}

.calendar-cell:active {
  transform: scale(0.985);
}

.calendar-cell.muted {
  background: rgba(255, 255, 255, 0.45);
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.calendar-cell.muted:hover {
  transform: none;
  box-shadow: none;
  background: rgba(0, 0, 0, 0.01);
}

.calendar-cell.today {
  background: rgba(255, 255, 255, 0.95);
  border: 1.5px solid var(--text-primary);
  box-shadow: 
    0 0 0 3px rgba(0, 0, 0, 0.04),
    0 2px 6px rgba(0, 0, 0, 0.05);
}

body.dark .calendar-cell {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

body.dark .calendar-cell:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

body.dark .calendar-cell.today {
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid var(--accent);
  box-shadow:
    0 0 0 3px rgba(10, 132, 255, 0.14),
    0 2px 10px rgba(0, 0, 0, 0.45);
}

.cell-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  flex-shrink: 0;
  line-height: 1;
}

.calendar-cell.today .cell-date {
  font-weight: 700;
}

.cell-bills {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.bill-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(235, 240, 255, 0.82));
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  padding: 3px 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  flex-shrink: 0;
  color: #0b0b0c;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: background 0.12s, border-color 0.12s;
}

.bill-chip:hover {
  background: linear-gradient(135deg, rgba(245, 247, 255, 0.96), rgba(225, 235, 255, 0.9));
  border-color: rgba(0, 0, 0, 0.08);
}

body.dark .bill-chip {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.12));
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f7f7fb;
  text-shadow: none;
}

body.dark .bill-chip:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.16));
  border-color: rgba(255, 255, 255, 0.12);
}

.bill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: linear-gradient(180deg, #0a84ff, #5ac8fa);
  box-shadow: 0 0 0 4px rgba(90, 200, 250, 0.12);
  flex-shrink: 0;
}

body.dark .bill-dot {
  background: linear-gradient(180deg, #4fa8ff, #7ad3ff);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.18);
}

.cell-add-btn {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: none;
  padding: 2px 6px;
  font-size: 10px;
  border-radius: 5px;
}

.calendar-cell:hover .cell-add-btn {
  display: inline-flex;
}

/* ============================================
   MODAL
   ============================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(30px) saturate(150%);
  -webkit-backdrop-filter: blur(30px) saturate(150%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms var(--ease-out), visibility 180ms var(--ease-out);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal {
  width: min(480px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  border-radius: var(--radius-xl);
  padding: 24px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: var(--blur-heavy);
  -webkit-backdrop-filter: var(--blur-heavy);
  border: 0.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.1),
    0 8px 20px rgba(0, 0, 0, 0.05);
  transform: scale(0.98) translateY(-6px);
  opacity: 0;
  transition: opacity 180ms var(--ease-out), transform 220ms var(--ease-spring);
  position: relative;
}

.modal-backdrop.active .modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal::after {
  content: '';
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(0,0,0,0.05));
}

body.dark .modal-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

body.dark .modal {
  background: rgba(18, 18, 24, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 8px 22px rgba(0, 0, 0, 0.4);
}

body.dark .modal::after {
  background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,0.3));
}

.modal h3 {
  margin: 0 0 18px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 0.5px solid rgba(0, 0, 0, 0.03);
  border-radius: var(--radius-md);
  transition: background 0.1s;
}

.item:hover {
  background: rgba(255, 255, 255, 0.8);
}

body.dark .item {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.06);
}

body.dark .item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.hr {
  height: 0.5px;
  background: rgba(0, 0, 0, 0.06);
  margin: 14px 0;
}

body.dark .hr {
  background: rgba(255, 255, 255, 0.08);
}

.glass-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

textarea.glass-input {
  resize: vertical;
  min-height: 70px;
  line-height: 1.4;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

#billForm .flex {
  gap: 8px;
  margin-bottom: 8px;
}

#billForm input[style*="width:140px"] {
  width: 130px !important;
}

/* ============================================
   AUTH GATE - Full screen login
   ============================================ */
.gate {
  position: fixed;
  inset: 0;
  background: linear-gradient(
    160deg,
    #f8f6fa 0%,
    #f5f5f7 30%,
    #f2f4f8 60%,
    #f5f5f7 100%
  );
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.gate::before {
  content: '';
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(ellipse 80% 60% at 10% 10%, rgba(210, 200, 230, 0.3) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 90% 20%, rgba(200, 215, 235, 0.25) 0%, transparent 45%),
    radial-gradient(ellipse 70% 50% at 50% 90%, rgba(215, 225, 240, 0.2) 0%, transparent 50%);
  z-index: -1;
  pointer-events: none;
}

body.dark .gate {
  background: linear-gradient(160deg, #0f1016 0%, #0c0d12 40%, #0a0b10 100%);
}

body.dark .gate::before {
  background:
    radial-gradient(ellipse 80% 60% at 10% 10%, rgba(46, 74, 140, 0.28) 0%, transparent 55%),
    radial-gradient(ellipse 60% 50% at 90% 20%, rgba(80, 55, 140, 0.24) 0%, transparent 45%),
    radial-gradient(ellipse 70% 50% at 50% 90%, rgba(30, 80, 120, 0.18) 0%, transparent 55%);
}

.gate.show {
  display: flex;
}

.gate-credit {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  letter-spacing: -0.01em;
}

.gate-card {
  width: min(340px, 100%);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(236, 241, 250, 0.86));
  backdrop-filter: var(--blur-heavy);
  -webkit-backdrop-filter: var(--blur-heavy);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.09),
    0 10px 28px rgba(0, 0, 0, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -1px 0 rgba(255, 255, 255, 0.5);
  animation: modalIn 0.4s var(--ease-out);
  text-align: center;
  position: relative;
  overflow: hidden;
}

body.dark .gate-card {
  background: linear-gradient(145deg, rgba(26, 28, 36, 0.95), rgba(20, 22, 30, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 10px 28px rgba(0, 0, 0, 0.45);
}

.gate-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.gate-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 120% at 20% 0%, rgba(255, 255, 255, 0.6), transparent 42%),
    radial-gradient(140% 140% at 90% 8%, rgba(210, 225, 255, 0.32), transparent 52%);
  pointer-events: none;
}

.gate-card::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: calc(var(--radius-xl) - 2px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

.gate-card h2 {
  margin: 0 0 4px;
}

.gate-card .subhead {
  margin: 0 0 18px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
}

.hint {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.45;
}

.flex {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gate-card .glass-input {
  width: 100%;
  height: 44px;
  text-align: center;
  font-size: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.82);
}

.gate-note {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.gate-card .glass-input:focus-visible {
  outline: 1px solid #0a84ff;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.16);
}

#gateBtn {
  width: 100%;
  padding: 12px 12px;
  font-size: 14px;
  border-radius: 12px;
  background: linear-gradient(150deg, #0b84ff, #5ac8fa);
  box-shadow:
    0 10px 24px rgba(10, 132, 255, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

#gateBtn:hover {
  background: linear-gradient(150deg, #0c7df0, #4db8f0);
}

#gateBtn:active {
  transform: translateY(1px);
  box-shadow:
    0 6px 16px rgba(10, 132, 255, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: var(--blur-medium);
  -webkit-backdrop-filter: var(--blur-medium);
  border: 0.5px solid rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  display: block;
  opacity: 0;
  pointer-events: none;
  z-index: 1500;
  animation: none;
  transform: translateY(8px);
  transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

body.dark .toast {
  background: rgba(16, 16, 22, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}

.toast.undo button {
  color: var(--accent);
  font-weight: 600;
}

.toast {
  background: var(--surface-strong);
  border: 0.5px solid var(--surface-border);
  z-index: 3000;
  display: block;
  position: fixed;
}

.toast::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0.6), rgba(255,255,255,0));
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  body {
    overflow: auto;
    min-height: 100vh;
  }

  .header-wrap {
    padding: 8px 12px;
    gap: 10px;
    flex-wrap: wrap;
  }
  
  .brand {
    font-size: 14px;
  }
  
  .brand-sub {
    display: none;
  }

  .search-input {
    display: block;
    width: 100%;
    max-width: none;
    font-size: 12px;
    padding: 8px 12px;
    min-width: 0;
  }

  .header-center {
    width: 100%;
    justify-content: center;
  }

  .segment-btn {
    padding: 4px 10px;
    font-size: 12px;
  }

  .hero-container {
    padding: 10px 8px 14px;
    height: auto;
    min-height: calc(100vh - 42px);
    min-height: calc(100dvh - 42px);
    overflow: visible;
  }

  .calendar-hero {
    padding: 12px;
    border-radius: var(--radius-lg);
    height: auto;
    min-height: 58vh;
    max-height: none;
    overflow: visible;
  }

  .month-title {
    font-size: 15px;
  }

  .nav-arrow {
    width: 28px;
    height: 28px;
  }

  .nav-arrow svg {
    width: 16px;
    height: 16px;
  }

  .dow > div {
    font-size: 9px;
  }

  .calendar-wrapper {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding-right: 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .calendar-grid {
    gap: 4px;
    height: auto;
    min-height: 52vh;
    max-height: none;
    grid-template-rows: repeat(6, minmax(92px, 1fr));
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    padding-right: 0;
  }

  .calendar-cell {
    padding: 6px;
    border-radius: 10px;
    min-height: 96px;
  }

  .cell-date {
    font-size: 10px;
  }

  .bill-chip {
    font-size: 8px;
    padding: 2px 4px;
  }
}

@media (max-width: 480px) {
  /* Keep lock + theme toggle + seed visible on mobile; hide export/import */
  .header-tools .btn:not(#lockBtn):not(#themeToggle):not(#seedBtn) {
    display: none;
  }

  .header-wrap {
    flex-wrap: wrap;
  }

  .header-center {
    width: 100%;
  }

  .calendar-hero {
    padding: 10px;
    min-height: 56vh;
    max-height: none;
  }

  .calendar-wrapper {
    max-height: none;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .calendar-grid {
    min-height: 50vh;
    grid-template-rows: repeat(6, minmax(88px, 1fr));
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .cell-date {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .bill-chip {
    font-size: 7px;
    padding: 2px 3px;
    border-radius: 3px;
  }

  .bill-dot {
    width: 4px;
    height: 4px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
