:root {
  color-scheme: light;
  --ink: #22262B;
  --ink-2: #3A4047;
  --muted: #5F666D;
  --faint: #8A9096;
  --line: #ECECEA;
  --line-2: #DCDDDA;
  --bg: #FFFFFF;
  --side: #F4F4F2;
  --side-on: #E4E5E2;
  --accent: #0E7C7B;
  --accent-dark: #0A5F5E;
  --accent-soft: #E3F2F1;
  --amber: #8F5300;
  --amber-bg: #FFF4E0;
  --personal: #6A4C9C;
  --personal-bg: #F1ECF9;
  --ok: #17703F;
  --ok-bg: #E7F4EC;
  --risk: #8F5300;
  --risk-bg: #FDF1DC;
  --bad: #B4302A;
  --bad-bg: #FBE9E7;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #7CC4C3; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.loading { padding: 48px 24px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- app frame ---------- */
.app { display: flex; min-height: 100vh; }
.side { width: 264px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line); padding: 22px 12px 18px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--ink); text-decoration: none; font-size: 15px; min-height: 36px; }
.side a:hover { background: #EAEAE7; }
.side a[aria-current="page"] { background: var(--side-on); font-weight: 600; }
.side a .n { margin-left: auto; font-size: 13px; color: var(--muted); font-weight: 500; }
.side a .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.side .lbl { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 20px 10px 4px; text-transform: uppercase; letter-spacing: .06em; }
.side .lbl button { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; }
.side .lbl button:hover { background: #EAEAE7; color: var(--ink); }
.side .bottom { margin-top: auto; padding-top: 16px; }
.main { flex: 1; min-width: 0; padding: 48px 64px 96px; }
.content { max-width: 820px; }
.tabs { display: none; }

/* ---------- headings ---------- */
.view-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.view-head h1 { font-size: 32px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; }
.view-sub { color: var(--muted); margin: 4px 0 24px; }
.view-sub.indent { margin-left: 44px; }
.head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #F7F7F5; color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--bad); border-color: #F0B8B3; }
.btn-danger:hover { background: var(--bad-bg); color: #8E221D; }
.btn-big { min-height: 50px; font-size: 16px; border-radius: 10px; padding: 0 20px; }
.btn-link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 14px; }
.btn[disabled] { opacity: .6; cursor: default; }

/* ---------- forms ---------- */
label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; color: var(--ink);
}
select { padding: 0 10px; }
textarea { resize: vertical; min-height: 80px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.form-error { color: var(--bad); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }

/* segmented choice (When / Status / Type) */
.seg { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0; }
.seg legend { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.seg label { position: relative; font-weight: 500; font-size: 14px; color: var(--ink); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 999px; cursor: pointer; background: #fff; }
.seg input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid #7CC4C3; outline-offset: 2px; }
.seg.health-seg input[value="on_track"]:checked + span { background: var(--ok); border-color: var(--ok); }
.seg.health-seg input[value="at_risk"]:checked + span { background: #A86400; border-color: #A86400; }
.seg.health-seg input[value="blocked"]:checked + span { background: var(--bad); border-color: var(--bad); }

/* ---------- quick add ---------- */
.quick { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; padding: 6px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.quick .ring { width: 20px; height: 20px; border: 1.6px dashed #B4B8BC; border-radius: 50%; margin-top: 11px; flex-shrink: 0; }
.quick textarea { flex: 999 1 260px; border: 0; padding: 9px 2px; min-height: 42px; height: 42px; resize: none; overflow: hidden; line-height: 1.5; font-size: 16px; }
.quick textarea:focus { outline: none; }
.quick select { flex: 1 1 180px; width: auto; min-height: 40px; font-size: 14px; color: var(--ink-2); }
.quick .btn { min-height: 40px; }
.quick .hint { flex-basis: 100%; margin: -6px 0 0 30px; }
.quick .form-error { flex-basis: 100%; margin-left: 30px; }
textarea[data-enter-submit] { resize: none; overflow: hidden; }

/* ---------- task rows ---------- */
.group { margin-bottom: 26px; }
.group-head { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.group-head a { color: var(--ink); text-decoration: none; }
.group-head a:hover { text-decoration: underline; }
.group-head.doctors { color: var(--amber); }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 4px 0; }
.chk { width: 22px; height: 22px; margin-top: 9px; border: 1.6px solid #A9AEB3; border-radius: 50%; background: #fff; flex-shrink: 0; cursor: pointer; padding: 0; position: relative; }
.chk:hover { border-color: var(--accent); }
.chk[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.chk[aria-pressed="true"]::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.task-body { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 6px; margin: 0 -6px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.task-body:hover { background: #F7F7F5; }
.task-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.task-title { overflow-wrap: anywhere; }
.task-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 8px; }
.task.done .task-title { text-decoration: line-through; color: var(--faint); }
.task-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.when.late { color: var(--bad); font-weight: 600; }
.when.soon { color: #A35200; font-weight: 600; }
.tag { font-size: 12px; font-weight: 600; border-radius: 4px; padding: 1px 7px; white-space: nowrap; }
.tag-doctor { color: var(--amber); background: var(--amber-bg); }
.tag-personal { color: var(--personal); background: var(--personal-bg); }
.tag-waiting { color: #5B4A00; background: #F3EDCF; }
.tag-pri { color: var(--bad); background: var(--bad-bg); }
.empty { padding: 28px 0; color: var(--muted); }
.empty strong { color: var(--ink); display: block; margin-bottom: 4px; font-size: 16px; }

/* ---------- health ---------- */
.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.health::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.h-on_track { color: var(--ok); background: var(--ok-bg); }
.h-at_risk { color: var(--risk); background: var(--risk-bg); }
.h-blocked { color: var(--bad); background: var(--bad-bg); }

/* ---------- panels ---------- */
.panel { border: 1px solid var(--line-2); border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.panel h2 { font-size: 16px; font-weight: 700; }
.panel.personal { background: var(--personal-bg); border-color: #DCD0EE; color: var(--personal); font-size: 14px; }
.panel-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.panel-row .field { flex: 999 1 260px; }
.desc { white-space: pre-wrap; color: var(--muted); margin-bottom: 18px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.activity { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 30px 0 10px; }

/* ---------- project list (phone "Projects" tab) ---------- */
.plist { list-style: none; margin: 0 0 24px; padding: 0; }
.plist a { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.plist a .name { flex: 1; min-width: 0; }
.plist a small { display: block; color: var(--muted); font-size: 13px; }

/* ---------- send update ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 999px; background: #fff; font-size: 14px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.pick { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.pick input { width: 22px; height: 22px; accent-color: var(--accent); margin: 2px 0 0; flex-shrink: 0; }
.pick label { flex: 1; font-weight: 400; font-size: 15px; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.pick label b { font-weight: 700; }
.pick .warn { color: var(--bad); font-size: 13px; }
.email { border: 1px solid var(--line-2); border-radius: 12px; overflow: hidden; }
.email-head { background: #F7F7F5; padding: 12px 18px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line-2); }
.email-head b { color: var(--ink); }
.email-body { padding: 18px; font-size: 15px; }
.send-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ---------- settings ---------- */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rows li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.steps summary { cursor: pointer; font-weight: 600; color: var(--accent); min-height: 32px; }
.steps ol { padding-left: 22px; display: flex; flex-direction: column; gap: 10px; color: var(--ink-2); font-size: 14px; }
.steps ul { padding-left: 18px; margin: 6px 0 0; display: flex; flex-direction: column; gap: 4px; }
code.block { display: block; overflow-wrap: anywhere; background: #F2F3F1; border-radius: 6px; padding: 8px 10px; font-size: 13px; margin: 6px 0; }
.keybox { background: var(--accent-soft); border: 1px solid #B5DCDA; border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--side); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line-2); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.auth-card h1 { font-size: 24px; font-weight: 800; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(540px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 50px rgba(20, 24, 28, .25); }
dialog::backdrop { background: rgba(20, 24, 28, .4); }
dialog form { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
dialog h2 { font-size: 19px; font-weight: 800; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.dialog-actions .spacer { flex: 1; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.show { opacity: 1; }
#toast.error { background: var(--bad); }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .side { display: none; }
  .main { padding: 24px 18px 110px; }
  .view-head h1 { font-size: 28px; }
  .view-sub.indent { margin-left: 40px; }
  .tabs { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line); padding: 6px 4px calc(10px + env(safe-area-inset-bottom)); z-index: 10; }
  .tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; min-height: 48px; justify-content: center; position: relative; }
  .tabs a[aria-current="page"] { color: var(--ink); font-weight: 700; }
  .tabs .badge { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 0 5px; min-width: 16px; text-align: center; }
  #toast { bottom: 96px; }
  .quick textarea { flex: 1 1 calc(100% - 40px); }
  .quick select { flex: 1 1 0; margin-left: 30px; min-width: 0; }
  .quick .hint { display: none; }
}

/* ---------- small utilities ---------- */
.pie { flex-shrink: 0; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; }
.full { flex-basis: 100%; }
.span-all { grid-column: 1 / -1; }
.field-end { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.email-body p { margin: 0 0 12px; }
.em-sum { background: #F5F6F7; padding: 10px 14px; border-radius: 6px; }
.em-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.em-row .health { margin-top: 2px; min-width: 84px; }
.em-row:last-of-type { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.em-ask { border-left: 3px solid var(--risk); padding-left: 10px; }
.pick .btn { min-height: 34px; font-size: 13px; }
