:root {
  --ink: #1d1d1f;
  --muted: #45454c;
  --faint: #6e6e73;
  --line: #e2e2e0;
  --bg: #f5f5f4;
  --surface: #ffffff;
  --accent: #0068d1;
  --accent-soft: #e8f1fc;
  --good: #1c7c3f;
  --good-soft: #e3f4e9;
  --warn: #9a6700;
  --warn-soft: #fbf1d9;
  --danger: #b3261e;
  --danger-soft: #fbe6e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 8px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar — graphite, matching the plugin admin's header language */
.topbar {
  background: linear-gradient(180deg, #26262b, #1d1d21);
  border-bottom: 1px solid #111114;
  position: sticky; top: 0; z-index: 100;
}
.topbar-inner {
  max-width: 1140px; margin: 0 auto; padding: 0 24px; height: 58px;
  display: flex; align-items: center; gap: 28px;
}
.topbar .brand {
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em; color: #f4f4f6;
  display: inline-flex; align-items: center; gap: 9px; white-space: nowrap;
}
.topbar .brand span { color: #4da3ff; }
.topbar .brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; max-width: 140px; border-radius: 6px; display: block; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  color: #c2c2c7; font-size: 13.5px; font-weight: 600; padding: 7px 13px;
  border-radius: 8px; transition: background .12s, color .12s;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.mainnav a.active { color: #fff; background: rgba(255,255,255,.14); }
.topbar .right { display: flex; align-items: center; gap: 10px; }
.topbar form { margin: 0; }
.user-chip {
  display: flex; align-items: center; gap: 9px; padding: 5px 10px 5px 5px;
  border-radius: 10px; transition: background .12s;
}
.user-chip:hover, .user-chip.active { background: rgba(255,255,255,.1); text-decoration: none; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 14px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { color: #f4f4f6; font-size: 13px; font-weight: 600; }
.user-org { color: #c2c2c7; font-size: 11.5px; }
.signout {
  background: none; border: none; color: #c2c2c7; font-size: 17px; cursor: pointer;
  padding: 7px 9px; border-radius: 8px; line-height: 1;
}
.signout:hover { color: #fff; background: rgba(255,255,255,.1); }
@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
  .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .user-meta { display: none; }
}

.wrap { max-width: 1140px; margin: 0 auto; padding: 32px 24px 80px; }

.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-head p { color: var(--muted); margin: 0; }

/* Stat tiles */
.stats { display: flex; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 140px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 13px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }

/* Cards & tables */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: #fafaf9;
}
td { padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f7f7f5; }
select {
  font-family: inherit; color: var(--ink); background: #fff;
}
.site-name { font-weight: 600; color: var(--ink); }
.site-url { color: var(--faint); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6;
}
.badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--good-soft); color: var(--good); }
.badge.neutral { background: #eee; color: var(--muted); }
.badge.count { background: var(--accent-soft); color: var(--accent); }
.badge.high { background: var(--danger-soft); color: var(--danger); }

.muted { color: var(--faint); }
.empty { padding: 40px 16px; text-align: center; color: var(--faint); }

.backlink { display: inline-block; margin-bottom: 12px; font-size: 14px; }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 36px; width: 100%; max-width: 380px;
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-card h1 span { color: var(--accent); }
.login-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input[type=email], .field input[type=password],
.field input[type=text], .field input[type=url], .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cfcfcd; border-radius: 8px;
  font-size: 15px; background: #fff; color: var(--ink); font-family: inherit;
}
.field textarea { resize: vertical; }
.field input[type=file] { font-size: 14px; }
.field input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.btn {
  width: 100%; padding: 11px; border: none; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .12s, transform .06s;
}
.btn:hover { background: #0058b0; }
.btn:active { transform: scale(.985); }
.error { color: var(--danger); font-size: 13px; margin-top: 6px; }
.hint { margin-top: 18px; font-size: 12.5px; color: var(--faint); text-align: center; }
.hint-left { font-size: 12.5px; color: var(--faint); margin: 6px 0 0; }

/* Flash + header row + buttons */
.flash {
  background: var(--good-soft); border: 1px solid #bfe3cb; color: var(--good);
  padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; font-size: 14px;
}
.flash.error { background: var(--danger-soft); border-color: #f0c4c1; color: var(--danger); }
.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.btn-inline {
  background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 14px; font-weight: 600; white-space: nowrap; border: none; cursor: pointer;
  transition: background .12s, transform .06s;
}
.btn-inline:hover { background: #0058b0; text-decoration: none; }
.btn-inline:active { transform: scale(.985); }
.btn-secondary {
  background: #fff; color: var(--ink); border: 1px solid #cfcfcd; padding: 8px 14px;
  border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-secondary:hover { background: #f5f5f4; border-color: #b9b9b7; text-decoration: none; }
.form-card { padding: 24px; max-width: 520px; }
.section-h { font-size: 15px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin: 28px 0 10px; }

/* Connection panel */
.conn { padding: 22px; margin-bottom: 8px; }
.conn-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.conn-head h2 { margin: 0; font-size: 18px; }
.code-box {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  background: #f5f5f4; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; font-size: 14px; word-break: break-all; color: var(--ink);
}
.code-box.big {
  font-size: 24px; font-weight: 600; letter-spacing: 0.08em; text-align: center;
  padding: 16px; background: var(--accent-soft); border-color: #bcd8f5; color: var(--accent);
}
.kv { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.kv > span { flex: 0 0 90px; font-size: 13px; font-weight: 600; color: var(--muted); }
.kv > .code-box { flex: 1; }
.manual { margin: 16px 0; }
.manual summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--accent); }
.manual[open] summary { margin-bottom: 10px; }

/* Per-comment feedback breakdown (richer sync) */
.cmt-meta { font-size: 12px; color: var(--faint); margin-top: 4px; }
.cmt-row > td { padding-top: 0; }
.cmt-row details { margin: 2px 0 6px; }
.cmt-row summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent);
  list-style: none; padding: 4px 0;
}
.cmt-row summary::-webkit-details-marker { display: none; }
.cmt-row summary::before { content: "▸ "; }
.cmt-row details[open] summary::before { content: "▾ "; }
.cmt-list { list-style: none; margin: 6px 0 4px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cmt {
  display: grid; grid-template-columns: 150px 1fr auto; gap: 12px; align-items: start;
  background: #fafaf9; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}
.cmt.is-resolved { opacity: 0.62; }
.cmt-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.cmt-body { font-size: 14px; color: var(--ink); line-height: 1.45; word-break: break-word; }
.cmt-note { font-size: 13px; color: var(--muted); margin-top: 4px; }
.cmt-strike { text-decoration: line-through; color: var(--danger); }
.cmt-arrow { color: var(--faint); margin: 0 4px; }
.cmt-new { color: var(--good); font-weight: 600; }
.cmt-icons { display: flex; gap: 8px; font-size: 13px; color: var(--faint); white-space: nowrap; }
@media (max-width: 640px) {
  .cmt { grid-template-columns: 1fr; gap: 6px; }
}

/* Two-way action controls on comments + page status */
.linkbtn {
  background: none; border: none; padding: 0; margin: 0; cursor: pointer;
  color: var(--accent); font-size: 12px; font-weight: 600; font-family: inherit;
}
.linkbtn:hover { text-decoration: underline; }
.linkbtn.ok { color: var(--good); }
.status-actions { display: flex; gap: 12px; margin-top: 6px; }
.cmt-actions { grid-column: 1 / -1; display: flex; gap: 16px; align-items: flex-start; margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.reply-d summary { list-style: none; }
.reply-d summary::-webkit-details-marker { display: none; }
.reply-form { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; max-width: 460px; }
.reply-form textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfcfcd; border-radius: 8px;
  font-family: inherit; font-size: 13px; resize: vertical;
}
.reply-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.reply-form button { align-self: flex-start; }

/* Care-plan usage meter */
.meter { height: 10px; background: #ececea; border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.meter-fill.over { background: var(--danger); }
.meter-fill.done { background: var(--good); }

/* Markups — annotation stage */
.mk-stage { margin-bottom: 22px; }
.mk-page-label { font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.mk-frame {
  position: relative; width: 100%; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); min-height: 60px;
}
.mk-media { display: block; width: 100%; }
img.mk-media { height: auto; }
/* URL markups: the annotation-proxy iframe sizes itself to the page height
   via postMessage; block layout, no aspect-ratio box. */
.mk-iframe { display: block; width: 100%; height: 1400px; border: 0; background: #fff; }
/* Pin/popup/toolbar/shape styles live in mk-annotate.css (shared with the
   proxied-page runtime and the client share page). */
#mk-toolbar-mount { position: sticky; top: 10px; z-index: 50; margin-bottom: 16px; }
.sharelink-box { display: flex; gap: 8px; align-items: center; }
.sharelink-box input {
  width: 300px; max-width: 44vw; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; color: var(--muted); background: var(--surface);
}

/* Danger zone */
.danger-zone { margin-top: 30px; }
.danger-zone > summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--danger);
  user-select: none; width: fit-content;
}

/* Tasks */
.task-row { display: flex; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.task-row:last-child { border-bottom: none; }
.task-row.overdue { background: #fdf3f2; }
.task-title { font-weight: 600; font-size: 14px; }
.task-title.is-done { text-decoration: line-through; color: var(--faint); font-weight: 500; }
.task-details { font-size: 13px; color: var(--muted); margin-top: 3px; }
.task-meta { font-size: 12.5px; color: var(--faint); margin-top: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.task-meta a { font-size: 12.5px; }
.due-over { color: var(--danger); font-weight: 600; }
.task-actions { display: flex; gap: 12px; align-items: center; white-space: nowrap; flex-shrink: 0; }
@media (max-width: 640px) { .task-row { flex-direction: column; } }
