/* SecureChat — single stylesheet for public page and admin panel */
:root {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #dfe7ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #e3f6ef 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e3e7f0;
  --text: #131a2a;
  --muted: #5d6781;
  --primary: #3555e8;
  --primary-ink: #ffffff;
  --primary-soft: #e9eeff;
  --success: #12805c;
  --success-soft: #e3f6ee;
  --warn: #a8610a;
  --warn-soft: #fff3df;
  --danger: #c22f3c;
  --danger-soft: #fdeaec;
  --bubble-in: #eef1f8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c111d;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #18234a 0%, transparent 60%), radial-gradient(900px 500px at 110% 10%, #0f2e27 0%, transparent 55%);
    --surface: #141b2b;
    --surface-2: #101624;
    --border: #252f45;
    --text: #e8ecf6;
    --muted: #97a1ba;
    --primary: #6d87ff;
    --primary-ink: #0b1020;
    --primary-soft: #1c2650;
    --success: #4fd1a1;
    --success-soft: #11312a;
    --warn: #f3b25a;
    --warn-soft: #33260f;
    --danger: #ff7884;
    --danger-soft: #3a161c;
    --bubble-in: #1b2438;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: 1200px; }

.topbar { padding: 18px 0 8px; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #7b5cf0); color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; }

.label-fair {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  background: var(--warn-soft); color: var(--warn);
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  cursor: pointer; font-family: inherit;
}
.label-fair svg { width: 14px; height: 14px; }

.hero { text-align: center; padding: 18px 0 20px; }
.hero h1 { font-size: clamp(24px, 5vw, 34px); letter-spacing: -.02em; }
.hero p { color: var(--muted); max-width: 520px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }

.footer { padding: 28px 0 36px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 4px; border-radius: 12px; margin-bottom: 20px;
}
.tab {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 8px; border-radius: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.tab svg { width: 16px; height: 16px; flex: none; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.seg { display: inline-grid; grid-auto-flow: column; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg label { padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--text); }
.seg label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.08); color: var(--text); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--primary); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field > label, .field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 5px; }
.input, .textarea, .select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
  background: var(--surface);
}
.textarea { min-height: 130px; resize: vertical; }
.input.mono, .textarea.mono { font-family: var(--mono); font-size: 13px; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; }
.input-wrap .peek {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px;
}
.input-wrap .peek svg { width: 18px; height: 18px; display: block; }
.counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 5px; }
.is-invalid { border-color: var(--danger) !important; }


/* Security level dropdown */
.level-picker {
  margin-bottom: 18px; padding: 14px;
  border: 1.5px solid color-mix(in srgb, var(--primary) 45%, var(--border));
  border-radius: 12px; background: var(--primary-soft);
}
.level-picker-label {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-weight: 700; font-size: 15px; color: var(--primary);
}
.level-picker-label svg { width: 18px; height: 18px; flex: none; }
.select-lg {
  appearance: none; -webkit-appearance: none;
  font-size: 16px; font-weight: 600; padding: 13px 44px 13px 14px; min-height: 50px;
  background-color: var(--surface); border-color: var(--border); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7bd8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px;
  text-overflow: ellipsis;
}
.select-lg:focus { background-color: var(--surface); }
.level-desc { margin: 9px 2px 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); cursor: pointer;
  transition: filter .15s, transform .05s; text-decoration: none !important; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn svg { width: 17px; height: 17px; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- Alerts / badges ---------- */
.alert { border-radius: 11px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; display: flex; gap: 10px; align-items: flex-start; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert-info { background: var(--primary-soft); color: var(--text); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.alert-success { background: var(--success-soft); color: var(--text); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.alert-warn { background: var(--warn-soft); color: var(--text); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--text); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert ul { margin: 0; padding-left: 18px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- Result / secret boxes ---------- */
.secret {
  display: flex; gap: 8px; align-items: stretch; margin-top: 6px;
}
.secret output, .secret textarea {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 13px;
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; word-break: break-all; color: var(--text);
}
.secret textarea { resize: vertical; min-height: 90px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- Chat bubbles ---------- */
.thread { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.bubble {
  max-width: 88%; padding: 11px 14px; border-radius: 16px 16px 16px 5px;
  background: var(--bubble-in); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word;
}
.bubble.locked { color: var(--muted); font-style: italic; border-style: dashed; }
.bubble-meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; white-space: normal; font-style: normal; }
.thread.admin .bubble { max-width: 100%; }

.timeline { list-style: none; padding: 0; margin: 10px 0 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }

/* ---------- Modal ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  width: min(520px, calc(100vw - 32px));
}
dialog.modal::backdrop { background: rgba(8, 12, 24, .55); }
.modal-body { padding: 22px; }
.modal-body ul { padding-left: 18px; margin: 0 0 14px; }
.modal-body li { margin-bottom: 6px; }

/* ---------- Admin ---------- */
.admin-nav { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.admin-nav .wrap { display: flex; align-items: center; gap: 14px; height: 60px; }
.admin-nav .brand { font-size: 16px; }
.admin-links { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.admin-links::-webkit-scrollbar { display: none; }
.admin-links a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; }
.admin-links a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.admin-links a.active { background: var(--primary-soft); color: var(--primary); }
.admin-user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.admin-main { padding: 22px 0 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }

.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.stat.alert-stat .n { color: var(--danger); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; flex: 1 1 150px; }
.filters .field > label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.filters .input, .filters .select { padding: 8px 10px; font-size: 14px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.preview { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-pad { padding: 16px 18px; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 14px; list-style: none; margin: 0; }
.pagination a, .pagination span { display: inline-block; min-width: 36px; text-align: center; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; }
.pagination .current span { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.pagination .disabled span { opacity: .5; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-shell .card { width: 100%; max-width: 400px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .card { padding: 16px; border-radius: 12px; }
  .row-2 { grid-template-columns: 1fr; gap: 0; }
  .tab { flex-direction: column; gap: 3px; font-size: 13px; padding: 8px 4px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .bubble { max-width: 100%; }
  .secret { flex-direction: column; }
  .hero { padding: 8px 0 14px; }
  .label-fair .lf-text-long { display: none; }

  .stats { grid-template-columns: repeat(2, 1fr); }
  .admin-nav .wrap { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 8px; row-gap: 8px; }
  .admin-links { order: 3; flex-basis: 100%; }
  .admin-user .who { display: none; }

  /* Tables become stacked cards */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
  .table.stack td::before { content: attr(data-label); font-size: 12px; color: var(--muted); flex: none; }
  .table.stack td.full { display: block; }
  .table.stack td.full::before { display: block; margin-bottom: 2px; }
  .preview { max-width: 100%; white-space: normal; }
}

/* ---------- Utilities (no inline styles: CSP) ---------- */
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 22px; }
.mb-md { margin-bottom: 14px; }
.mb-0 { margin-bottom: 0; }
.level-hint { margin: -4px 0 14px; min-height: 1em; }
.inline { display: inline; }
.flex-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
