/* ===========================================================
   TooLongAgo — styles
   Mobile-first, calm, minimalist. Desktop = centered phone-ish
   pane so the app feels equally at home on both.
   =========================================================== */

:root {
  /* Brand */
  --brand-1: #FFB37A;
  --brand-2: #F26B5E;

  /* Surfaces (dark default) */
  --bg: #14192B;
  --surface: #1B2238;
  --surface-2: #232C47;
  --surface-3: #2C3754;
  --border: #2B3654;
  --text: #ECEEF7;
  --text-dim: #A3AAC4;
  --text-faint: #7780A0;

  /* Semantic */
  --primary: #F26B5E;
  --primary-ink: #FFFFFF;
  --success: #28C68A;
  --danger: #E5484D;

  /* Sizing */
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
  --shadow-soft: 0 2px 10px rgba(0,0,0,0.18);

  /* Layout */
  --app-max: 480px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg: #F5F4EE;
  --surface: #FFFFFF;
  --surface-2: #F7F5EE;
  --surface-3: #EFECE3;
  --border: #E4E0D2;
  --text: #1B2238;
  --text-dim: #5A6178;
  --text-faint: #8A92A8;
  --shadow: 0 8px 30px rgba(20,25,45,0.10);
  --shadow-soft: 0 2px 10px rgba(20,25,45,0.06);
}

@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg: #F5F4EE;
    --surface: #FFFFFF;
    --surface-2: #F7F5EE;
    --surface-3: #EFECE3;
    --border: #E4E0D2;
    --text: #1B2238;
    --text-dim: #5A6178;
    --text-faint: #8A92A8;
    --shadow: 0 8px 30px rgba(20,25,45,0.10);
    --shadow-soft: 0 2px 10px rgba(20,25,45,0.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--text); }

/* ---------- App shell ---------- */
.app {
  max-width: var(--app-max);
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: calc(96px + var(--safe-bot));
  position: relative;
}

@media (min-width: 640px) {
  body {
    background:
      radial-gradient(1200px 600px at 20% -10%, rgba(242,107,94,0.10), transparent 60%),
      radial-gradient(900px 500px at 110% 110%, rgba(255,179,122,0.08), transparent 60%),
      var(--bg);
  }
  .app {
    margin-top: 32px;
    margin-bottom: 32px;
    min-height: calc(100dvh - 64px);
    background: var(--surface);
    border-radius: 28px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    padding-bottom: 112px;
  }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 28px; height: 28px; }
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}
.icon-btn {
  background: transparent;
  color: var(--text);
  border: 0;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 6px 14px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

/* ---------- Tasks list ---------- */
.tasks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 14px 24px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 4px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.section-head .count {
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
}

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.task:hover { box-shadow: var(--shadow-soft); }
.task-stripe {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--cat-color, var(--text-faint));
}
.task-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-left: 6px;
}
.task-title {
  flex: 1;
  font-weight: 600;
  font-size: 16px;
  line-height: 1.3;
  word-break: break-word;
}
.task-notes {
  padding-left: 6px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: pre-wrap;
}
.task-meta {
  padding-left: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-dim);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 999px;
}
.chip.is-cat {
  background: color-mix(in srgb, var(--cat-color) 18%, transparent);
  color: var(--cat-color);
}
.chip .dot {
  width: 7px; height: 7px; border-radius: 999px; background: currentColor;
}

.task-progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-left: 6px;
}
.task-progress > span {
  display: block;
  height: 100%;
  background: var(--cat-color, var(--brand-2));
  width: 0;
  transition: width .35s ease;
}

.task-actions {
  display: flex;
  gap: 6px;
  padding-left: 6px;
  flex-wrap: wrap;
}
.task-actions .btn { padding: 7px 12px; font-size: 13px; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-dim);
}
.empty-logo { width: 64px; height: 64px; opacity: 0.6; margin-bottom: 8px; }
.empty h2 { margin: 8px 0 4px; color: var(--text); font-size: 18px; }
.empty p { margin: 0 0 16px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 22px;
  bottom: calc(22px + var(--safe-bot));
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: white;
  border: 0;
  box-shadow: 0 10px 24px rgba(242,107,94,0.40);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: transform .15s ease;
}
.fab:active { transform: scale(0.96); }

