/* IC portal styling.
 *
 * Same token vocabulary as the proponent widget (docservice/widget/styles.css)
 * so the two surfaces of the same product read as one. No external font: a
 * strict-CSP bank portal makes no network requests it does not have to, so this
 * uses the platform's own UI stack. Colour, spacing and rhythm are ours. */

:root {
  --bg: #f4f6fa; --card: #ffffff; --fg: #0f172a; --muted: #64748b;
  --line: #d8dee8; --primary: #2563eb; --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --error: #e74c3c; --success: #10b981; --warn: #d97706;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --card: #111a2e; --fg: #e5ecf5; --muted: #94a3b8;
    --line: #24324a; --primary: #3b82f6; --primary-dark: #2563eb;
    --primary-light: #1e3a8a; --success: #34d399; --warn: #f59e0b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.4rem; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; margin: 0; }

.wrap { max-width: 980px; margin: 0 auto; padding: 20px 18px 64px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }
/* The [hidden] ATTRIBUTE (app.js toggles views/viewer with node.hidden) must win
   over display-setting classes like .viewer/.topbar (same specificity, author
   rule would otherwise beat the UA default) — else the full-screen viewer overlay
   shows on load and covers the login. */
[hidden] { display: none !important; }
.note { color: var(--muted); font-size: 0.9rem; }
.spacer { flex: 1 1 auto; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; }

/* ---- brand ---- */
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: -0.02em;
}
.brand-mark { color: var(--primary); flex: 0 0 auto; }
.brand-lg { font-size: 1.15rem; justify-content: center; margin-bottom: 18px; }

/* ---- top bar ---- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-in {
  max-width: 980px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 0.9rem; }

.key-pill {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  border-radius: 999px; padding: 5px 12px; font-size: 0.82rem; cursor: pointer;
}
.key-pill:hover { border-color: var(--primary); }
.key-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--error); }
.key-pill.has-key .key-dot { background: var(--warn); }
.key-pill.remembered .key-dot { background: var(--success); }

/* ---- buttons ---- */
.primary {
  background: var(--primary); color: #fff; border: 0;
  border-radius: 10px; padding: 11px 18px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer;
}
.primary:hover:not(:disabled) { background: var(--primary-dark); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.link {
  background: none; border: 0; color: var(--primary);
  font-size: 0.9rem; cursor: pointer; padding: 4px 2px;
}
.link:hover { text-decoration: underline; }
.back { display: inline-block; margin-bottom: 12px; }
.mini {
  background: transparent; border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 5px 12px; font-size: 0.82rem; cursor: pointer;
}
.mini:hover { border-color: var(--primary); color: var(--primary); }

/* ---- cards / fields ---- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"],
select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--fg);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
.error { color: var(--error); font-size: 0.88rem; }
.nojs { max-width: 560px; margin: 40px auto; text-align: center; }

/* ---- login ---- */
.login-wrap { max-width: 400px; margin: 6vh auto 0; }
.login-card h1 { margin-bottom: 6px; font-size: 1.25rem; }
.login-card .note { margin: 0 0 18px; }

/* ---- view head ---- */
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 8px 0 16px; flex-wrap: wrap;
}
.filters { display: flex; align-items: center; gap: 12px; }
.filters select { width: auto; }
.section-title { margin: 28px 0 10px; }

/* ---- table ---- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card);
}
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td {
  text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table th {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600;
}
.table tbody tr:last-child td { border-bottom: 0; }
.row { cursor: pointer; }
.row:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.row:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.ref { font-weight: 600; }

/* ---- badge ---- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600;
  background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--success) 20%, transparent); color: var(--success); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--error) 18%, transparent); color: var(--error); }

/* ---- meta grid ---- */
.meta {
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px;
  margin: 0 0 8px; font-size: 0.92rem;
}
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; }

/* ---- timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item {
  position: relative; padding: 0 0 16px 24px; margin: 0;
}
.tl-item::before {
  content: ""; position: absolute; left: 5px; top: 14px; bottom: -2px;
  width: 2px; background: var(--line);
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  position: absolute; left: 0; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--muted);
}
.tl-item.ok .tl-dot { border-color: var(--success); background: var(--success); }
.tl-item.warn .tl-dot { border-color: var(--warn); }
.tl-item.bad .tl-dot { border-color: var(--error); background: var(--error); }
.tl-title { font-weight: 600; font-size: 0.92rem; }
.tl-sub { font-size: 0.82rem; }

/* ---- batch cards ---- */
.batch { padding: 16px 18px; }
.batch-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.artifact-list { list-style: none; margin: 0; padding: 0; }
.artifact-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-top: 1px solid var(--line);
}
.artifact-list li:first-child { border-top: 0; }
.a-type { font-weight: 500; word-break: break-all; }
.a-meta { text-align: right; white-space: nowrap; }

/* ---- key dialog ---- */
.key-dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--fg);
  padding: 0; max-width: 520px; width: calc(100% - 32px);
}
.key-dialog::backdrop { background: rgba(2, 8, 20, 0.55); }
.key-dialog form { padding: 22px; }
.key-dialog h2 { margin: 0 0 6px; }
.key-dialog textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.warn {
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border-radius: 10px; padding: 12px 14px; font-size: 0.85rem; margin: 12px 0;
}
.remember { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; margin: 12px 0 4px; }
.remember input { width: auto; }
.key-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* ---- viewer ---- */
body.viewer-open { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.viewer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--card);
}
.viewer-head h2 { margin: 0; }
.viewer-body { flex: 1 1 auto; display: flex; min-height: 0; }
.viewer-list {
  width: 340px; flex: 0 0 340px; overflow-y: auto;
  border-right: 1px solid var(--line); padding: 16px; background: var(--card);
}
.viewer-stage { flex: 1 1 auto; min-width: 0; display: flex; }
.viewer-empty { margin: auto; text-align: center; padding: 24px; }
.viewer-frame { flex: 1 1 auto; display: flex; }
.stage-pdf { flex: 1 1 auto; width: 100%; height: 100%; border: 0; }
.stage-img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; padding: 16px; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin: 6px 0 16px; }
.mini-table th, .mini-table td {
  text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line);
}
.mini-table th { color: var(--muted); font-weight: 600; }

.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.doc-info { min-width: 0; }
.doc-name { display: block; font-weight: 600; font-size: 0.88rem; word-break: break-all; }
.doc-sub { font-size: 0.78rem; }
.doc-actions { display: flex; gap: 6px; flex: 0 0 auto; }

@media (max-width: 720px) {
  .viewer-body { flex-direction: column; }
  .viewer-list { width: 100%; flex: 0 0 auto; max-height: 45%; border-right: 0; border-bottom: 1px solid var(--line); }
}
