:root {
  --bg: #15171b;
  --bg-2: #181b20;
  --surface: #1e2228;
  --surface-2: #23272f;
  --border: #2c323b;
  --border-soft: #262b33;
  --text: #d7dae0;
  --text-soft: #969ca6;
  --text-dim: #6b717b;
  --accent: #ff7a1a;
  --accent-bright: #ff9647;
  --accent-dim: #b85f14;
  --accent-glow: rgba(255, 122, 26, 0.16);
  --ok: #4ec08c;
  --ok-bg: rgba(78, 192, 140, 0.10);
  --ok-border: rgba(78, 192, 140, 0.32);
  --danger: #ff6258;
  --danger-bg: rgba(255, 98, 88, 0.10);
  --danger-border: rgba(255, 98, 88, 0.38);
  --warn: #e8b84b;
  --mono: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(900px 520px at 82% -8%, rgba(255,122,26,0.12), transparent 60%),
    radial-gradient(700px 520px at -10% 18%, rgba(255,122,26,0.05), transparent 55%);
  pointer-events: none;
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: -2;
  background-image:
    linear-gradient(rgba(255,255,255,0.020) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.020) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 24%, #000, transparent 88%);
  mask-image: radial-gradient(circle at 50% 24%, #000, transparent 88%);
  pointer-events: none;
}

.scanbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 2px; z-index: 20;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  background-size: 45% 100%;
  background-repeat: no-repeat;
  animation: scan 7s linear infinite;
  opacity: 0.85;
}
@keyframes scan { 0% { background-position: -50% 0; } 100% { background-position: 150% 0; } }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 24px 110px; }

.status-strip {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 16px 0 0;
  font-family: var(--mono); font-size: 0.72rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-soft); flex-wrap: wrap;
}
.status-left { display: flex; align-items: center; gap: 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,122,26,0.55); }
  70% { box-shadow: 0 0 0 9px rgba(255,122,26,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,122,26,0); }
}
#clock { color: var(--text-dim); }

header { border-bottom: 1px solid var(--border); padding: 26px 0 30px; }
.site-name { font-size: 2.4rem; font-weight: 800; letter-spacing: -0.03em; margin: 0; line-height: 1.05; }
.site-name .lock { color: var(--accent); text-shadow: 0 0 22px rgba(255,122,26,0.4); }
.tagline { margin: 12px 0 0; color: var(--text-soft); font-size: 1rem; font-weight: 400; }
.tagline .bar { color: var(--accent); margin: 0 9px; }

section { margin-top: 52px; }
.sec-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; padding-bottom: 9px; border-bottom: 1px solid var(--border); }
.sec-num { font-family: var(--mono); font-size: 0.74rem; color: var(--accent); letter-spacing: 0.12em; }
h2 { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.13em; margin: 0; color: var(--text); }

p { margin: 0 0 16px; }
p:last-child { margin-bottom: 0; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(255,122,26,0.35); }
a:hover { border-bottom-color: var(--accent); }
strong { font-weight: 600; color: #e8eaee; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
.muted { color: var(--text-dim); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 18px 18px 15px; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.stat.ok::before { background: var(--ok); }
.stat.alert::before { background: var(--danger); }
.stat .num { font-size: 2.1rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; }
.stat .lab { font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-soft); margin-top: 8px; }

.note {
  background: linear-gradient(180deg, rgba(255,122,26,0.06), rgba(255,122,26,0.02));
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 4px; padding: 16px 20px; margin-top: 18px; font-size: 0.95rem; color: var(--text-soft);
}
.note p { margin: 0; }
ul.principles { margin: 18px 0 0; padding-left: 1.2em; }
ul.principles li { margin-bottom: 8px; }
ul.principles li::marker { color: var(--accent); }
ul.principles li:last-child { margin-bottom: 0; }

.log-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 200px; }
.search-wrap::before { content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-soft); font-size: 0.95rem; }
.search-wrap input {
  width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 0.84rem; padding: 9px 12px 9px 31px;
}
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
  font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 7px 11px; border-radius: 6px; cursor: pointer; transition: all 0.14s ease;
}
.chip:hover { color: var(--text); border-color: var(--text-dim); }
.chip.active { background: rgba(255,122,26,0.12); border-color: var(--accent); color: var(--accent); }
.chip[data-filter="backonline"].active { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

.row-count { font-family: var(--mono); font-size: 0.74rem; color: var(--text-soft); white-space: nowrap; }
.row-count b { color: var(--accent); font-weight: 600; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--surface); }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; scroll-margin-top: 24px; }
tbody tr:hover { background: rgba(255,122,26,0.05); }
thead th {
  font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-soft); background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: relative;
}
#log thead th { cursor: pointer; user-select: none; }
#log thead th::after { content: "↕"; opacity: 0.3; margin-left: 7px; font-size: 0.85em; }
#log thead th[data-sort="asc"]::after { content: "↑"; opacity: 1; color: var(--accent); }
#log thead th[data-sort="desc"]::after { content: "↓"; opacity: 1; color: var(--accent); }
#log thead th:hover { color: var(--text); }

td.ref { font-family: var(--mono); font-size: 0.74rem; color: var(--accent); white-space: nowrap; }
td.date { font-family: var(--mono); font-size: 0.8rem; color: var(--text-soft); white-space: nowrap; }
td.target { font-family: var(--mono); font-size: 0.8rem; color: var(--text); }
td.outcome { min-width: 150px; }
td.empty { color: var(--text-dim); font-style: italic; text-align: center; }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 9px; border-radius: 11px; border: 1px solid var(--border);
  color: var(--text-soft); white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.done { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }
