/* ============ 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(72px + 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; }
.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; }

/* ============ 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; }
.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 ============ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; text-align: center; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 15px;
  padding: 14px 0; min-height: 56px; position: relative;
}
.tabs a.active { color: var(--accent); }
.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(80px + 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;
}