@media (min-width: 640px) {
  .fab {
    position: absolute;
    right: 24px;
    bottom: 24px;
  }
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: var(--primary-ink);
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(242,107,94,0.30);
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn-block { width: 100%; }
.btn-success {
  background: var(--success);
  color: #04231A;
  border-color: transparent;
}

/* ---------- Onboarding ---------- */
.onboard {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #1B2238 0%, #14192B 100%);
  color: #ECEEF7;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
[data-theme="light"] .onboard,
[data-theme="auto"] .onboard {
  background:
    radial-gradient(700px 400px at 20% 0%, rgba(242,107,94,0.10), transparent 70%),
    radial-gradient(600px 400px at 100% 100%, rgba(255,179,122,0.10), transparent 70%),
    var(--bg);
  color: var(--text);
}

.onboard-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  position: relative;
}
.step { display: none; animation: fade .25s ease; }
.step.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.onboard-logo { width: 72px; height: 72px; display: block; margin: 0 auto 8px; }
.onboard-title {
  text-align: center;
  font-size: 26px;
  letter-spacing: -0.01em;
  margin: 4px 0 4px;
}
.onboard-sub {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 24px;
}
.step-title { margin: 4px 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.step-sub { margin: 0 0 16px; color: var(--text-dim); font-size: 14px; }
.step-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

.dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
}
.dots .dot {
  width: 7px; height: 7px;
  border-radius: 999px;
  background: var(--border);
  transition: width .15s ease, background .15s ease;
}
.dots .dot.is-active {
  width: 20px;
  background: var(--brand-2);
}

.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.lang-grid .lang {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}
.lang-grid .lang.is-active {
  border-color: var(--brand-2);
  background: color-mix(in srgb, var(--brand-2) 12%, var(--surface-2));
}
.lang-grid .lang small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Notification step illustration */
.notif-illustration {
  display: flex; justify-content: center; padding: 16px 0 6px;
}
.bell {
  width: 96px; height: 96px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--brand-2) 12%, transparent);
  color: var(--brand-2);
}
.celebrate { text-align: center; margin-bottom: 8px; }

/* ---------- Categories editor ---------- */
.cat-list {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 10px;
}
.cat-row {
  display: grid;
  grid-template-columns: 32px 1fr 90px 32px;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
}
.cat-row input[type="color"] {
  width: 32px; height: 32px;
  padding: 0; border: 1px solid var(--border); border-radius: 8px; background: transparent;
  cursor: pointer;
}
.cat-row input[type="text"],
.cat-row input[type="number"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  width: 100%;
}
.cat-row .pct-wrap {
  display: flex; align-items: center; gap: 4px;
}
.cat-row .pct-wrap input { text-align: right; }
.cat-row .pct-wrap span { color: var(--text-faint); font-size: 13px; }
.cat-row .del {
  background: transparent;
  color: var(--text-faint);
  border: 0; cursor: pointer;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.cat-row .del:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

/* ---------- Drawer (settings) ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
}
.drawer-scrim {
  position: absolute; inset: 0;
  background: rgba(8,10,20,0.55);
  backdrop-filter: blur(2px);
  animation: scrimIn .2s ease;
}
@keyframes scrimIn { from { opacity: 0; } to { opacity: 1; } }
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: drawerIn .22s ease;
}
@keyframes drawerIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-body {
  overflow: auto;
  padding: 16px 18px 32px;
  display: flex; flex-direction: column; gap: 22px;
}
.setting h3 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.footer-note { text-align: center; margin: 24px 0 0; }

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

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  background: transparent;
  color: var(--text-dim);
  border: 0;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.seg button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) {
  .modal { align-items: center; }
}
.modal-scrim {
  position: absolute; inset: 0;
  background: rgba(8,10,20,0.55);
  animation: scrimIn .2s ease;
}
.modal-card {
  position: relative;
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 8px 0 12px;
  box-shadow: var(--shadow);
  animation: sheetIn .22s ease;
}
@media (min-width: 640px) {
  .modal-card { border-radius: 22px; }
}
@keyframes sheetIn { from { transform: translateY(20px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 18px 8px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 18px 12px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > legend {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  outline: none;
  transition: border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: color-mix(in srgb, var(--brand-2) 60%, var(--border));
}
.field-row {
  border: 0; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  align-items: center;
}
.field-row legend {
  grid-column: 1 / -1;
  padding: 0;
  margin-bottom: 4px;
}

.modal-actions {
  display: flex; gap: 8px; align-items: center;
  padding-top: 6px;
}

/* Toggle (switch style) */
.toggle, .toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input, .toggle-field input { display: none; }
.toggle-slider {
  position: relative;
  width: 40px; height: 22px;
  background: var(--surface-3);
  border-radius: 999px;
  transition: background .15s ease;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked ~ .toggle-slider,
.toggle-field input:checked ~ .toggle-slider {
  background: var(--brand-2);
}
.toggle input:checked ~ .toggle-slider::after,
.toggle-field input:checked ~ .toggle-slider::after {
  transform: translateX(18px);
}
.toggle-label { font-size: 14px; color: var(--text); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bot));
  transform: translate(-50%, 30px);
  background: var(--surface-3);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* ---------- Utility ---------- */
[hidden] { display: none !important; }
