:root {
  --ground: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #16202e;
  --ink-2: #3e4855;
  --muted: #5b6675;
  --line: #dde2e8;
  --line-2: #edf0f3;
  --field: #b9c2cd;
  --accent: #1f4e8c;
  --accent-ink: #ffffff;
  --accent-hover: #163a69;
  --accent-soft: #eaf0f8;
  --ok-bg: #e3f1e7; --ok-ink: #1d6233;
  --off-bg: #eceef1; --off-ink: #48525f;
  --warn-bg: #fff6e5; --warn-ink: #6b4a00; --warn-line: #f1dfb8;
  --err: #b42318; --err-bg: #fdecea;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font-size: 15px; line-height: 1.45; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0; }
p { margin: 0 0 12px; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.main { flex: 1; padding-top: 28px; padding-bottom: 48px; display: flex; flex-direction: column; gap: 20px; }
.footer { color: var(--muted); font-size: 13px; padding-bottom: 28px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; background: var(--surface); padding: 8px 12px; z-index: 100; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand:hover { color: var(--ink); }
.mark { width: 38px; height: 38px; border-radius: 8px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.brand-name { display: block; font-weight: 600; }
.brand-sub { display: block; font-size: 13px; color: var(--muted); }
.logo { display: block; height: 48px; width: auto; }
.brand .brand-sub { padding-left: 14px; border-left: 1px solid var(--line); font-size: 14px; font-weight: 500; color: var(--ink-2); }
.usernav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: 14px; }
.usernav a { text-decoration: none; font-weight: 500; }
.who { color: var(--muted); }
.inline { display: inline; margin: 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 500; cursor: pointer; }
.linklike:hover { color: var(--accent-hover); text-decoration: underline; }

/* blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 20px; }
.card-head { padding: 14px 20px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.lede { color: var(--muted); font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.spacer { flex: 1; }
.flash { background: var(--accent-soft); border: 1px solid #c9d8ee; color: var(--ink); border-radius: 8px; padding: 12px 14px; }
.alert { background: var(--err-bg); border: 1px solid #f5c2bd; color: var(--err); border-radius: 8px; padding: 12px 14px; }
.note { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 8px; padding: 10px 14px; font-size: 14px; }
.validation-summary-valid { display: none; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.field-error { color: var(--err); font-size: 13px; }

/* forms */
label { font-weight: 600; font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], select {
  height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 8px; font: inherit; color: var(--ink); background: #fff; min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid #8fb0df; outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn.secondary { background: #fff; color: var(--accent); border-color: var(--field); }
.btn.secondary:hover { background: var(--accent-soft); color: var(--accent-hover); }
.btn.danger { background: #fff; color: var(--err); border-color: #e6b3ae; }
.btn.danger:hover { background: var(--err-bg); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* tables */
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th { text-align: left; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 16px; white-space: nowrap; }
table.grid td { padding: 12px 16px; border-top: 1px solid var(--line-2); vertical-align: middle; }
table.grid tr:hover td { background: #fbfcfd; }
table.grid td.actions { text-align: right; white-space: nowrap; }
.num { font-weight: 600; white-space: nowrap; }
table.grid th.pick, table.grid td.pick { width: 44px; padding-right: 0; text-align: center; }
.pick input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--accent); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn[aria-busy=true] { opacity: .7; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.open { background: var(--ok-bg); color: var(--ok-ink); }
.pill.closed { background: var(--off-bg); color: var(--off-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.err { background: var(--err-bg); color: var(--err); }
.docname { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.docicon { flex: 0 0 auto; width: 36px; height: 36px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.docname strong { display: block; word-break: break-word; }
.empty { padding: 28px 20px; color: var(--muted); text-align: center; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* claim header */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-top: 12px; }
.facts dt { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.facts dd { margin: 4px 0 0; }
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; min-height: 40px; }

/* auth pages */
.auth { display: flex; justify-content: center; padding-top: 24px; }
.auth .card { width: 100%; max-width: 440px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.auth h1 { font-size: 22px; }
.code-input { letter-spacing: 6px; font-size: 20px !important; text-align: center; }
.qr { display: flex; justify-content: center; padding: 8px; background: #fff; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; }
.secret { font-family: Consolas, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; word-break: break-all; font-size: 14px; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; font-family: Consolas, Menlo, monospace; font-size: 15px; }
.codes span { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px; text-align: center; }
.choice { display: grid; gap: 12px; }
.choice .btn { justify-content: flex-start; }

/* viewer */
.viewer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.viewer-title { min-width: 0; flex: 1 1 280px; }
.viewer-title strong { display: block; word-break: break-word; }
.viewer-body { background: #e6e9ee; min-height: 560px; display: flex; justify-content: center; align-items: flex-start; padding: 20px; overflow: auto; border-radius: 0 0 var(--radius) var(--radius); }
.viewer-body iframe { width: 100%; height: 78vh; min-height: 560px; border: 0; background: #fff; border-radius: 4px; }
.viewer-body img.doc-image { max-width: 100%; height: auto; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.viewer-body .paper { background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); padding: 32px 40px; width: 100%; max-width: 900px; overflow-x: auto; }
.viewer-body pre.paper { white-space: pre-wrap; word-break: break-word; font-family: Consolas, Menlo, monospace; font-size: 13px; margin: 0; }
.viewer-body canvas { max-width: 100%; height: auto; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.12); display: block; margin: 0 auto 16px; }
.viewer-status { color: var(--ink-2); padding: 40px 16px; text-align: center; }
.mail-head { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 16px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.mail-head dt { color: var(--muted); font-weight: 600; }
.mail-head dd { margin: 0; word-break: break-word; }
.mail-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.mail-atts { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; }
.sheet-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.sheet-tabs button[aria-pressed=true] { background: var(--accent); color: #fff; border-color: var(--accent); }
.sheet table { border-collapse: collapse; font-size: 13px; }
.sheet td, .sheet th { border: 1px solid #d6dbe1; padding: 4px 8px; white-space: nowrap; }
.docx-wrapper { background: transparent !important; padding: 0 !important; }

@media (max-width: 640px) {
  h1 { font-size: 22px; }
  .usernav .who { display: none; }
  .auth .card { padding: 20px; }
  .viewer-body { padding: 8px; }
  .viewer-body .paper { padding: 16px; }
}
