:root {
  --bg-canvas: #060608;
  --bg-card: #121216;
  --bg-card-hover: #18181e;
  --bg-elevated: #1c1c23;
  --bg-glass: rgba(14, 14, 18, 0.84);
  --text-primary: #f4f4f6;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --hairline: rgba(255, 255, 255, 0.075);
  --hairline-strong: rgba(255, 255, 255, 0.14);
  --accent: #ff453a;
  --accent-soft: rgba(255, 69, 58, 0.14);
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ff453a;
  --shadow-card: 0 2px 8px -2px rgba(0, 0, 0, 0.45), inset 0 1px 0 0 rgba(255, 255, 255, 0.06);
  --shadow-sheet: 0 -12px 48px rgba(0, 0, 0, 0.72);
  --radius-outer: 16px;
  --radius-inner: 10px;
}

[data-theme="light"] {
  --bg-canvas: #f6f6f9;
  --bg-card: #ffffff;
  --bg-card-hover: #fafafa;
  --bg-elevated: #efeff4;
  --bg-glass: rgba(255, 255, 255, 0.86);
  --text-primary: #141416;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --hairline: rgba(0, 0, 0, 0.07);
  --hairline-strong: rgba(0, 0, 0, 0.13);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px -2px rgba(0, 0, 0, 0.04);
  --shadow-sheet: 0 -12px 40px rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100dvh;
}

.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
}

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
  display: flex;
  flex-direction: column;
}

/* ─── Sticky Glass Header ─── */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--hairline);
  padding: 10px 16px 10px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.sync-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--hairline);
  padding: 2px 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sync-badge.synced::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ok);
}

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

.icon-btn {
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.14s cubic-bezier(0.16, 1, 0.3, 1), background 0.14s;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* ─── Bottom Filter Bar & Search ─── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 520px;
  margin: 0 auto;
  padding: 2px 4px;
}
.filter-bar::-webkit-scrollbar {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 32;
  background: var(--bg-glass);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border-top: 1px solid var(--hairline);
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
}

.tab-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

.tab-chip.active {
  background: var(--text-primary);
  color: var(--bg-canvas);
  border-color: transparent;
}

.tab-count {
  font-size: 10.5px;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

.search-row {
  margin-top: 8px;
  display: none;
}
.search-row.open {
  display: block;
}

.search-input {
  width: 100%;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--hairline-strong);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 0 12px;
  font-size: 13.5px;
  outline: none;
}

/* ─── Main Feed & Pinned Hero Card ─── */
.feed-container {
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hero-card {
  position: relative;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-card) 100%);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-outer);
  box-shadow: var(--shadow-card);
  padding: 18px 16px 16px;
  text-align: center;
  overflow: hidden;
  cursor: pointer;
}

.hero-pin-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--hairline-strong);
}

.hero-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 340px;
  margin: 0 auto 12px;
}

.hero-unit-box {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-inner);
  padding: 8px 4px 6px;
}
[data-theme="light"] .hero-unit-box {
  background: rgba(0, 0, 0, 0.035);
}

.hero-num {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--text-primary);
}

.hero-lbl {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 3px;
  text-transform: uppercase;
}

.hero-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ─── Section Divider Headers ─── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 2px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ─── Event Cards ─── */
.event-card {
  background: var(--bg-card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-outer);
  box-shadow: var(--shadow-card);
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.14s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.14s, background 0.14s;
}

.event-card:active {
  transform: scale(0.985);
}

.event-left {
  min-width: 0;
  flex: 1;
}

.event-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 3px;
}

/* Soft, Calm Urgency Card Tints ONLY (Red <= 3d, Amber/Yellow <= 7d, Neutral otherwise) */
.event-card[data-urgency="urgent"] {
  background: linear-gradient(135deg, rgba(255, 69, 58, 0.12) 0%, rgba(255, 69, 58, 0.03) 70%, var(--bg-card) 100%);
  border-color: rgba(255, 69, 58, 0.24);
}

.event-card[data-urgency="soon"] {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.11) 0%, rgba(245, 158, 11, 0.03) 70%, var(--bg-card) 100%);
  border-color: rgba(245, 158, 11, 0.22);
}

.event-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.jalali-chip {
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--hairline);
}

.notify-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.24);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.event-ticker-sub {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.event-right {
  text-align: right;
  flex-shrink: 0;
}

.event-primary-val {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  white-space: nowrap;
}

.event-primary-val .unit-sm {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 1px;
  margin-right: 4px;
}

.event-badge-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 2px;
}

.event-badge-sub.since-tag {
  color: var(--text-secondary);
}
.event-badge-sub.today-tag {
  color: #fbbf24;
}

/* ─── Floating + FAB & Bottom Navigation Bar ─── */
.fab-add {
  position: fixed;
  right: max(18px, calc(50% - 240px));
  bottom: calc(env(safe-area-inset-bottom, 0px) + 74px);
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  box-shadow: 0 8px 24px rgba(255, 69, 58, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  font-size: 28px;
  font-weight: 400;
  cursor: pointer;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}
.fab-add:active {
  transform: scale(0.91);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 32;
  background: var(--bg-glass);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border-top: 1px solid var(--hairline);
  padding: 6px 12px calc(env(safe-area-inset-bottom, 0px) + 6px);
}

.bottom-nav-inner {
  max-width: 500px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 4px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.nav-item.active {
  color: var(--text-primary);
}
.nav-icon {
  font-size: 17px;
  line-height: 1;
}

/* ─── Bottom Sheet Modals (Add/Edit, Presets, Settings) ─── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop.open {
  display: flex;
}

.sheet-panel {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-card);
  border-top: 1px solid var(--hairline-strong);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-sheet);
  padding: 12px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  animation: sheetUp 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sheetUp {
  from { transform: translateY(100%); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--hairline-strong);
  margin: 2px auto 14px;
}

.form-group {
  margin-bottom: 13px;
}
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-input, .form-select {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--hairline-strong);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 0 12px;
  font-size: 14px;
  outline: none;
}
.seg-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
}
@media (max-width: 420px) {
  .emoji-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
.emoji-opt {
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--hairline);
  background: var(--bg-elevated);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.12s, background 0.12s;
}
.emoji-opt:active {
  transform: scale(0.92);
}
.emoji-opt.active {
  background: var(--bg-card-hover);
  border-color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--text-primary);
}
.seg-btn {
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--hairline);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--text-primary);
  color: var(--bg-canvas);
  border-color: transparent;
}
.btn-primary {
  width: 100%;
  height: 42px;
  border-radius: 11px;
  border: none;
  background: var(--text-primary);
  color: var(--bg-canvas);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger {
  height: 42px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid rgba(255, 69, 58, 0.35);
  background: rgba(255, 69, 58, 0.12);
  color: #ff453a;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

