/* ─── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── Tokens (dark default) ─────────────────────────────────────────── */
:root {
  /* XUL brand */
  --xul-purple:   #5B2A86;
  --xul-purple-2: #7A3FAF;
  --xul-red:      #D42E2E;
  --xul-red-2:    #E8473D;

  /* Surfaces */
  --bg:            #0A0A0B;
  --bg-1:          #111113;
  --bg-2:          #161619;
  --bg-3:          #1D1D21;
  --surface:       #141418;
  --surface-hover: #1A1A20;

  /* Text */
  --fg:       #EDEDEE;
  --fg-muted: #A1A1A8;
  --fg-subtle:#6C6C74;

  /* Borders */
  --border:       #222228;
  --border-strong:#2E2E36;

  /* Accents */
  --accent:      var(--xul-purple-2);
  --accent-soft: rgba(122, 63, 175, 0.14);
  --accent-ring: rgba(122, 63, 175, 0.35);

  /* Semantic */
  --success: #3BB97A;
  --warn:    #E8B84A;
  --danger:  var(--xul-red-2);
  --info:    #6AA6F1;

  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow-lg: 0 20px 40px -12px rgba(0,0,0,.5), 0 8px 16px -8px rgba(0,0,0,.4);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --sidebar-w: 240px;
}

/* ─── Light mode ────────────────────────────────────────────────────── */
body.light {
  --bg:            #FAFAFA;
  --bg-1:          #FFFFFF;
  --bg-2:          #F5F5F7;
  --bg-3:          #EFEFF2;
  --surface:       #FFFFFF;
  --surface-hover: #F7F7F9;
  --fg:       #14141A;
  --fg-muted: #58585F;
  --fg-subtle:#8A8A92;
  --border:       #E5E5EA;
  --border-strong:#D4D4DB;
  --shadow-lg: 0 12px 32px -12px rgba(20,20,30,.12), 0 4px 10px -4px rgba(20,20,30,.08);
}

/* ─── Base ──────────────────────────────────────────────────────────── */
html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01","cv11";
  line-height: 1.5;
  font-size: 14px;
  display: flex;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 30px; height: 30px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-weight: 700; font-size: 11px; letter-spacing: .5px;
  flex-shrink: 0;
}

.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }

.sidebar-nav {
  flex: 1;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-subtle);
  padding: 14px 10px 6px;
}

.sidebar-nav ul { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all .12s;
  cursor: pointer;
}

.sidebar-nav li a:hover { background: var(--surface-hover); color: var(--fg); }

.sidebar-nav li.active a {
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 500;
}

.sidebar-nav li.active a .cat-icon { color: var(--accent); }

.cat-icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }

.cat-count {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-subtle);
}

/* ─── Main ──────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg);
  flex-shrink: 0;
}

.topbar-left { flex: 1; }

.topbar-left h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.topbar-left p {
  font-size: 12px;
  color: var(--fg-muted);
  margin-top: 1px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 240px;
  transition: all .12s;
}

.search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.search-wrap svg {
  width: 14px; height: 14px;
  color: var(--fg-subtle);
  flex-shrink: 0;
}

.search-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 13px;
}

.search-wrap input::placeholder { color: var(--fg-subtle); }

.content { flex: 1; overflow-y: auto; padding: 28px; }

/* ─── Template grid ─────────────────────────────────────────────────── */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

.template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all .12s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.template-card:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-emoji {
  width: 38px; height: 38px;
  background: var(--accent-soft);
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-image { color: var(--warn);    background: color-mix(in oklch, var(--warn) 14%, transparent); }
.badge-video { color: var(--xul-red-2); background: color-mix(in oklch, var(--xul-red-2) 14%, transparent); }
.badge-text  { color: var(--success); background: color-mix(in oklch, var(--success) 14%, transparent); }
.badge-data  { color: var(--info);    background: color-mix(in oklch, var(--info) 14%, transparent); }
.badge-audio { color: var(--accent);  background: var(--accent-soft); }

.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-desc {
  font-size: 12.5px;
  color: var(--fg-muted);
  line-height: 1.5;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 500;
}

.card-meta svg { width: 13px; height: 13px; }

.card-arrow {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  font-family: var(--font);
}

/* ─── Empty state ───────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-muted);
  font-size: 13px;
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ─── Template editor ───────────────────────────────────────────────── */
.template-editor { display: flex; flex-direction: column; gap: 18px; }
.template-editor.hidden { display: none; }
#template-grid.hidden { display: none; }

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px 6px 4px;
  border-radius: var(--radius-sm);
  transition: all .12s;
}

