:root {
  --bg: #f3f7f8;
  --surface: #ffffff;
  --text: #10282d;
  --muted: #5b7176;
  --border: #d5e0e2;
  --accent: #0e7490;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #157f3b;
  --input-bg: #ffffff;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1416;
    --surface: #142226;
    --text: #e6f1f3;
    --muted: #93aab0;
    --border: #26393e;
    --accent: #22a6c3;
    --accent-text: #04191e;
    --danger: #ff8a80;
    --ok: #6ee79a;
    --input-bg: #0f1b1e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding:
    env(safe-area-inset-top)
    calc(16px + env(safe-area-inset-right))
    calc(32px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.app-header h1 {
  margin: 16px 0 12px;
  font-size: 30px;
  letter-spacing: -0.02em;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-actions[hidden] { display: none; }

/* Sync indicator */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.sync-status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}
.sync-status[data-state="synced"] { color: var(--ok); }
.sync-status[data-state="offline"] { color: var(--danger); }

.link-button {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 10px;
}
.link-button.wide { width: 100%; margin-top: 8px; }

.loading, .intro { color: var(--muted); }
.intro { margin: 0 0 14px; }
.intro strong { color: var(--text); overflow-wrap: anywhere; }
.notice {
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: var(--text);
}

main {
  max-width: 560px;
  margin: 0 auto;
}
.app-header { max-width: 560px; margin: 0 auto; }

h2 {
  font-size: 20px;
  margin: 28px 0 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* Totals */
.totals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.total {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.total-label { font-size: 14px; color: var(--muted); }
.total-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.total-sub { font-size: 14px; color: var(--muted); }

/* Form */
form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  min-width: 0;
}
form label > span { font-size: 15px; font-weight: 600; color: var(--muted); }
form label em { font-weight: 400; font-style: normal; }

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

input, textarea {
  /* 16px+ prevents iOS from zooming on focus */
  font: inherit;
  font-size: 18px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 50px;
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}
/* iOS renders date/time inputs oddly without these */
input[type="date"], input[type="time"] {
  display: block;
  text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; }
textarea { resize: vertical; }

input:focus, textarea:focus, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.error {
  color: var(--danger);
  margin: 0 0 12px;
  font-weight: 600;
}

.log-button {
  width: 100%;
  min-height: 60px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 21px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.log-button:active { transform: scale(0.985); filter: brightness(0.95); }

/* History */
.empty { color: var(--muted); }

.soak-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.soak {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.soak-body { flex: 1; min-width: 0; }
.soak-when { font-weight: 600; }
.soak-stats { color: var(--muted); font-variant-numeric: tabular-nums; }
.soak-notes {
  margin-top: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.delete-button {
  flex: none;
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.delete-button:active { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ---- Fougere home (launcher.js): tiles + bottom bar, same shape as the other Fougere apps ---- */
body { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
body:not([data-current="soak"]) #header-actions { display: none; } /* sync status belongs to the soak log */
.greeting { color: var(--muted); margin: 0 0 12px; }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.tile-group { margin: 18px 0 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.tile-group:first-child { margin-top: 0; }
.today { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.today li + li { border-top: 1px solid var(--border); }
.today-row { display: flex; gap: 12px; padding: 11px 14px; min-height: 44px; box-sizing: border-box; color: var(--text); text-decoration: none; }
.today-label { flex: 0 0 76px; color: var(--muted); font-size: 15px; }
.today-value { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.today-value.hot { color: var(--accent); }
.today-row::after { content: "\203A"; color: var(--muted); font-size: 18px; line-height: 1.2; }
.tile {
  display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.tile:active { transform: scale(.99); }
.tile-icon {
  flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--app) 14%, transparent); color: var(--app);
}
@media (prefers-color-scheme: dark) { .tile-icon { color: color-mix(in srgb, var(--app) 55%, white); background: color-mix(in srgb, var(--app) 30%, transparent); } }
.tile-icon svg, .tabbar svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tile-name { font-weight: 700; }
.tile-glance { color: var(--muted); font-size: 15px; }
.tile-glance.hot { color: var(--accent); font-weight: 600; }
.tile-go { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; margin: 14px 2px 0; }
.account p { margin: 0 0 12px; }
.log-button.secondary { background: transparent; color: var(--danger); border: 1px solid var(--border); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
}
.tabbar[hidden] { display: none; }
.tabbar button, .tabbar .tabbtn { text-decoration: none;
  flex: 1; max-width: 180px; min-height: 56px; padding: 6px 4px; border: 0; border-radius: 12px; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabbar button[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* Soak log tabs: Log shows the form, History shows past soaks; totals on both */
#tiles { margin-top: 0; }
.account + .account { margin-top: 12px; }

/* ---- Tasks ---- */
#page-title { margin-bottom: 8px; }
.sub { color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.group { margin: 18px 0 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.group.over { color: var(--danger); }
.tasks { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tasks li + li { border-top: 1px solid var(--border); }
.t { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; min-height: 52px; }
.t .check { flex: none; width: 30px; height: 30px; margin-top: 2px; border-radius: 50%; border: 2px solid var(--muted); background: transparent; padding: 0; color: var(--ok); font-size: 18px; line-height: 1; cursor: pointer; }
.t .check:active { background: var(--ok); }
.t .body { flex: 1; min-width: 0; color: var(--text); text-decoration: none; }
.t .title { font-weight: 600; overflow-wrap: anywhere; }
.t .meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.t .meta .late { color: var(--danger); font-weight: 600; }
.t .meta .hi { color: var(--accent); font-weight: 600; }
.t .snooze { flex: none; background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 4px 8px; font-size: 13px; margin-top: 4px; }
.empty { color: var(--muted); padding: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.form input, .form select, .form textarea { font: inherit; color: var(--text); background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; width: 100%; }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.form button { font: inherit; border-radius: 10px; padding: 11px 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.form button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.form button.danger { color: var(--danger); }
.err { color: var(--danger); margin: 8px 0 0; }
.areas { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.areas a { display: flex; justify-content: space-between; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 600; }
.areas span { color: var(--muted); font-weight: 400; }
