/* Hale dashboard. Phone first, one column, no charts.
   Colours follow Telegram's theme when opened as a mini app, else the system light/dark setting. */
:root {
  color-scheme: light;
  --bg: var(--tg-theme-secondary-bg-color, #f3f2ee);
  --surface: var(--tg-theme-bg-color, #fcfcfb);
  --text: var(--tg-theme-text-color, #0b0b0b);
  --muted: var(--tg-theme-hint-color, #5c5b57);
  --line: color-mix(in srgb, var(--text) 13%, transparent);
  --accent: var(--tg-theme-button-color, #2a78d6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --good: #0a7d0a;
  --warning: #8a5a00;
  --serious: #b0471d;
  --critical: #c22f2f;
  --radius: 14px;
  --gutter: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --text: #f0efec;
    --muted: #b4b3aa;
    --accent: #3987e5;
  }
  :root { --good: #35c235; --warning: #fab219; --serious: #ec835a; --critical: #f06a6a; }
}
:root.tg-dark { color-scheme: dark; --good: #35c235; --warning: #fab219; --serious: #ec835a; --critical: #f06a6a; }
:root.tg-light { color-scheme: light; --good: #0a7d0a; --warning: #8a5a00; --serious: #b0471d; --critical: #c22f2f; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1, h2, h3, p, blockquote { margin: 0; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- header and tabs */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 0;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button {
  flex: 1; min-height: 44px; border: 0; background: none; cursor: pointer;
  font-weight: 600; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 620px; margin: 0 auto; padding: 14px var(--gutter) 0; }
.notice {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.group-title {
  font-size: 13px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 22px 2px 8px;
}
.group-title:first-child { margin-top: 4px; }

/* ---------- card */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  -webkit-user-select: text; user-select: text;
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); }
.headline { font-size: 18px; line-height: 1.35; font-weight: 650; letter-spacing: -0.005em; text-wrap: pretty; }
.value-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-top: 10px; }
.value { font-size: 34px; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.unit { color: var(--muted); font-size: 14px; }
.lines { list-style: none; margin: 10px 0 0; padding: 0; }
.lines li { padding: 5px 0 5px 14px; position: relative; text-wrap: pretty; }
.lines li::before { content: ""; position: absolute; left: 0; top: 0.95em; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 650; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px; border: 1.5px solid currentColor;
}
.status::before { font-weight: 800; }
.status.good { color: var(--good); }       .status.good::before { content: "\2713"; }
.status.warning { color: var(--warning); } .status.warning::before { content: "!"; }
.status.serious { color: var(--serious); } .status.serious::before { content: "!!"; }
.status.critical { color: var(--critical); } .status.critical::before { content: "\00D7"; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 15px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 8px 6px 0; border-bottom: 1px solid var(--line); }
td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: break-word; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 0; padding-left: 8px; white-space: nowrap; }

.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.source { font-size: 12.5px; color: var(--muted); line-height: 1.4; overflow-wrap: anywhere; }
.ask {
  flex: none; min-height: 44px; min-width: 64px; padding: 0 14px;
  border: 1.5px solid var(--accent); border-radius: 999px; background: none; color: var(--accent);
  font-weight: 650; cursor: pointer;
}

/* ---------- recall */
.recall { display: block; width: 100%; text-align: left; cursor: pointer; }
.recall .answer-text { margin-top: 8px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.recall .hint { margin-top: 8px; color: var(--accent); font-weight: 600; font-size: 14px; }

/* ---------- links */
.chain-summary { margin-top: 6px; color: var(--muted); text-wrap: pretty; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; }
.steps li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.steps li:last-child { border-left-color: transparent; padding-bottom: 0; }
.steps li::before { content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.entity { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.live { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }
.live .muted { display: block; font-weight: 400; }

/* ---------- vault */
.day-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 2px 8px; }
.day-head:first-of-type { margin-top: 4px; }
.day-head h3 { font-size: 15px; font-weight: 650; }
.commit { display: block; width: 100%; text-align: left; cursor: pointer; background: none; border: 0; padding: 0; min-height: 44px; }
.commit .subject { font-weight: 600; text-wrap: pretty; }
.commit .meta { margin-top: 4px; }
.added { margin: 10px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.added li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.added li.path { font-size: 12.5px; color: var(--muted); border-bottom: 0; padding-bottom: 0; }
.routine { color: var(--muted); font-size: 14px; margin: 2px 2px 0; }

/* ---------- ask bar and sheet */
.askbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.askbar button, .primary {
  display: block; width: 100%; min-height: 50px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 650; font-size: 16px; cursor: pointer;
}
.primary[disabled] { opacity: 0.55; }
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 16px var(--gutter) calc(18px + env(safe-area-inset-bottom));
  max-width: 620px; margin: 0 auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-head h2 { font-size: 18px; }
.ghost { min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; }
blockquote { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; color: var(--muted); max-height: 7.5em; overflow-y: auto; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chips button { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 14.5px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; resize: vertical;
}
textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.answer { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.answer .muted { display: block; margin-top: 10px; white-space: normal; }

[hidden] { display: none !important; }
@media (prefers-reduced-motion: no-preference) {
  .sheet-body { animation: rise 160ms ease-out; }
  @keyframes rise { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
}