.back-btn:hover { background: var(--surface-hover); color: var(--fg); }
.back-btn svg { width: 15px; height: 15px; }

.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 900px) { .editor-layout { grid-template-columns: 1fr; } }

/* ── Form panel ─────────────────────────────────────────────────────── */
.editor-form-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.editor-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-header h2 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.editor-header p {
  font-size: 12.5px;
  color: var(--fg-muted);
  line-height: 1.5;
}

.editor-fields {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field-group { display: flex; flex-direction: column; gap: 6px; }

.field-group label {
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.field-group label span.required { color: var(--xul-red-2); margin-left: 2px; }

.field-group input,
.field-group textarea,
.field-group select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-2);
  color: var(--fg);
  outline: none;
  transition: all .12s;
  width: 100%;
}

.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus {
  border-color: var(--accent);
  background: var(--bg-1);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field-group select { appearance: auto; }
.field-group textarea { resize: vertical; min-height: 76px; line-height: 1.5; }

.field-hint {
  font-size: 11px;
  color: var(--fg-subtle);
  line-height: 1.4;
}

/* Color row */
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="text"] { flex: 1; font-family: var(--mono); font-size: 12px; }

.color-swatch {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 3px;
  background: var(--bg-2);
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
}
.color-swatch input[type="color"] {
  width: 100%; height: 100%;
  border: none; padding: 0; cursor: pointer;
  border-radius: 3px;
  background: none;
}

/* Chips */
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-2);
  color: var(--fg-muted);
  transition: all .12s;
  user-select: none;
}

.chip:hover { background: var(--surface-hover); color: var(--fg); }

.chip.selected {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

/* Actions */
.editor-actions {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg-2);
}

.btn-primary {
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}
.btn-primary:hover { background: var(--xul-purple); }

.btn-ghost {
  padding: 8px 14px;
  background: var(--bg-3);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); color: var(--fg); }

/* ── Preview panel ──────────────────────────────────────────────────── */
.editor-preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}

.preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg-subtle);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}
.copy-btn:disabled { opacity: .35; cursor: default; }
.copy-btn:not(:disabled):hover { background: var(--xul-purple); }
.copy-btn svg { width: 13px; height: 13px; }
.copy-btn.copied { background: var(--success); }

.prompt-preview {
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 280px;
  max-height: 68vh;
  overflow-y: auto;
}

.preview-placeholder {
  color: var(--fg-subtle);
  font-family: var(--font);
  font-size: 13px;
}

/* ─── Logout button ─────────────────────────────────────────────────── */
.topbar-right { display: flex; align-items: center; gap: 10px; }

.logout-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  transition: all .12s;
  flex-shrink: 0;
}
.logout-btn svg { width: 16px; height: 16px; }
.logout-btn:hover { background: var(--surface-hover); color: var(--danger); border-color: var(--danger); }

/* ─── Login screen ──────────────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 1000;
  overflow: hidden;
}

.login-bg-blob {
  position: absolute;
  width: 520px; height: 520px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  filter: blur(80px);
  z-index: 0;
  animation: float 20s infinite alternate ease-in-out;
  pointer-events: none;
}

@keyframes float {
  0%   { transform: translate(-20%, -20%) scale(1); }
  100% { transform: translate(20%, 20%) scale(1.2); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px;
  text-align: center;
  animation: slideUp .6s cubic-bezier(.16, 1, .3, 1);
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.login-logo-wrap { margin-bottom: 28px; }

.login-logo {
  height: 28px;
  width: auto;
  color: var(--fg);
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.2));
}

.login-header { margin-bottom: 28px; }

.login-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.login-header p {
  font-size: 13px;
  color: var(--fg-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-input-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-left: 2px;
}

.login-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--fg);
  outline: none;
  transition: all .2s;
  width: 100%;
}

.login-input::placeholder { color: var(--fg-subtle); }

.login-input:focus {
  border-color: var(--accent);
  background: var(--bg-1);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in oklch, var(--xul-red-2) 12%, transparent);
  border: 1px solid color-mix(in oklch, var(--xul-red-2) 28%, transparent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--xul-red-2);
}

.login-error svg { width: 15px; height: 15px; flex-shrink: 0; }

.login-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  transition: all .2s;
}

.login-submit:hover:not(:disabled) {
  background: var(--xul-purple);
  transform: translateY(-1px);
}

.login-submit:active { transform: translateY(0); }

.login-submit:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

.login-spinner {
  width: 18px; height: 18px;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.login-footer {
  margin-top: 28px;
  font-size: 11px;
  color: var(--fg-subtle);
}

/* ─── App shell ─────────────────────────────────────────────────────── */
#app-shell {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: row;
}
