:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #1c2b33;
  --ink-soft: #52646e;
  --line: #d9e0e4;
  --brand: #0d6b74;
  --brand-dark: #094e55;
  --brand-tint: #e3f2f3;
  --danger: #b42318;
  --danger-tint: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 50, .06), 0 2px 8px rgba(16, 40, 50, .05);

  --s-none-bg: #fde8e8;  --s-none-fg: #9b1c1c;
  --s-tent-bg: #fff3d6;  --s-tent-fg: #7a4b00;
  --s-conf-bg: #dcf5e4;  --s-conf-fg: #14612e;
  --s-done-bg: #e6ebee;  --s-done-fg: #40515b;
  --s-canc-bg: #eeeeee;  --s-canc-fg: #5c5c5c;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
a { color: var(--brand-dark); }
:focus-visible { outline: 3px solid #f0a92b; outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar { background: var(--brand-dark); color: #fff; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; text-decoration: none; color: #fff; margin-right: auto; }
.brand strong { font-size: 1.05rem; letter-spacing: .01em; }
.brand span { font-size: .8rem; opacity: .8; }
.nav { display: flex; gap: 4px; }
.nav a { color: #fff; text-decoration: none; padding: 8px 12px; border-radius: 8px; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.18); opacity: 1; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.userbox .who { text-align: right; line-height: 1.25; }
.userbox .who small { display: block; opacity: .75; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.5); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.12); }

.demo-banner {
  background: #fff3d6; color: #6b4300; text-align: center; padding: 8px 16px; font-size: .9rem;
  border-bottom: 1px solid #f1d58f;
}

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { flex: 1 1 260px; }
.page-head p { margin: 4px 0 0; color: var(--ink-soft); }
.crumb { display: inline-block; margin-bottom: 8px; font-size: .9rem; }

