/* ==========================================================================
   Zyphora admin — shared design system
   Self-hosted fonts, theme tokens (dark + light), base components.
   Loaded by dashboard.html, user.html and login.html.
   ========================================================================== */

/* ---------- Fonts ---------- */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/plus-jakarta-sans.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono.woff2") format("woff2");
}

/* ---------- Theme tokens ---------- */
:root {
  color-scheme: dark;

  --font-sans: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #070a13;
  --bg-2: #0a0f1b;
  --surface: #0f1420;
  --surface2: #151c2b;
  --surface3: #1b2436;
  --border: #222c3f;
  --border2: #303d57;

  --text: #eef2fb;
  --text2: #97a2bc;
  --text3: #6a7591;

  --accent: #8f7dff;
  --accent2: #6c5cf7;
  --accent3: #4c40d6;
  --accent-soft: rgba(143, 125, 255, 0.12);
  --accent-line: rgba(143, 125, 255, 0.34);

  --cyan: #35d6e8;
  --cyan-soft: rgba(53, 214, 232, 0.12);
  --gold: #f3b64a;
  --gold-soft: rgba(243, 182, 74, 0.12);
  --success: #35d6a4;
  --success-soft: rgba(53, 214, 164, 0.12);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.12);
  --info: #4cc3ff;
  --info-soft: rgba(76, 195, 255, 0.12);

  --topbar-bg: rgba(7, 10, 19, 0.74);
  --overlay: rgba(3, 6, 14, 0.66);
  --scroll-thumb: #2b374e;

  --ring: 0 0 0 3px rgba(143, 125, 255, 0.22);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32), 0 2px 10px rgba(0, 0, 0, 0.16);
  --shadow: 0 14px 36px rgba(2, 6, 18, 0.44);
  --shadow-lg: 0 30px 80px rgba(2, 6, 18, 0.58);

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --topbar-h: 70px;

  --grad-brand: linear-gradient(135deg, #8f7dff 0%, #6c5cf7 46%, #35d6e8 130%);
  --grad-primary: linear-gradient(135deg, #8f7dff 0%, #5b4bea 100%);
}

html[data-theme="light"] {
  color-scheme: light;

  --bg: #f3f6fc;
  --bg-2: #eaf0fa;
  --surface: #ffffff;
  --surface2: #f7f9fe;
  --surface3: #eef3fb;
  --border: #e2e8f4;
  --border2: #cfd9ea;

  --text: #0f172b;
  --text2: #5b6884;
  --text3: #7c88a0;

  --accent: #6455f5;
  --accent2: #5748e6;
  --accent3: #4437c9;
  --accent-soft: rgba(100, 85, 245, 0.09);
  --accent-line: rgba(100, 85, 245, 0.26);

  --cyan: #0e9db4;
  --cyan-soft: rgba(14, 157, 180, 0.1);
  --gold: #a9700b;
  --gold-soft: rgba(169, 112, 11, 0.1);
  --success: #0d8f6b;
  --success-soft: rgba(13, 143, 107, 0.1);
  --danger: #d92c50;
  --danger-soft: rgba(217, 44, 80, 0.08);
  --info: #0b74c0;
  --info-soft: rgba(11, 116, 192, 0.08);

  --topbar-bg: rgba(255, 255, 255, 0.78);
  --overlay: rgba(15, 23, 43, 0.34);
  --scroll-thumb: #c3cee2;

  --ring: 0 0 0 3px rgba(100, 85, 245, 0.18);
  --shadow-sm: 0 1px 2px rgba(15, 23, 43, 0.05), 0 2px 10px rgba(15, 23, 43, 0.04);
  --shadow: 0 14px 34px rgba(15, 23, 43, 0.09);
  --shadow-lg: 0 30px 80px rgba(15, 23, 43, 0.18);

  --grad-primary: linear-gradient(135deg, #7a6bff 0%, #5142e2 100%);
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

body,
h1, h2, h3, h4, p, figure { margin: 0; }

html { background: var(--bg); }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1000px 560px at 8% -12%, var(--accent-soft), transparent 62%),
    radial-gradient(820px 520px at 102% -6%, var(--cyan-soft), transparent 58%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color 0.18s; }
a:hover { color: var(--accent2); }

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
img, svg { display: block; max-width: 100%; }

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text3); background-clip: content-box; }

/* ---------- Icons ---------- */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 17px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
  transition: transform 0.18s var(--ease), background 0.18s, border-color 0.18s,
    box-shadow 0.18s, color 0.18s, filter 0.18s;
}
.btn:hover {
  background: var(--surface3);
  border-color: var(--border2);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0) scale(0.985); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn .icon { width: 16px; height: 16px; }

.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; border-radius: 8px; }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 14px; }

