/* Cotangent Tech admin portal */
:root {
  --ink: #16232d;
  --muted: #5a6872;
  --brand: #1f4e5f;
  --brand-dark: #153744;
  --accent: #8a6a2c;
  --line: #d7dee2;
  --soft: #f3f6f7;
  --paper: #ffffff;
  --bg: #eef2f4;
  --focus: #b35c00;
  --ok: #2e6b3f;
  --warn: #8a6a2c;
  --bad: #a3322a;
  --info: #2b5c8a;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
a:hover { color: var(--brand-dark); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }
p { margin: 0 0 10px; }
code { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .9em; background: var(--soft); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--soft); padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.wrap-anywhere { overflow-wrap: anywhere; }
.warn-text { color: var(--bad); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 8px; }
.js .js-hide { display: none; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; background: var(--brand-dark); color: #fff; padding: 10px 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; }
.brand:hover { color: #fff; }
.brand small { font-weight: 400; color: #b9cdd4; margin-left: 4px; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.mainnav a { color: #dbe7eb; text-decoration: none; padding: 7px 12px; border-radius: 6px; }
.mainnav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.mainnav a[aria-current="page"] { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 10px; }
.usermenu a { color: #fff; text-decoration: none; }
.usermenu small { color: #b9cdd4; }
.usermenu form { margin: 0; }
.usermenu .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .4); background: transparent; }

.main { max-width: 1280px; margin: 0 auto; padding: 24px; }
.appfooter { max-width: 1280px; margin: 0 auto; padding: 0 24px 32px; color: var(--muted); font-size: .82rem; }

/* Headings and layout */
.page-head { margin-bottom: 18px; }
.page-head.with-actions { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.crumbs { font-size: .86rem; margin-bottom: 4px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form, .actions-cell form { margin: 0; display: inline; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2.tight, .grid-3.tight { gap: 12px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.panel.narrow, .narrow { max-width: 720px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 18px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card-link { color: inherit; text-decoration: none; display: block; transition: border-color .15s, box-shadow .15s; }
.card-link:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(22, 35, 45, .08); color: inherit; }
.card h2 { font-size: 1.02rem; }
.card.archived { opacity: .7; }
.stat { font-size: 1.9rem; font-weight: 700; margin: 4px 0; color: var(--brand-dark); }
.stat small { font-size: .9rem; font-weight: 400; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; }
.stat-card .stat { font-size: 1.6rem; }
.summary-panel .progress { max-width: 520px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--paper); color: var(--brand-dark);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn:hover { background: var(--soft); color: var(--brand-dark); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-small { padding: 5px 10px; font-size: .84rem; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #e6c2bf; }
.btn-danger:hover { background: #fbeeed; color: var(--bad); }
button[disabled], select[disabled], input[disabled], textarea[disabled] { opacity: .7; cursor: not-allowed; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--paper); border: 1px solid #bfcbd1; border-radius: 6px; padding: 7px 9px; max-width: 100%; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
input[readonly].calc { background: var(--soft); }
textarea { resize: vertical; width: 100%; }
textarea.editor { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .9rem; line-height: 1.5; min-height: 420px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack input:not([type="checkbox"]):not([type="file"]), .stack select { width: 100%; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin: 0 0 16px; }
.filters label { font-size: .82rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
legend { font-weight: 700; padding: 0 6px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 12px; }
.field-grid input { width: 100%; }
.field-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 18px; margin: 0; }
.field-list.single { grid-template-columns: 1fr; }
.field-list div { display: flex; flex-direction: column; }
.field-list.single div { flex-direction: row; gap: 12px; border-bottom: 1px solid var(--soft); padding-bottom: 6px; }
.field-list.single dt { width: 150px; flex: none; }
.field-list dt { font-size: .82rem; color: var(--muted); }
.field-list dd { margin: 0; font-weight: 600; }
.code-input { font-size: 1.4rem; letter-spacing: .25em; text-align: center; max-width: 220px; }
.secret { font-size: 1.05rem; letter-spacing: .06em; padding: 4px 8px; user-select: all; }
.qr-setup { margin: 12px 0; }
.qr { display: flex; justify-content: center; margin: 10px 0 12px; }
.qr img { box-sizing: content-box; background: #fff; border: 1px solid var(--line); border-radius: 8px; image-rendering: pixelated; max-width: 100%; height: auto; }
.qr-manual { font-size: .9rem; margin-bottom: 8px; }
.qr-manual summary { cursor: pointer; color: var(--brand); }

/* Alerts and badges */
.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: #edf6ef; border-color: #b9d8c0; color: #1f4a2b; }
.alert-error { background: #fbeeed; border-color: #e6c2bf; color: #7a231d; }
.alert-info { background: #edf3f9; border-color: #bfd2e6; color: #1e4468; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; vertical-align: middle; border: 1px solid transparent; }
.badge-teal { background: #e3eef1; color: #1f4e5f; }
.badge-gold { background: #f6efe0; color: #6e5321; }
.badge-purple { background: #eee8f5; color: #57397f; }
.badge-green { background: #e4f1e7; color: #245532; }
.badge-slate { background: #e8ecef; color: #445460; }
.badge-blue { background: #e4edf6; color: #234d75; }
.badge-red { background: #fbe9e7; color: #8f2a22; }
.badge-muted { background: transparent; color: var(--muted); border-color: var(--line); }

/* Progress */
.progress { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.progress span { font-size: .84rem; color: var(--muted); white-space: nowrap; }
progress { flex: 1; height: 10px; border: 0; border-radius: 999px; background: #e3e9ec; overflow: hidden; -webkit-appearance: none; appearance: none; }
progress::-webkit-progress-bar { background: #e3e9ec; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--paper); }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--soft); }
.table.compact th, .table.compact td { padding: 6px 8px; font-size: .88rem; }
.table .num { text-align: right; width: 1%; white-space: nowrap; }
.table tr.row-warn td { background: #fdf6f5; }
.items .step-title { font-weight: 700; text-decoration: none; }
.items .step-title:hover { text-decoration: underline; }
.items .detail { color: var(--muted); margin-top: 4px; }
.items .detail p { margin: 0 0 4px; }
.items tr.status-done .step-title, .items tr.status-na .step-title { color: var(--muted); }
.items tr.status-done td.num::after { content: " ✓"; color: var(--ok); }
.items .status-col { width: 150px; }
.items .notes-cell { max-width: 260px; overflow-wrap: anywhere; }
.inline-status { display: flex; gap: 6px; margin: 0; }
.inline-status select { font-size: .86rem; padding: 4px 6px; }
.section-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 8px; }
.section-head .actions form { display: inline; }
.md-table { border-collapse: collapse; margin: 8px 0 14px; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.md-table th { background: var(--soft); }

/* Lists, history, diff */
.feed, .plain { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.plain li { padding: 4px 0; border-bottom: 1px solid var(--soft); overflow-wrap: anywhere; }
.history { list-style: none; margin: 0; padding: 0; }
.history > li { padding: 10px 0; border-bottom: 1px solid var(--soft); }
.history-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.changes { margin: 6px 0 0; padding-left: 18px; font-size: .86rem; }
.changes .field { color: var(--muted); }
.changes del { color: var(--bad); }
.changes ins { color: var(--ok); text-decoration: none; }
.diff { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .86rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.diff > div { padding: 1px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff-op { display: inline-block; width: 1.4em; color: var(--muted); user-select: none; }
.diff-add { background: #e9f5ec; }
.diff-del { background: #fbecea; text-decoration: line-through; text-decoration-color: rgba(163, 50, 42, .4); }
.diff-skip { color: var(--muted); background: var(--soft); text-align: center; }
.diff-note { background: #fdf6e8; }
.steps-list { padding-left: 20px; }
.steps-list li { margin-bottom: 8px; }
.prose h2, .prose h3, .prose h4 { margin-top: 18px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose blockquote { margin: 8px 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.document-text { max-width: 860px; }
details.source { margin-top: 18px; }
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 14px 0; }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--brand); }
.chart .bar:hover { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.key { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-left: 10px; }
.key-bar { background: var(--brand); }
.key-line { background: var(--accent); height: 3px; }

/* Sign-in pages */
body.bare { background: linear-gradient(160deg, #153744 0%, #1f4e5f 55%, #2a6175 100%); min-height: 100vh; }
.main-bare { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 24px 16px; }
.main-bare > .alert { width: 100%; max-width: 420px; }
.auth-card { background: var(--paper); border-radius: 14px; padding: 28px 30px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.auth-card.auth-wide { max-width: 560px; }
.auth-logo { display: block; margin-bottom: 10px; }
.notice { margin-top: 18px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
body.bare.print-view { background: var(--paper); }
body.print-view .main-bare { display: block; min-height: 0; max-width: 1000px; margin: 0 auto; }
.print-head { margin-bottom: 16px; }

/* Inactivity warning */
.idle-warning { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; background: var(--ink); color: #fff; padding: 12px 16px;
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px); }

@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .main { padding: 16px; }
  .usermenu { width: 100%; justify-content: space-between; }
}
@media (max-width: 640px) {
  .items .status-col { width: auto; }
  .field-list.single div { flex-direction: column; gap: 0; }
}
@media print {
  .topbar, .appfooter, .skip-link, .screen-only, .idle-warning, .filters, .actions, .btn { display: none !important; }
  body, body.bare { background: #fff; font-size: 10.5pt; }
  .main, .main-bare { padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; }
  .table th { background: #f0f0f0; }
  a { color: inherit; text-decoration: none; }
  h2 { break-after: avoid; }
  tr { break-inside: avoid; }
}
