:root {
  --accent: #5A52FF;
  --accent-hover: #4941EE;
  --accent-soft: #9F9BFF;
  --accent-tint: rgba(90, 82, 255, 0.11);
  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --surface-2: #ECECE9;
  --sidebar: #121212;
  --sidebar-card: #1E1E21;
  --text: #151515;
  --text-2: #79797E;
  --border: #E0E0EA;
  --urgent: #F2600C;
  --urgent-tint: rgba(242, 96, 12, 0.12);
  --success: #16A34A;
  --success-tint: rgba(22, 163, 74, 0.12);
  --danger: #DC2626;
  --danger-tint: rgba(220, 38, 38, 0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --shadow-nav: 0 8px 28px rgba(18, 18, 18, 0.10);
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1C1C1E;
  --surface-2: #27272A;
  --sidebar: #0B0B0D;
  --sidebar-card: #1C1C1E;
  --text: #FFFFFF;
  --text-2: #9A9AA0;
  --border: #2C2C32;
  --accent-tint: rgba(90, 82, 255, 0.22);
  --shadow-nav: 0 10px 30px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button {
  cursor: pointer;
}

/* Shell Layout */
.shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.sidebar {
  display: none;
}

.main-wrap {
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(98px + env(safe-area-inset-bottom, 0px));
}

.main-wrap--onboarding {
  max-width: 480px;
  padding: 28px 18px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
}

/* Mobile Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.topbar__left {
  min-width: 0;
}

.topbar__greet {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 2px;
}

.page-title {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-2);
}

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

.pill-alert {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #FFFFFF;
  border: 0;
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.desktop-add-btn {
  display: none;
}

/* Bottom Mobile Nav */
.bottom-nav-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  z-index: 40;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}

.bottom-nav {
  pointer-events: auto;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-nav);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: 6px 10px;
  gap: 4px;
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 16px;
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 600;
  border: 0;
  background: transparent;
}

.bottom-nav__item.is-active {
  color: var(--accent);
}

.bottom-nav__add {
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--accent);
  color: #FFFFFF;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}

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

/* Logo */
.logo {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
}

.logo__dot {
  color: var(--accent);
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
}

.card--flat {
  border: 0;
}

.card--accent {
  background: var(--accent);
  color: #FFFFFF;
  border-color: transparent;
}

.card--accent .muted,
.card--accent .card__eyebrow {
  color: rgba(255, 255, 255, 0.82);
}

.card__eyebrow {
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
}

.big-amount {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 6px 0 4px;
}

.muted {
  color: var(--text-2);
}

.small {
  font-size: 12.5px;
}

.urgent-text {
  color: var(--urgent);
  font-weight: 600;
}

/* Progress Bar */
.progress-track {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 6px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.card--accent .progress-track {
  background: rgba(255, 255, 255, 0.25);
}

.card--accent .progress-fill {
  background: #FFFFFF;
}

/* Quick Actions Row (4 squares) */
.quick-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}

.quick-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.quick-btn__icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

/* Section Headers */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
}

.section-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.link-muted {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 600;
}

.link-accent {
  font-size: 13.5px;
  color: var(--accent);
  font-weight: 600;
}

/* Subscription / Item List */
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.sub-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}

.sub-row:last-child {
  border-bottom: 0;
}

.sub-row:hover {
  background: var(--surface-2);
}

.sub-row__main {
  flex: 1;
  min-width: 0;
}

