/* SecurePages design system: tokens, then components. No inline styles anywhere (strict CSP). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e9ecf1;
  --text: #15161c;
  --text-2: #4a4d59;
  --muted: #6e7280;
  --line: #e3e5ea;
  --line-strong: #cfd3db;
  --accent: #3657d6;
  --accent-hover: #2d4bc0;
  --accent-soft: #edf1fd;
  --accent-fg: #ffffff;
  --danger: #c4312b;
  --danger-soft: #fdeeed;
  --ok: #217a45;
  --ok-soft: #e8f6ee;
  --warn: #8a5a00;
  --warn-soft: #fff6df;
  --focus: 0 0 0 3px rgba(54, 87, 214, .28);
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(15, 18, 30, .05), 0 2px 8px rgba(15, 18, 30, .04);
  --shadow-lg: 0 24px 64px rgba(15, 18, 30, .22);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111216;
    --surface: #191a20;
    --surface-2: #20222a;
    --surface-3: #2a2d37;
    --text: #eceef3;
    --text-2: #c3c6d0;
    --muted: #9599a6;
    --line: #2c2f39;
    --line-strong: #3a3e4b;
    --accent: #7b96f5;
    --accent-hover: #93a9f7;
    --accent-soft: #232b45;
    --accent-fg: #0d0f16;
    --danger: #f2766e;
    --danger-soft: #3a2022;
    --ok: #63d394;
    --ok-soft: #1b3226;
    --warn: #f1c35b;
    --warn-soft: #3a3019;
    --focus: 0 0 0 3px rgba(123, 150, 245, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* ---------- utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-family: var(--mono); }
.stack { display: grid; gap: 12px; }
.stack-lg { display: grid; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 550; font-size: .92rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: .84rem; }
.btn-lg { padding: 12px 18px; font-size: 1rem; }
.btn-icon { padding: 7px; }
.btn-block { width: 100%; }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-weight: 550; font-size: .9rem; }
.field .hint { color: var(--muted); font-size: .84rem; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=text], input[type=email], input[type=password], input[type=search], select { height: 40px; }
.center { text-align: center; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); font-weight: 600; }
.text-danger:empty { display: none; }
.check { display: flex; align-items: flex-start; gap: 9px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; height: 60px;
  display: flex; align-items: center; gap: 24px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.02rem; color: var(--text); }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; }
.nav { display: flex; gap: 4px; height: 100%; }
.nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a[aria-current=page] { color: var(--text); border-bottom-color: var(--accent); }
.topbar .account { margin-left: auto; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
@media (max-width: 640px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .topbar .account-email, .brand-name { display: none; }
}

/* ---------- layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 28px 24px 64px; }
@media (max-width: 640px) { .container { padding: 20px 14px 48px; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 1.5rem; letter-spacing: -.01em; }
.page-head p { color: var(--muted); margin-top: 4px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.search { position: relative; flex: 1; max-width: 360px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }

/* ---------- page list ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.list-item {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 14px 16px; border-top: 1px solid var(--line); cursor: pointer; transition: background .1s;
}
.list-item:first-child { border-top: 0; }
.list-item:hover { background: var(--surface-2); }
.file-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.list-item .title { font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.list-item .meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.list-item .actions { display: flex; gap: 6px; align-items: center; }
@media (max-width: 640px) {
  .list-item { grid-template-columns: minmax(0, 1fr) auto; }
  .list-item .file-icon { display: none; }
  .list-item .primary-action { display: none; }
}

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-draft { background: var(--surface-3); color: var(--muted); }
.badge-live { background: var(--ok-soft); color: var(--ok); }
.badge-changes { background: var(--warn-soft); color: var(--warn); }

.empty { text-align: center; padding: 56px 24px; }
.empty .empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.empty h2 { font-size: 1.15rem; margin-bottom: 6px; }
.empty p { color: var(--muted); max-width: 420px; margin: 0 auto 18px; }

/* ---------- tables (users) ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
.table tr:first-child td { border-top: 0; }
.table td.actions { text-align: right; white-space: nowrap; }
@media (max-width: 640px) { .table .hide-sm { display: none; } }

/* ---------- dialogs: modal + side panel ---------- */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(12, 14, 22, .45); }
dialog.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border-radius: 16px; display: flex; flex-direction: column; }
dialog.modal.modal-lg { width: min(760px, calc(100vw - 32px)); }
dialog.modal.modal-full { width: min(1200px, calc(100vw - 32px)); height: calc(100vh - 48px); }
dialog.modal:not([open]), dialog.drawer:not([open]) { display: none; }
.dlg-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 1.1rem; }
.dlg-head .sub { color: var(--muted); font-size: .88rem; margin-top: 3px; }
.dlg-head .close { margin-left: auto; margin-top: -4px; margin-right: -6px; }
.dlg-body { padding: 20px; overflow: auto; flex: 1; }
.dlg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.dlg-foot .left { margin-right: auto; }

