/* Web Clipboard - single stylesheet. Light + dark via prefers-color-scheme. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --border-strong: #c3c9d2;
  --text: #1a1f27;
  --text-muted: #59626f;      /* 6.0:1 on white */
  --accent: #2456d3;          /* 6.3:1 on white */
  --accent-hover: #1b45ad;
  --accent-soft: #e7eefc;
  --on-accent: #ffffff;
  --danger: #b4232c;
  --danger-soft: #fbe9ea;
  --ok: #17733f;
  --ok-soft: #e3f4ea;
  --warn: #8a5300;
  --warn-soft: #fdf1dc;
  --focus: #2456d3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2b313b;
    --border-strong: #3c4450;
    --text: #e7eaee;
    --text-muted: #a3acb8;    /* 7.5:1 on surface */
    --accent: #7fa6ff;        /* 7.4:1 on surface */
    --accent-hover: #a2bfff;
    --accent-soft: #1d2a45;
    --on-accent: #0b1020;
    --danger: #ff8a8f;
    --danger-soft: #3a1c1f;
    --ok: #6fd69a;
    --ok-soft: #16301f;
    --warn: #f2bd63;
    --warn-soft: #33270f;
    --focus: #7fa6ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, kbd, pre { font-family: var(--mono); }
kbd {
  display: inline-block; padding: 0 .35em; font-size: .85em;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface);
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); }
.muted, .hint { color: var(--text-muted); }
.hint { font-size: .85rem; margin: .3em 0 0; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand:hover { color: var(--text); }
.brand-mark { width: 24px; height: 24px; fill: var(--accent); }
.topnav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topnav a { color: var(--text-muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-sm); font-weight: 500; }
.topnav a:hover { color: var(--text); background: var(--surface-2); }
.topnav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.topnav-user { color: var(--text-muted); font-size: .85rem; padding: 0 6px 0 12px; border-left: 1px solid var(--border); margin-left: 6px; max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.container { max-width: 960px; margin: 0 auto; padding: 24px 20px 64px; }
.container.narrow { max-width: 720px; }
.page-center main { display: grid; place-items: center; padding: 40px 16px; min-height: calc(100vh - 60px); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.enrol-card { width: 100%; max-width: 520px; padding: 28px; }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .9rem; }

/* ------------------------------------------------------------- forms */
.stack > * + * { margin-top: 14px; }
.field label, .field .label-spacer { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
.code-input { font-family: var(--mono); font-size: 1.25rem; letter-spacing: .2em; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: var(--radius-sm); font-size: .9rem; margin: 10px 0 0; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 220px; }
/* Top-aligned variant: fields with a hint under them don't push neighbours down.
   The action button sits in a .field with an invisible label so it lines up with the inputs. */
.inline-form-top { align-items: flex-start; }
.inline-form .field-action { flex: 0 0 auto; }
.inline-form .field-action .btn { min-height: calc(15px * 1.5 + 20px); } /* = input height: body line box + padding + border */
.check { display: flex; gap: 8px; align-items: center; margin: 14px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .9rem; line-height: 1.2;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s, transform .06s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #1a0507; } }
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { color: var(--danger); background: var(--danger-soft); }
.btn-sm { padding: 6px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 6px 8px; }
.icon { width: 16px; height: 16px; fill: currentColor; flex: none; }
.btn.copied { background: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.copied { color: #04140a; } }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

/* ------------------------------------------------------------- composer */
.composer { padding: 16px; }
.paste-zone {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  cursor: pointer; transition: border-color .15s, background-color .15s;
}
.paste-zone:hover, .paste-zone:focus-visible, body.dragging .paste-zone {
  border-color: var(--accent); background: var(--accent-soft);
}
.paste-zone:focus-visible { outline-offset: 3px; }
.paste-icon { width: 34px; height: 34px; fill: var(--accent); flex: none; }
.paste-title { font-weight: 650; margin: 0; }
.paste-zone .hint { margin: 2px 0 0; }
body.dragging::after {
  content: "Drop to add"; position: fixed; inset: 0; display: grid; place-items: center; z-index: 50;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-size: 1.6rem; font-weight: 700;
  pointer-events: none; border: 4px dashed var(--accent);
}
.text-form { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.text-form textarea { font-family: var(--mono); font-size: .9rem; resize: vertical; min-height: 64px; }
.text-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.upload-progress { height: 3px; margin-top: 10px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.upload-progress span { display: block; height: 100%; width: 35%; background: var(--accent); animation: indet 1s ease-in-out infinite; }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }

/* ------------------------------------------------------------- list */
.list-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin: 28px 0 8px; }
.list-toolbar h2 { margin: 0; font-size: 1.15rem; }
.list-toolbar .count { color: var(--text-muted); font-weight: 500; }
.toolbar-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text-muted); padding: 4px 8px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.live[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.live[data-state="offline"] .dot { background: var(--danger); }
.usage { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: .8rem; color: var(--text-muted); }
.usage-bar { flex: 0 0 120px; height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.usage-bar[data-level="mid"] span { background: var(--warn); }
.usage-bar[data-level="high"] span { background: var(--danger); }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "body actions" "meta actions";
  gap: 6px 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow);
}
.item.pinned { border-left: 3px solid var(--accent); }
.item.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: var(--accent-soft); transform: translateY(-4px); opacity: .4; } 15% { transform: none; opacity: 1; } 100% { background: var(--surface); } }
.item-body { grid-area: body; min-width: 0; }
.item-text {
  margin: 0; font-size: .875rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 9.5em; overflow: hidden;
}
.item-more { margin: 4px 0 0; font-size: .8rem; color: var(--text-muted); }
.item-thumb {
  display: block; max-width: min(320px, 100%); max-height: 240px; width: auto; height: auto; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px;
}
.item-meta { grid-area: meta; display: flex; gap: 10px; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); }
.item-kind { font-weight: 600; }
.item-pin-badge { color: var(--accent); font-weight: 600; }
.item-actions { grid-area: actions; display: flex; gap: 2px; align-items: center; }
.item [data-action=pin][aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.empty { text-align: center; padding: 48px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty-title { font-weight: 650; font-size: 1.05rem; margin-bottom: 4px; }

/* ------------------------------------------------------------- dialogs */
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; max-width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog-wide { max-width: min(860px, calc(100vw - 32px)); width: 100%; }
.dialog::backdrop { background: rgba(10, 14, 20, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.view-body { max-height: 70vh; overflow: auto; }
.view-text { font-family: var(--mono); font-size: .85rem; min-height: 50vh; resize: vertical; white-space: pre; }
.view-image { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: var(--radius-sm); }

/* ------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; z-index: 200;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow-lg);
  font-weight: 600; font-size: .9rem; max-width: calc(100vw - 32px); text-align: center;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .toast[data-kind="error"] { color: #1a0507; } }

/* ------------------------------------------------------------- enrolment */
.steps { padding-left: 1.3em; margin: 16px 0 0; }
.steps > li { margin-bottom: 22px; }
.steps > li::marker { font-weight: 700; color: var(--accent); }
.steps h2 { font-size: 1rem; }
.qr-wrap { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); width: fit-content; margin: 0 auto 12px; }
.qr { display: block; width: 220px; height: 220px; }
.manual summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0 4px; }
.kv dt { color: var(--text-muted); font-size: .85rem; }
.kv dd { margin: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.secret { font-size: .95rem; letter-spacing: .05em; word-break: break-all; background: var(--surface-2); padding: 3px 6px; border-radius: 4px; }
.recovery-codes {
  list-style: none; padding: 14px; margin: 12px 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 20px;
  background: var(--surface-2); border-radius: var(--radius-sm); font-family: var(--mono); font-size: 1rem;
}

/* ------------------------------------------------------------- account / admin */
.session-list { list-style: none; margin: 0; padding: 0; }
.session { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.session:first-child { border-top: 0; }
.session-name { margin: 0; font-weight: 600; }
.session .hint { margin: 2px 0 0; }
.badge { display: inline-block; font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--accent-soft); color: var(--accent); }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 650; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table-compact td { padding: 6px 8px; font-size: .82rem; }
.actions-cell { text-align: right; }
.table-actions { display: flex; gap: 2px; justify-content: flex-end; flex-wrap: wrap; }
.link-card { border-color: var(--accent); }
.link-row { display: flex; gap: 8px; }
.link-row input { font-family: var(--mono); font-size: .85rem; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; }
  .topnav-user { display: none; }
  .container { padding: 16px 16px 48px; }
  .card { padding: 16px; }
  .auth-card, .enrol-card { padding: 20px; }
  .paste-zone { padding: 14px; }
  .item { grid-template-columns: 1fr; grid-template-areas: "body" "meta" "actions"; }
  .item-actions { justify-content: flex-start; flex-wrap: wrap; }
  .usage-bar { flex-basis: 70px; }
  .link-row { flex-direction: column; }
  .recovery-codes { grid-template-columns: 1fr; }
  .session { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