.status.pending { color: var(--accent); border-color: rgba(255,122,26,0.35); background: rgba(255,122,26,0.08); }
.status.resurfaced { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.status.pending::before { animation: pulse-sm 1.8s ease-out infinite; }
.status.resurfaced::before { animation: pulse-red 1.6s ease-out infinite; }
@keyframes pulse-sm {
  0% { box-shadow: 0 0 0 0 rgba(255,122,26,0.5); }
  70% { box-shadow: 0 0 0 5px rgba(255,122,26,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,122,26,0); }
}
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(255,98,88,0.55); }
  70% { box-shadow: 0 0 0 5px rgba(255,98,88,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,98,88,0); }
}

.xref { display: inline-block; margin-left: 7px; font-family: var(--mono); font-size: 0.72rem; color: var(--text-dim); }
.ref-link { color: var(--accent); border-bottom: 1px dotted rgba(255,122,26,0.5); white-space: nowrap; }
.ref-link:hover { border-bottom-style: solid; }

tbody tr.flash { animation: rowflash 1.8s ease-out; }
@keyframes rowflash { 0% { background: rgba(255,122,26,0.32); } 100% { background: transparent; } }

.log-hint { font-size: 0.8rem; color: var(--text-dim); margin-top: 13px; font-style: italic; }

/* ---- shared form controls ---- */
.fld { display: flex; flex-direction: column; gap: 5px; }
.fld-wide { grid-column: 1 / -1; }
.fld > span { font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-soft); }
input, select, textarea {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--mono); font-size: 0.85rem; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn {
  display: inline-block; font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 9px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); transition: all 0.14s ease; background: transparent; color: var(--text-soft);
}
a.btn { border-bottom: 1px solid var(--border); }
.btn-sm { padding: 6px 10px; font-size: 0.68rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a1206; font-weight: 700; }
.btn-primary:hover { background: var(--accent-bright); border-color: var(--accent-bright); }
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
.btn-ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.admin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.admin-actions { display: flex; gap: 8px; flex-wrap: wrap; grid-column: 1 / -1; margin-top: 4px; align-items: center; }
.next-ref { font-family: var(--mono); font-size: 0.74rem; color: var(--text-soft); margin-right: auto; }
.next-ref b { color: var(--accent); }

/* ---- contact ---- */
.email-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.contact-email { font-family: var(--mono); font-size: 1.02rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 11px 16px; color: var(--text); }
.copy-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-soft);
  font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em;
  padding: 8px 13px; border-radius: 6px; cursor: pointer; transition: all 0.15s ease;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.copied { color: var(--ok); border-color: var(--ok-border); }
.contact-uses { margin: 20px 0 0; padding-left: 1.2em; color: var(--text-soft); font-size: 0.95rem; }
.contact-uses li { margin-bottom: 6px; }
.contact-uses li::marker { color: var(--accent); }

footer { margin-top: 76px; padding-top: 24px; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--text-dim); line-height: 1.6; }
footer .meta { font-family: var(--mono); font-size: 0.72rem; margin-top: 12px; color: var(--text-soft); }
footer .meta b { color: var(--accent); font-weight: 600; }
footer .meta a { color: var(--text-dim); border: none; text-decoration: underline; text-underline-offset: 2px; }
footer .meta a:hover { color: var(--accent); }

/* ---- auth / login ---- */
.auth-wrap { max-width: 360px; margin: 12vh auto 0; }
.auth-brand { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 22px; }
.auth-tag { font-family: var(--mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; vertical-align: middle; }
.auth-form { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 22px; }
.auth-form .btn-primary { margin-top: 4px; }
.auth-back { margin-top: 18px; font-size: 0.82rem; }
.auth-back a { color: var(--text-soft); border: none; }

/* ---- flash messages ---- */
.flash { border-radius: 6px; padding: 11px 14px; margin: 0 0 14px; font-size: 0.85rem; border: 1px solid var(--border); }
.flash-ok { color: var(--ok); border-color: var(--ok-border); background: var(--ok-bg); }
.flash-err { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.flash-warn { color: var(--warn); border-color: rgba(232,184,75,0.4); background: rgba(232,184,75,0.08); }
.flash code { color: inherit; }

/* ---- admin layout ---- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--border); margin-bottom: 22px; flex-wrap: wrap; }
.topbar-brand { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-link { color: var(--text-soft); font-size: 0.82rem; border: none; }
.topbar-user { font-family: var(--mono); font-size: 0.74rem; color: var(--text-dim); }
.inline-form { display: inline; margin: 0; }

.stats-admin { margin-bottom: 26px; }

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 22px; margin-top: 22px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-title { font-family: var(--mono); font-size: 0.8rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.07em; margin: 0 0 16px; }
.card-head .card-title { margin: 0; }

table.entries { font-size: 0.86rem; }
table.entries thead th { background: var(--surface); }
.row-actions { white-space: nowrap; display: flex; gap: 6px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .site-name { font-size: 1.95rem; }
  .admin-form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .scanbar, .dot, .status.pending::before, .status.resurfaced::before, tbody tr.flash { animation: none; }
}
.js [data-reveal] { opacity: 0; transform: translateY(14px); transition: opacity 0.6s ease, transform 0.6s ease; }
.js [data-reveal].in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .js [data-reveal] { opacity: 1; transform: none; transition: none; }
}