.sub-row__title {
  font-weight: 700;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sub-row__sub {
  font-size: 12.5px;
  color: var(--text-2);
  margin-top: 2px;
}

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

.sub-row__amount {
  font-weight: 700;
  font-size: 14.5px;
}

.sub-row__cycle {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
}

/* Tiles */
.tile {
  border-radius: 12px;
  color: #FFFFFF;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}

.tile--sm {
  width: 36px;
  height: 36px;
  font-size: 12px;
  border-radius: 10px;
}

.tile--md {
  width: 42px;
  height: 42px;
  font-size: 13px;
  border-radius: 12px;
}

.tile--lg {
  width: 68px;
  height: 68px;
  font-size: 20px;
  border-radius: 18px;
}

.tile--dense.tile--sm { font-size: 10px; }
.tile--dense.tile--md { font-size: 11px; }
.tile--dense.tile--lg { font-size: 16px; }

/* Buttons & Chips */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 700;
  font-size: 14.5px;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: #FFFFFF;
}

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

.btn--white {
  background: #FFFFFF;
  color: #151515;
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn--dark-muted {
  background: #2C2C30;
  color: #FFFFFF;
}

.btn--danger {
  background: var(--danger);
  color: #FFFFFF;
}

.btn--ghost {
  background: transparent;
  color: var(--text-2);
}

.btn--sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn--full {
  width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.chip.is-active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge--accent {
  background: var(--accent-tint);
  color: var(--accent);
}

.badge--success {
  background: var(--success-tint);
  color: var(--success);
}

.badge--urgent {
  background: var(--urgent-tint);
  color: var(--urgent);
}

.badge--danger {
  background: var(--danger-tint);
  color: var(--danger);
}

.badge--muted {
  background: var(--surface-2);
  color: var(--text-2);
}

/* Demo Banner */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--accent-tint);
  color: var(--text);
  border: 1px solid rgba(90, 82, 255, 0.25);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cal-nav {
  display: flex;
  gap: 6px;
}

.cal-nav__btn {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.cal-weekdays, .cal-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  gap: 4px;
}

.cal-weekdays {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.cal-day {
  position: relative;
  height: 40px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cal-day:hover:not(:disabled) {
  background: var(--surface-2);
}

.cal-day.is-today {
  background: var(--accent);
  color: #FFFFFF;
}

.cal-day.is-selected:not(.is-today) {
  background: var(--accent-tint);
  color: var(--accent);
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  margin-top: 2px;
}

.cal-day.is-today .cal-dot {
  background: #FFFFFF;
}

/* Detail view */
.detail-hero {
  text-align: center;
  padding: 8px 0 18px;
}

.detail-hero__tile {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.detail-hero__title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.detail-hero__sub {
  margin: 4px 0 10px;
  color: var(--text-2);
  font-size: 14px;
}

.kv-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-bottom: 14px;
}

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.kv-row:last-child {
  border-bottom: 0;
}

.kv-row__label {
  color: var(--text-2);
}

.kv-row__val {
  font-weight: 700;
}

.history-boxes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 12px 0 8px;
}

.history-box {
  height: 28px;
  border-radius: 8px;
  background: var(--border);
}

.history-box.is-filled {
  background: var(--accent);
}

.stack-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch__slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s ease;
  cursor: pointer;
}

.switch__slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform 0.2s ease;
}

.switch input:checked + .switch__slider {
  background: var(--accent);
}

.switch input:checked + .switch__slider::before {
  transform: translateX(20px);
}

/* Forms */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
}

.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-error {
  background: var(--danger-tint);
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
}

/* Store Grid */
.store-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.product-card__head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.product-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Variants side by side (ref 6 paywall style) */
.variants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.variant-card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.variant-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.variant-pill {
  display: inline-block;
  align-self: flex-start;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.feature-list {
  margin: 10px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
}

/* Modals & Sheets */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 18, 0.58);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-backdrop--sheet {
  align-items: flex-end;
  padding: 0;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  color: var(--text);
  border-radius: 24px;
  padding: 24px 20px 20px;
  border: 1px solid var(--border);
}

.modal-card--success {
  text-align: center;
}

.success-badge {
  width: 68px;
  height: 68px;
  border-radius: 999px;
  background: var(--accent);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-body {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-2);
}

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

.modal-actions--row {
  flex-direction: row;
  justify-content: flex-end;
}

.sheet-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom, 0px));
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0 auto 14px;
}

.sheet-title {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 800;
}

.sheet-subtitle {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-2);
}

/* Toasts */
.toast-root {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: #151515;
  color: #FFFFFF;
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast__btn {
  background: var(--accent);
  color: #FFFFFF;
  border: 0;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Utilities */
.desktop-only { display: none; }
.mobile-only { display: block; }
.stack-12 { display: flex; flex-direction: column; gap: 12px; }
.stack-16 { display: flex; flex-direction: column; gap: 16px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Desktop Layout (>= 1024px) */
@media (min-width: 1024px) {
  .desktop-only { display: block; }
  .mobile-only { display: none; }

  .shell {
    flex-direction: row;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #FFFFFF;
    padding: 24px 14px;
    position: sticky;
    top: 0;
    height: 100dvh;
  }

  .sidebar__logo {
    padding: 4px 10px 22px;
  }

  .sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }

  .sidebar__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: #A0A0A8;
    transition: background 0.12s ease, color 0.12s ease;
  }

  .sidebar__link:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.06);
  }

  .sidebar__link.is-active {
    background: var(--accent);
    color: #FFFFFF;
  }

  .sidebar__summary {
    background: var(--sidebar-card);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 12.5px;
    color: #E4E4E7;
  }

  .sidebar__summary .progress-track {
    background: #323238;
    height: 6px;
    margin: 8px 0 0;
  }

  .sidebar__summary .progress-fill {
    background: var(--accent);
  }

  .main-wrap {
    max-width: 1140px;
    padding: 28px 36px 48px;
  }

  .bottom-nav-wrap {
    display: none;
  }

  .desktop-add-btn {
    display: inline-flex;
  }

  .home-top-grid {
    display: grid;
    grid-template-columns: 1.55fr 0.95fr 0.95fr;
    gap: 16px;
    margin-bottom: 18px;
  }

  .home-main-grid {
    display: grid;
    grid-template-columns: 1.55fr 1fr;
    gap: 18px;
    align-items: start;
  }

  .cal-layout {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 18px;
    align-items: start;
  }

  .store-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
  }

  .modal-backdrop--sheet {
    align-items: center;
    padding: 18px;
  }

  .sheet-card {
    border-radius: 24px;
    padding: 20px 24px 24px;
  }
}