/* ---------- buttons & fields ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--brand); color: #fff; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; min-height: 40px;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--brand-dark); border-color: var(--line); }
.btn.secondary:hover { background: var(--brand-tint); }
.btn.ghost { background: transparent; color: var(--brand-dark); border-color: var(--line); }
.btn.ghost:hover { background: var(--brand-tint); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: #f0b4ae; }
.btn.danger:hover { background: var(--danger-tint); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .88rem; }
.btn.link { background: none; border: 0; color: var(--brand-dark); text-decoration: underline; padding: 4px; min-height: 0; font-weight: 500; }

label, .label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
.hint { color: var(--ink-soft); font-size: .86rem; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #b9c4ca; border-radius: 8px;
  background: #fff; color: var(--ink); min-height: 42px;
}
textarea { min-height: 110px; resize: vertical; }
input[type=file] { width: 100%; font: inherit; padding: 8px; border: 1px dashed #b9c4ca; border-radius: 8px; background: #fafcfc; }
input:disabled, select:disabled, textarea:disabled { background: #eef1f3; color: #66757d; }
.field { margin-bottom: 16px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin: 0;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer;
}
.check:has(input:checked) { background: var(--brand-tint); border-color: var(--brand); }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .95rem; }
.alert.error { background: var(--danger-tint); color: var(--danger); border: 1px solid #f0b4ae; }
.alert.info { background: var(--brand-tint); color: var(--brand-dark); border: 1px solid #b7dadd; }
.alert.ok { background: #dcf5e4; color: #14612e; border: 1px solid #a6dfb8; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card > h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.card > h2 .tag { margin-left: auto; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--ink-soft); font-weight: 600; font-size: .9rem; }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.muted { color: var(--ink-soft); }
.tag { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-tint); color: var(--brand-dark); }
.tag.warn { background: var(--danger-tint); color: var(--danger); }
.tag.internal { background: #ece7fb; color: #4b2f9c; }

/* ---------- status badges & chips ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.s-none { background: var(--s-none-bg); color: var(--s-none-fg); }
.s-tent { background: var(--s-tent-bg); color: var(--s-tent-fg); }
.s-conf { background: var(--s-conf-bg); color: var(--s-conf-fg); }
.s-done { background: var(--s-done-bg); color: var(--s-done-fg); }
.s-canc { background: var(--s-canc-bg); color: var(--s-canc-fg); text-decoration: line-through; }
.chip { display: inline-block; font-size: .8rem; padding: 2px 8px; margin: 0 4px 4px 0; border-radius: 6px; background: #edf1f3; color: #33454f; }

/* ---------- list view ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile {
  appearance: none; font: inherit; text-align: left; cursor: pointer; padding: 14px 16px;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.tile .n { display: block; font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.tile .t { display: block; font-size: .9rem; color: var(--ink-soft); font-weight: 600; }
.tile[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-tint); }
.tile.t-none .n { color: var(--s-none-fg); }
.tile.t-tent .n { color: var(--s-tent-fg); }
.tile.t-conf .n { color: var(--s-conf-fg); }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 240px; }
.toolbar select { width: auto; }
.pastlinks { font-size: .9rem; color: var(--ink-soft); margin-bottom: 10px; }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.list th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #eef2f4; padding: 10px 12px; }
table.list td { padding: 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #f7fbfb; }
.pname { font-weight: 700; text-decoration: none; color: var(--ink); }
.pname:hover { text-decoration: underline; }
.sub { font-size: .82rem; color: var(--ink-soft); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-soft); background: var(--surface); border: 1px dashed #b9c4ca; border-radius: var(--radius); }

/* ---------- documents ---------- */
.doclist { list-style: none; margin: 0 0 14px; padding: 0; }
.doclist li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.doclist li:first-child { border-top: 0; }
.doclist .dtype { font-size: .78rem; font-weight: 700; color: var(--brand-dark); background: var(--brand-tint); padding: 2px 8px; border-radius: 6px; }
.doclist .dname { flex: 1 1 200px; overflow-wrap: anywhere; }
.upload-row { display: grid; grid-template-columns: 170px 1fr auto; gap: 10px; align-items: end; padding-top: 12px; border-top: 1px solid var(--line); }

.notes-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 26px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: 4px; }
.auth-card .lead { color: var(--ink-soft); margin: 0 0 20px; }
.auth-card .btn { width: 100%; }
.auth-links { text-align: center; margin-top: 14px; font-size: .92rem; }
.demo-choices { display: grid; gap: 10px; }

.reveal { background: #fffbe8; border: 2px solid #f0c94a; }
.reveal code { font-size: 1.25rem; font-weight: 700; letter-spacing: .06em; background: #fff; padding: 4px 10px; border-radius: 6px; border: 1px solid #e6d58c; user-select: all; }

.people th, .people td { font-size: .92rem; }
table.people { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.people th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #eef2f4; padding: 10px 12px; }
table.people td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
table.people select { min-height: 34px; padding: 4px 8px; }
.inactive { opacity: .6; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(92vw, 460px); }
.toast { background: #1c2b33; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .95rem; }
.toast.error { background: var(--danger); }

.spinner { text-align: center; padding: 60px 0; color: var(--ink-soft); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .grid2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  main { padding: 16px 14px 56px; }
  .row2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .upload-row { grid-template-columns: 1fr; }
  .userbox .who { display: none; }
  table.list thead { position: absolute; left: -9999px; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list { background: none; border: 0; box-shadow: none; }
  table.list tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; padding: 6px 4px; box-shadow: var(--shadow); }
  table.list td { border: 0; padding: 6px 12px; display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
  table.list td::before { content: attr(data-label); font-size: .78rem; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
  table.list td.empty-cell { display: none; }
  table.people { display: block; overflow-x: auto; }
}
@media print {
  .topbar, .toolbar, .tiles, .btn, #toasts, .demo-banner { display: none !important; }
  body { background: #fff; }
}