dialog.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(520px, 100vw);
  border-radius: 0; display: flex; flex-direction: column;
}
dialog.drawer .dlg-foot { border-radius: 0; }

.section { padding: 18px 0; border-top: 1px solid var(--line); }
.section:first-child { padding-top: 0; border-top: 0; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.danger-zone .section-title { color: var(--danger); }
.action-list { display: grid; gap: 8px; }
.action-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.action-row .label { font-weight: 550; }
.action-row .desc { color: var(--muted); font-size: .84rem; }

/* ---------- wizard ---------- */
.stepper { display: flex; gap: 8px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface-2); overflow-x: auto; }
.step { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; font-weight: 600; white-space: nowrap; }
.step .dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; border: 1.5px solid var(--line-strong); background: var(--surface); }
.step.active { color: var(--text); }
.step.active .dot { border-color: var(--accent); color: var(--accent); }
.step.done .dot { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.step + .step::before { content: ""; width: 24px; height: 1.5px; background: var(--line-strong); margin-right: 4px; }
.step-title { font-size: 1.05rem; font-weight: 650; }
.step-intro { color: var(--muted); margin-top: 4px; }

.dropzone {
  display: grid; place-items: center; text-align: center; gap: 8px; cursor: pointer;
  padding: 34px 20px; border: 2px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--surface-2);
  transition: border-color .12s, background .12s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--surface); color: var(--accent); display: grid; place-items: center; box-shadow: var(--shadow); }
.dropzone strong { font-size: 1rem; }

.file-summary { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--radius); font-size: .9rem; }
.callout svg { flex: none; margin-top: 2px; }
.callout-warn { background: var(--warn-soft); color: var(--warn); }
.callout-info { background: var(--accent-soft); color: var(--text-2); }
.callout-ok { background: var(--ok-soft); color: var(--ok); }
.callout ul { margin: 6px 0 0; padding-left: 18px; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s; }

.big-choice { display: grid; place-items: center; gap: 10px; text-align: center; padding: 28px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-2); }

.summary { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 550; }

.success-mark { width: 56px; height: 56px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto; }

/* ---------- access codes ---------- */
.code-pill { font-family: var(--mono); font-weight: 650; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.code-list { display: grid; gap: 8px; }
.code-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.code-item.expired { opacity: .65; }
.code-item .info { flex: 1; min-width: 0; }
.code-item .label { font-weight: 550; }
.code-item .meta { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.share-box { display: grid; gap: 10px; padding: 16px; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--surface-2); }
.share-box .link { display: flex; gap: 8px; }
.share-box .link input { font-family: var(--mono); font-size: .86rem; }
.reveal { display: none; }
.reveal.open { display: grid; gap: 12px; }

/* ---------- code editor ---------- */
.editor-wrap { display: grid; grid-template-columns: 220px minmax(0, 1fr); flex: 1; width: 100%; min-height: 0; }
.editor-wrap.single { grid-template-columns: minmax(0, 1fr); }
.editor-wrap.single .editor-files { display: none; }
.editor-files { border-right: 1px solid var(--line); overflow: auto; padding: 10px; background: var(--surface-2); }
.editor-files button { display: block; width: 100%; text-align: left; font: inherit; font-size: .86rem; padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--text-2); cursor: pointer; }
.editor-files button:hover { background: var(--surface-3); }
.editor-files button[aria-current=true] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.editor-text { width: 100%; height: 100%; border: 0; border-radius: 0; resize: none; padding: 16px 18px; font: 13.5px/1.6 var(--mono); tab-size: 2; background: var(--surface); white-space: pre; overflow: auto; }
.editor-text:focus { box-shadow: none; }
dialog.modal.modal-full .dlg-body { padding: 0; display: flex; min-height: 0; }
@media (max-width: 720px) { .editor-wrap { grid-template-columns: 1fr; } .editor-files { display: none; } }

/* ---------- menus + toasts ---------- */
.menu {
  position: fixed; z-index: 1000; min-width: 210px; padding: 6px; display: grid;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; font-size: .9rem; padding: 8px 10px; border: 0; border-radius: 7px; background: none; color: var(--text); cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); box-shadow: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu .menu-label { padding: 6px 10px; font-size: .8rem; color: var(--muted); }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 2000; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: .92rem; animation: toast-in .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .7s linear infinite; }
.loading { display: grid; place-items: center; padding: 48px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 28px; display: grid; gap: 16px; }
.login-card .brand { margin-bottom: 4px; }
.login-card h1 { font-size: 1.3rem; }
.login-card .error { color: var(--danger); font-size: .9rem; min-height: 1.3em; }
