/* Fieldnote Studio — responsive styles (390 / 768 / 1280) */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e3e6ec;
  --brand: #0a58ca;
  --brand-dark: #0845a0;
  --ok: #0a7d3a;
  --err: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 4px 14px rgba(16, 24, 40, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
.hidden { display: none !important; }
.app { min-height: 100vh; display: flex; flex-direction: column; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #7c3fd9);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.demo-nav-link { margin-left: auto; margin-right: 14px; color: var(--brand); font-size: 12px; font-weight: 600; text-decoration: none; }
.demo-nav-link:hover { text-decoration: underline; }
.account-menu { display: flex; align-items: center; }
.account-row { display: flex; align-items: center; gap: 10px; }
.actor-email { font-size: 13px; color: var(--ink); font-weight: 600; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor-role {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #eef2ff; color: var(--brand); text-transform: capitalize;
}

/* Buttons */
.btn {
  font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-size: 14px; transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #f1f3f7; }
.btn-danger { background: transparent; color: var(--err); border-color: var(--err); }
.link { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 13px; text-decoration: underline; }

/* Main */
.main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.view h1 { font-size: 22px; margin: 6px 0 16px; }

/* Tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  font: inherit; cursor: pointer; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Form cards */
.form-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.form-card h2, .form-card h3 { margin-top: 0; font-size: 15px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; align-items: center; gap: 6px; margin: 10px 0; color: var(--ink); font-size: 14px; }
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid rgba(10, 88, 202, 0.35); border-color: var(--brand); }
textarea { resize: vertical; }
.form-error {
  margin-top: 10px; padding: 8px 12px; border-radius: 8px;
  background: #fdecea; color: var(--err); border: 1px solid #f5b8b3; font-size: 13px;
}
.form-actions { margin-top: 14px; }
.form-links { display: flex; gap: 14px; margin-top: 10px; }

/* Brand list — cards are semantic <button> elements (Tab-focusable). */
.brand-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.brand-card {
  font: inherit; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
}
.brand-card:hover, .brand-card:focus-visible { border-color: var(--brand); box-shadow: var(--shadow); outline: none; }
.brand-card:focus-visible { outline: 3px solid rgba(10, 88, 202, 0.45); }
.brand-card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(10, 88, 202, 0.25); }
.brand-card .bb-name { font-weight: 700; font-size: 15px; }
.brand-card .bb-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Fact list */
.fact-list { margin-bottom: 16px; }
.fact-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 8px;
}
.fact-item .f-body { min-width: 0; }
.fact-item .f-key { font-weight: 700; font-size: 14px; }
.fact-item .f-val { font-size: 13px; color: var(--ink); word-break: break-word; margin-top: 2px; white-space: pre-wrap; }
.fact-item .f-meta { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }

/* Reply to customer */
.reply-card { border-left: 4px solid var(--brand); }
.reply-hint { font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.reply-result { margin-top: 12px; }
.reply-text {
  background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word;
  margin-top: 4px;
}
.reply-guidance-text {
  font-size: 12px; color: var(--muted); font-style: italic;
  white-space: pre-wrap; word-break: break-word; margin: 6px 0 0;
}
.reply-actions { display: flex; gap: 10px; margin-top: 8px; }
.reply-history { margin-top: 14px; font-size: 13px; color: var(--muted); }
.reply-history summary { cursor: pointer; }
.reply-history-list { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.history-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  background: var(--card);
}
.history-item .h-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.history-item .h-q { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.history-item .h-reply { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.history-item .badge { margin-left: 6px; }
.empty-note { color: var(--muted); font-size: 12px; padding: 6px 0; }

/* Language toggle */
.lang-toggle { min-width: 44px; font-weight: 600; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.badge.ok { background: #e7f7ee; color: var(--ok); }
.badge.gap { background: #fff4e5; color: #b45309; }
.fact-empty { color: var(--muted); font-size: 13px; padding: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px;
  background: #16181d; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); z-index: 50;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }

/* Responsive */
@media (max-width: 767px) {
  .topbar { padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
  .brand { flex-shrink: 0; }
  .demo-nav-link { max-width: 48%; margin-right: 0; text-align: right; }
  .account-menu { width: 100%; min-width: 0; }
  .account-row { width: 100%; min-width: 0; }
  .brand-sub { display: none; }
  .actor-role { display: none; }
  .actor-email { flex: 1; min-width: 0; max-width: none; }
  .main { padding: 14px 12px 32px; }
}
@media (min-width: 768px) {
  .main { padding: 28px 20px 56px; }
}

/* M-03 materials UI */
.materials-card { margin-top: 18px; }
.materials-card input[type="file"] { margin: 8px 0 4px; font-size: 13px; }
.material-status { font-size: 13px; min-height: 18px; margin: 8px 0; color: var(--muted); }
.materials-list summary { cursor: pointer; font-weight: 600; margin: 6px 0; }
.materials-list-body { margin-top: 8px; }
.material-row {
  border: 1px solid var(--border, #e3e3e8);
  border-radius: 8px; padding: 8px 10px; margin: 6px 0;
  display: flex; flex-direction: column; gap: 4px;
}
.m-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.m-name { font-weight: 600; font-size: 14px; overflow-wrap: break-word; }
.m-meta { font-size: 12px; color: var(--muted); }
.m-open { align-self: flex-start; }
.material-detail { margin-top: 12px; }
.material-detail-text {
  white-space: pre-wrap; word-break: break-word; background: var(--code-bg, #f7f7f9);
  border: 1px solid var(--border, #e3e3e8); border-radius: 8px;
  padding: 12px; max-height: 320px; overflow: auto; font-size: 13px; line-height: 1.55;
}
.material-detail-refs { margin-top: 8px; max-height: 200px; overflow: auto; }
.material-detail-refs .ref-item {
  font-size: 12px; font-family: ui-monospace, Menlo, monospace; white-space: pre-wrap;
  word-break: break-word; padding: 2px 4px; border-left: 2px solid var(--border, #e3e3e8);
  margin-bottom: 2px;
}
.material-detail-refs .ref-item .ref-loc { color: var(--muted); }

/* M-03 digest & review UI (matches renderDigestSelection / renderDigestResult) */
.digest-card { margin-top: 6px; }
.digest-select { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 4px; }
.digest-sel {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px; color: var(--ink); padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
.digest-sel input[type="checkbox"] { margin-top: 3px; accent-color: var(--brand); flex: 0 0 auto; }
.digest-sel span { min-width: 0; overflow-wrap: anywhere; }
.digest-sel:focus-within { outline: 2px solid rgba(10, 88, 202, 0.35); border-color: var(--brand); }

/* Prose summary */
.digest-summary-text {
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-size: 14px; line-height: 1.6; margin-top: 4px;
}

/* Pending candidate review cards */
.digest-candidates summary { cursor: pointer; font-weight: 600; margin: 6px 0; }
.digest-candidates-body { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.digest-cand {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  background: var(--card); box-shadow: var(--shadow);
}
.d-fact-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.d-fact {
  font-size: 14px; font-weight: 600; min-width: 0; overflow-wrap: anywhere;
  word-break: break-word; flex: 1 1 auto;
}
.d-fact-head .badge { flex: 0 0 auto; }
.badge.d-pending-save { background: #eef2ff; color: var(--brand); border: 1px solid #c7d7f7; }
.d-meta { font-size: 12px; color: var(--muted); margin: 6px 0 10px; overflow-wrap: anywhere; word-break: break-word; }

/* Editable reviewed key/value */
.d-form { display: flex; flex-direction: column; gap: 4px; }
.d-form .d-label { margin: 8px 0 2px; }
.d-form input[type="text"], .d-form textarea {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.d-form textarea { resize: vertical; white-space: pre-wrap; overflow-wrap: break-word; min-height: 44px; }
.d-form input[type="text"]:focus, .d-form textarea:focus {
  outline: 2px solid rgba(10, 88, 202, 0.35); border-color: var(--brand);
}
.d-replace {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink); margin: 4px 0 0; cursor: pointer;
}
.d-replace input[type="checkbox"] { accent-color: var(--brand); }

/* Accept / reject controls */
.d-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.d-act.btn { min-width: 96px; }
.d-act.active { box-shadow: 0 0 0 2px rgba(10, 88, 202, 0.35); }
.d-act.btn-danger.active { box-shadow: 0 0 0 2px rgba(179, 38, 30, 0.35); }
.d-act:focus-visible { outline: 3px solid rgba(10, 88, 202, 0.45); outline-offset: 1px; }

/* Saved status / audit + source details & quotes */
.d-src summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 2px; }
.d-src summary:focus-visible { outline: 2px solid rgba(10, 88, 202, 0.45); border-radius: 4px; }
.d-src-body { margin-top: 4px; }
.d-src-id {
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted);
  white-space: normal; overflow-wrap: anywhere; word-break: break-all;
}
.d-src .ref-quote {
  margin: 6px 0 0; padding: 8px 12px; border-left: 3px solid var(--line);
  background: #f8f9fb; border-radius: 0 8px 8px 0;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  color: var(--ink); font-size: 13px;
}
.d-conflict {
  margin-top: 10px; padding: 8px 12px; border-radius: 8px;
  background: #fdecea; color: var(--err); border: 1px solid #f5b8b3;
  font-size: 13px; white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}

/* Digest confirm actions */
.digest-confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.digest-confirm-actions .btn { min-width: 140px; }

/* History */
.digest-history-body { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.digest-history-item {
  font: inherit; text-align: left; width: 100%; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; color: var(--ink);
  overflow-wrap: anywhere; word-break: break-word;
}
.digest-history-item:hover { border-color: var(--brand); background: #f1f3f7; }
.digest-history-item:focus-visible { outline: 3px solid rgba(10, 88, 202, 0.45); border-color: var(--brand); }

/* M-03 mode selector: keyboard-usable radio group */
.digest-mode {
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 2px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); font-size: 13px;
}
.digest-mode legend { font-weight: 600; padding: 0 4px; color: var(--ink); }
.digest-mode-opt {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  font-size: 13px; color: var(--ink);
}
.digest-mode-opt input[type="radio"] { accent-color: var(--brand); }
.digest-mode-opt:focus-within { outline: 2px solid rgba(10, 88, 202, 0.35); border-radius: 4px; }

/* Actions / Questions result views */
.digest-items-body { margin-top: 8px; display: flex; flex-direction: column; gap: 10px; }
.digest-mode-view { margin-top: 6px; }
.digest-mode-view > label {
  font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px;
}
.d-open-material { align-self: flex-start; margin: 4px 0; }

/* Narrow layouts: never let long hashes/ids force horizontal scroll */
@media (max-width: 767px) {
  .digest-confirm-actions .btn { min-width: 0; flex: 1 1 100%; }
  .d-actions .btn { flex: 1 1 100%; }
  .digest-mode { flex-direction: column; align-items: flex-start; }
}