.btn-primary {
  background: var(--grad-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 24px rgba(108, 92, 247, 0.28);
}
.btn-primary:hover {
  background: var(--grad-primary);
  filter: brightness(1.08);
  box-shadow: 0 14px 30px rgba(108, 92, 247, 0.36);
}

.btn-ghost { background: transparent; border-color: var(--border2); color: var(--text2); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-danger {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 24px rgba(225, 29, 72, 0.24);
}
.btn-danger:hover { filter: brightness(1.06); box-shadow: 0 14px 30px rgba(225, 29, 72, 0.32); }

.btn-success {
  background: linear-gradient(135deg, #34d399, #059669);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 24px rgba(5, 150, 105, 0.24);
}
.btn-success:hover { filter: brightness(1.06); box-shadow: 0 14px 30px rgba(5, 150, 105, 0.3); }

.btn-icon { width: 38px; height: 38px; padding: 0; }

/* ---------- Form controls ---------- */
.input,
.select,
.form-group input,
.form-group textarea,
.form-group select,
textarea {
  width: 100%;
  height: 40px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
.input::placeholder,
textarea::placeholder { color: var(--text3); }

.input:hover,
.select:hover,
.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover { border-color: var(--border2); }

.input:focus,
.select:focus,
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--ring);
}

.select,
.form-group select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 36px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2397a2bc' stroke-width='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 12px center;
  background-size: 12px;
}

textarea { height: auto; min-height: 96px; padding: 11px 13px; resize: vertical; line-height: 1.55; }

input[type="checkbox"],
input[type="radio"] { accent-color: var(--accent); cursor: pointer; }

input[type="datetime-local"] { color-scheme: inherit; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
}
.form-group textarea { min-height: 96px; }

/* ---------- Cards / panels ---------- */
.card,
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card { padding: 20px; margin-top: 18px; }
.panel { padding: 22px; margin-top: 20px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.panel-head h3 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.panel-head p { margin-top: 3px; font-size: 12px; color: var(--text2); }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}
.panel-actions .meta {
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
}
.panel-actions .meta.error { color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th,
td { padding: 13px 18px; text-align: left; font-size: 12.5px; white-space: nowrap; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface2);
  color: var(--text2);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover td { background: var(--accent-soft); }

.cell-main { display: flex; flex-direction: column; gap: 3px; }
.cell-main strong { font-weight: 600; }
.cell-main span { color: var(--text2); font-size: 11px; }

.mono {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: -0.02em;
  color: var(--text2);
}

code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--gold);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: rgba(148, 163, 184, 0.13); color: var(--text2); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Mini stats, chips ---------- */
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.mini-stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  transition: border-color 0.18s, background 0.18s;
}
.mini-stat:hover { border-color: var(--accent-line); background: var(--surface); }
.mini-stat .k,
.mini-stat .label {
  color: var(--text2);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.mini-stat .v { margin-top: 5px; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
}

/* ---------- Status / feedback ---------- */
.warning {
  display: none;
  margin-top: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border: 1px solid rgba(243, 182, 74, 0.26);
  color: var(--gold);
  font-size: 12px;
  line-height: 1.5;
}
.warning.show { display: block; animation: fadeUp 0.35s var(--ease) both; }

.result {
  display: none;
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.5;
}
.result.show { display: block; animation: fadeUp 0.3s var(--ease) both; }
.result.success { background: var(--success-soft); color: var(--success); }
.result.error { background: var(--danger-soft); color: var(--danger); }

.error-box {
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid rgba(251, 113, 133, 0.28);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.55;
}

.loading,
.empty {
  color: var(--text2);
  text-align: center;
  padding: 38px 20px;
  font-size: 13px;
}
.loading { position: relative; }
.loading::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseDot 1.1s ease-in-out infinite;
  vertical-align: middle;
}

.hint { color: var(--text2); font-size: 11.5px; line-height: 1.55; }
.meta { color: var(--text2); font-size: 12px; }
.spacer { flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease both; }

.modal-box {
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 26px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.32s var(--ease) both;
}
.modal-box.small { max-width: 360px; text-align: center; }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.modal-head h3 { font-size: 18px; font-weight: 700; }
.modal-head p { margin-top: 4px; color: var(--text2); font-size: 12px; word-break: break-all; }

.modal-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  font-size: 16px;
  transition: all 0.18s;
}
.modal-close:hover { color: var(--text); border-color: var(--accent-line); background: var(--surface3); }

.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  overflow: hidden;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent-line); background: var(--surface3); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--ring); }
.theme-toggle .icon {
  position: absolute;
  width: 17px;
  height: 17px;
  transition: transform 0.45s var(--ease), opacity 0.28s;
}
.theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.55); }
.theme-toggle .icon-moon { opacity: 1; transform: none; }
html[data-theme="light"] .theme-toggle .icon-sun { opacity: 1; transform: none; }
html[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.55); }

/* ---------- Shared bits ---------- */
.status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(53, 214, 164, 0.5);
  animation: pulseDot 2.4s ease-out infinite;
}

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

.raw-json { margin-top: 14px; }
.raw-json summary {
  cursor: pointer;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.raw-json summary::-webkit-details-marker { display: none; }
.raw-json summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.2s var(--ease);
}
.raw-json[open] summary::before { transform: rotate(45deg); }
.raw-json pre {
  margin-top: 10px;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text2);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  overflow-x: auto;
}

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes navIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(53, 214, 164, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(53, 214, 164, 0); }
  100% { box-shadow: 0 0 0 0 rgba(53, 214, 164, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes growBar { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
