/* ============ Colors (light + dark) ============ */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #d8d8dc;
  --accent: #0a66d8;
  --red: #d70015;
  --amber: #b25000;
  --green: #1a7f37;
  --chip: #e5e5ea;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: #38383a;
    --accent: #4a9eff;
    --red: #ff6961;
    --amber: #ffb340;
    --green: #4cd964;
    --chip: #2c2c2e;
  }
}

/* ============ Basics ============ */
* { 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;
  /* room for the notch on top and the tab bar + home indicator at the bottom */
  padding: env(safe-area-inset-top) 0 calc(84px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 28px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 8px; }
.view { max-width: 700px; margin: 0 auto; padding: 0 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.error { color: var(--red); }

/* ============ Inputs & buttons (44px+ tap targets) ============ */
input, select, textarea {
  font: inherit;            /* 16px+ stops iOS from zooming in on focus */
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
}
textarea { min-height: 100px; resize: vertical; }
.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--chip);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.btn.big { width: 100%; margin-top: 8px; min-height: 50px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; }
.icon-btn {
  font: inherit; font-size: 22px;
  background: none; border: 0; color: var(--accent);
  min-width: 44px; min-height: 44px; cursor: pointer;
}
.icon-btn.back { font-size: 17px; padding-left: 0; text-align: left; }

/* ============ Top bar & filters ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0 8px;
}
.filters { position: sticky; top: 0; background: var(--bg); padding: 4px 0 8px; z-index: 2; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.chip {
  font: inherit; font-size: 15px;
  border: 0; border-radius: 999px;
  background: var(--chip); color: var(--text);
  padding: 8px 14px; min-height: 40px; white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; }
.filter-row { display: flex; gap: 8px; }
.filter-row select { width: 40%; }

/* ============ Cards ============ */
.list { list-style: none; margin: 0; padding: 0; }
.card {
  background: var(--card);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
  border-left: 4px solid transparent;
}
.card.unread { border-left-color: var(--accent); }
.card.unread .card-title { font-weight: 700; }
.card-main { padding: 12px 14px 6px; cursor: pointer; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.card-meta .time { margin-left: auto; }
.card-title { font-size: 17px; font-weight: 500; margin: 4px 0 2px; }
.card-preview {
  color: var(--muted); font-size: 15px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tag {
  font-size: 12px; font-weight: 600;
  background: var(--chip); color: var(--text);
  border-radius: 6px; padding: 2px 6px;
}
.tag.alert { background: var(--red); color: #fff; }
.tag.question { background: var(--accent); color: #fff; }
.pin { font-size: 13px; }

/* Row of big action buttons under each card */
.card-actions { display: flex; border-top: 1px solid var(--line); }
.card-actions button {
  flex: 1; font: inherit; font-size: 14px; font-weight: 600;
  background: none; border: 0; color: var(--accent);
  min-height: 48px; cursor: pointer;
}
.card-actions button + button { border-left: 1px solid var(--line); }

/* ============ Detail ============ */
#detail { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 16px; }
#detail h1 { font-size: 22px; margin: 8px 0; }
.md { overflow-wrap: anywhere; }
.md pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 8px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.md img { max-width: 100%; }
.link-buttons { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.todo-form { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0; }
.todo-form label { display: flex; align-items: center; gap: 8px; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.reply-box { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 8px 0; white-space: pre-wrap; }
.waiting { color: var(--amber); font-weight: 600; }
.thread-item { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }

/* ============ Today ============ */
.today-status { margin: 0 0 12px; font-size: 15px; color: var(--muted); }
.today-status p { margin: 0; }
.today-coach { display: flex; flex-direction: column; gap: 4px; background: var(--card); border-radius: 14px; margin-bottom: 10px; padding: 12px 14px; color: inherit; text-decoration: none; }
.today-coach-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.today-section { background: var(--card); border-radius: 14px; margin-bottom: 10px; padding: 0 14px; }
.today-section > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; font-weight: 700; cursor: pointer; list-style: none;
}
.today-section > summary::-webkit-details-marker { display: none; }
.today-section > summary::after { content: "›"; color: var(--muted); font-size: 22px; transition: transform .15s; }
.today-section[open] > summary::after { transform: rotate(90deg); }
.today-section > summary .count { margin-left: auto; color: var(--muted); font-weight: 600; font-size: 15px; }
.today-section .md { font-size: 15px; padding-bottom: 4px; }
.today-section .md ul { padding-left: 20px; margin: 4px 0; }
.today-section .updated { font-size: 12px; margin: 4px 0 10px; }
.today-section .attention .card { background: var(--bg); }
.todos .todo { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.todos .todo:first-child { border-top: 0; }
.tick {
  flex: none; width: 28px; height: 28px; margin: 2px 0;
  border: 2px solid var(--muted); border-radius: 50%; background: none;
  color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
  /* 44px tap area around a 28px circle */
  box-shadow: 0 0 0 8px transparent; outline-offset: 8px;
}
.todo.done .todo-title { text-decoration: line-through; color: var(--muted); }
.todo-body { flex: 1; min-width: 0; }
.todo-title { font-size: 16px; overflow-wrap: anywhere; }
.todo-title a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.today-section .md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.today-section[data-key="now_next"] .md p { margin: 10px 0 2px; }
.today-section[data-key="now_next"] .md ul { margin: 0 0 6px; }
.tick.pick, .tick-static { border-radius: 7px; }
.tick.pick.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tick-static { display: inline-flex; align-items: center; justify-content: center; opacity: .6; }
.todo.push.answered .todo-title a { color: var(--muted); }
#run-pushes { margin-bottom: 4px; }
.todo-meta { font-size: 13px; color: var(--muted); }
.todo-warn { font-size: 13px; color: var(--amber); }
/* Done / Snooze / Cancel: three matching buttons; a lone Undo keeps the same width */
.todo-actions { display: flex; gap: 8px; margin-top: 8px; }
.todo-actions .btn.small { flex: 1 1 0; max-width: calc((100% - 16px) / 3); min-height: 44px; }
.sheet h2 { margin: 0 0 4px; }
.sheet .hint { margin: 0 0 8px; overflow-wrap: anywhere; }
.task-date { display: block; margin-top: 16px; font-size: 14px; color: var(--muted); }
.task-date input { display: block; width: 100%; margin-top: 4px; box-sizing: border-box; }
.decides .decide { padding: 10px 0; border-top: 1px solid var(--line); }
.decides .decide:first-child { border-top: 0; }
.decide-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.decide-buttons .btn { flex: 1; min-width: 90px; }

/* ============ Runs ============ */
.run { background: var(--card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; display: flex; gap: 12px; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.dot.fail { background: var(--red); }
.dot.warn { background: var(--amber); }
.dot.ok { background: var(--green); }
.run-body { flex: 1; min-width: 0; }
.run-top { display: flex; justify-content: space-between; gap: 8px; }
.run-summary { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }

/* ============ Settings ============ */
.panel { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 12px; }

/* ============ Login ============ */
.login { display: flex; flex-direction: column; gap: 10px; max-width: 360px; margin: 15vh auto 0; text-align: center; }
.login-icon { width: 72px; height: 72px; border-radius: 16px; margin: 0 auto; }

/* ============ Bottom tab bar ============ */
/* Same shape as the other Fougere apps (Fuel Log, Pantry, Rebuild Coach, The Quiet Circle, Apothecary):
   line icons, a soft pill on the current tab, count badge on the icon. Colors stay Inbox's own. */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 4px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; max-width: 180px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: 6px 4px; border-radius: 12px;
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 12px;
}
.tabs svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.tabs .badge { position: absolute; top: 3px; left: calc(50% + 6px); min-width: 18px; padding: 0 5px; font-size: 11px; font-weight: 700; }
.badge {
  display: inline-block; min-width: 20px; padding: 1px 6px;
  border-radius: 999px; background: var(--red); color: #fff;
  font-size: 12px; line-height: 18px;
}

/* ============ Snooze sheet & toast ============ */
.sheet {
  border: 0; border-radius: 16px 16px 0 0;
  width: 100%; max-width: 700px;
  margin: auto auto 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--card); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .4); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 15px; z-index: 10;
  white-space: nowrap;
}

/* Today's "↻ Sync" button: text, so a smaller size than the icon buttons */
#refresh-today, #claude-refresh { font-size: 16px; font-weight: 600; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.topbar-actions { display: inline-flex; gap: 4px; align-items: center; }
#refresh-today:disabled { opacity: .6; }

.todo.push { align-items: center; }
.todo.push.skipped .todo-title a { color: var(--muted); text-decoration: line-through; }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: 14px; flex: none; }

/* Today: Sync left, title centered, Refresh right */
.today-bar { display: grid; grid-template-columns: 1fr minmax(0, auto) 1fr; gap: 8px; }
.today-bar #refresh-today { justify-self: start; }
.today-bar #claude-refresh { justify-self: end; }
.today-bar h1 { text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
