:root {
  --bg: #0e1114;
  --panel: #151a1f;
  --panel-2: #1d242b;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9ecef;
  --muted: #93a0aa;
  --soft: #c7d0d6;
  --accent: #55c2b8;
  --accent-2: #e1b85c;
  --danger: #e06c75;
  --success: #79d39a;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
  --radius: 20px;
  --radius-sm: 14px;
  --font-body: "Trebuchet MS", "Verdana", sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(85, 194, 184, 0.16), transparent 34%),
    radial-gradient(circle at top right, rgba(225, 184, 92, 0.12), transparent 28%),
    linear-gradient(180deg, #11161b 0%, #0b0e12 100%);
  font-family: var(--font-body);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,0.85), transparent 86%);
  mask-image: linear-gradient(180deg, rgba(0,0,0,0.85), transparent 86%);
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 30px rgba(85, 194, 184, 0.24);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--soft);
  font-size: 12px;
}

.pill.ok { color: var(--success); border-color: rgba(121, 211, 154, 0.25); }
.pill.warn { color: var(--accent-2); border-color: rgba(225, 184, 92, 0.25); }
.pill.bad { color: var(--danger); border-color: rgba(224, 108, 117, 0.25); }

.grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(21, 26, 31, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.panel-header {
  padding: 18px 18px 0;
}

.panel-body {
  padding: 18px;
}

.login-card .panel-body { display: grid; gap: 12px; }
.login-card { width: 400px; max-width: 100%; }

.login-section {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 140px);
}

.pw-wrap { position: relative; }

.pw-input { padding-right: 48px; }

.pw-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 0;
}

.pw-toggle:hover { color: var(--soft); }

.btn-full { width: 100%; margin-top: 4px; }

.section-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 18px;
}

.section-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.field-grid { display: grid; gap: 10px; }

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.input, .textarea, .select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(9, 12, 15, 0.72);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  outline: none;
}

.textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.6;
  white-space: pre-wrap;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: rgba(85, 194, 184, 0.65);
  box-shadow: 0 0 0 3px rgba(85, 194, 184, 0.12);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #4fa2d1); color: #081015; }
.btn-secondary { background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--soft); border: 1px solid var(--line); }

.stack { display: grid; gap: 14px; }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }

.metric {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
}

.metric span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.metric strong { font-size: 20px; }

.dashboard {
  display: grid;
  gap: 18px;
}

.dashboard[data-active="false"] { display: none; }

.main-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.list {
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  border-radius: 16px;
  padding: 14px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}

.item.active {
  border-color: rgba(85, 194, 184, 0.55);
  background: rgba(85, 194, 184, 0.08);
}

.item .name { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 700; }
.item .sub { margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }

.sidebar-card .panel-body { display: grid; gap: 12px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.backups-row { align-items: center; margin-top: 10px; }
.backups-row label { font-size: 13px; color: var(--soft); }
.backups-row select { min-width: 220px; }

.editor-card .panel-body { display: grid; gap: 14px; }

.doc-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--soft);
  cursor: pointer;
  font-size: 13px;
}

.tab.active {
  background: rgba(85, 194, 184, 0.12);
  border-color: rgba(85, 194, 184, 0.4);
  color: var(--text);
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.section-refresh-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.section-refresh-bar .btn {
  font-size: 0.8rem;
  padding: 4px 10px;
  white-space: nowrap;
}

.refresh-url-input {
  flex: 1;
  min-width: 200px;
  font-size: 0.78rem;
  padding: 3px 10px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  background: rgba(9, 12, 15, 0.72);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.refresh-url-input:focus {
  border-color: rgba(85, 194, 184, 0.65);
  box-shadow: 0 0 0 3px rgba(85, 194, 184, 0.12);
}

.refresh-url-input::placeholder {
  color: var(--muted);
}

.section-refresh-status {
  font-size: 0.8rem;
  color: var(--muted, #64748b);
  white-space: nowrap;
}

.status-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: status-spin 0.7s linear infinite;
  vertical-align: middle;
  opacity: 0.7;
  margin-right: 4px;
  will-change: transform;
}

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

.doc-editor {
  min-height: 520px;
  width: 100%;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.notice {
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: rgba(255,255,255,0.03);
  color: var(--soft);
  line-height: 1.5;
}

.notice.error { color: #f7c6cb; border-color: rgba(224,108,117,0.28); background: rgba(224,108,117,0.08); }
.notice.success { color: #c9f0d9; border-color: rgba(121,211,154,0.28); background: rgba(121,211,154,0.08); }
.notice.warn { color: #f3e2b8; border-color: rgba(225,184,92,0.28); background: rgba(225,184,92,0.08); }

.full-sync-card {
  margin-top: 24px;
  padding: 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.02);
}
.full-sync-card .btn { margin: 10px 0; }
.full-sync-results {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.full-sync-results li {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px 12px;
  font-size: 13px;
}
.full-sync-results li.ok { color: var(--success); border-color: rgba(121, 211, 154, 0.25); }
.full-sync-results li.bad { color: var(--danger); border-color: rgba(224, 108, 117, 0.25); }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.hidden { display: none !important; }

.split {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.token-box {
  display: grid;
  gap: 10px;
}

.token-output {
  min-height: 92px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ── Intake panel ─────────────────────────────────────── */
.intake-panel { margin-bottom: 18px; }

.btn-sm { padding: 7px 11px; font-size: 12px; border-radius: 10px; }

/* ── Client summary strip ─────────────────────────────── */
.client-summary-strip {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 0 -0px;
}

.summary-chip { font-size: 12px; color: var(--muted); letter-spacing: 0.03em; }
.summary-chip.ok { color: var(--success); }
.summary-chip.missing { color: var(--danger); }

/* ── Gathered info collapsibles ───────────────────────── */
.field-label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}

.info-section { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }

.info-section details {
  border-bottom: 1px solid var(--line);
}
.info-section details:last-child { border-bottom: none; }

.info-section summary {
  padding: 11px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--soft);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
}
.info-section summary::-webkit-details-marker { display: none; }
.info-section summary::before { content: "▶"; font-size: 10px; color: var(--muted); transition: transform 0.15s; }
.info-section details[open] summary::before { transform: rotate(90deg); }
.info-section summary:hover { color: var(--text); background: rgba(255,255,255,0.02); }

.info-section pre {
  white-space: pre-wrap;
  font: inherit;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  padding: 10px 16px 16px;
  margin: 0;
  background: rgba(0,0,0,0.15);
}

.empty-file {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 16px 12px;
  margin: 0;
  font-style: italic;
}

.chip-missing {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(224,108,117,0.15);
  color: var(--danger);
  margin-left: 4px;
}

/* ── Doc textarea ─────────────────────────────────────── */
.doc-textarea { min-height: 340px; }

/* ── Token details panel ──────────────────────────────── */
.token-details {
  overflow: hidden;
}

.token-summary {
  padding: 16px 20px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  color: var(--soft);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
}
.token-summary::-webkit-details-marker { display: none; }
.token-summary::before { content: "▶"; font-size: 10px; color: var(--muted); transition: transform 0.15s; }
.token-details[open] .token-summary::before { transform: rotate(90deg); }
.token-summary:hover { color: var(--text); }


.doc-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(85, 194, 184, 0.10);
  color: var(--accent);
  font-weight: 400;
}

@media (max-width: 1180px) {
  .grid, .main-grid, .split { grid-template-columns: 1fr; }
  .statusbar { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .shell { padding: 14px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .metrics { grid-template-columns: 1fr; }
  .doc-editor { min-height: 360px; }
}

/* ── Smart knowledge file editors ─────────────────────── */

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.25rem 0;
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.editor-field label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

/* Personality selector */
.personality-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.personality-card {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  -webkit-user-select: none;
  user-select: none;
  color: var(--soft);
}

.personality-card:hover {
  border-color: rgba(85, 194, 184, 0.45);
  color: var(--text);
}

.personality-card.selected {
  border-color: var(--accent);
  background: rgba(85, 194, 184, 0.1);
  color: var(--accent);
  font-weight: 700;
}

/* Color palette */
.color-palette {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.color-row-label {
  font-size: 0.78rem;
  color: var(--muted);
  width: 80px;
  flex-shrink: 0;
  font-family: monospace;
}

.color-swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  background: none;
}

.color-swatch::-webkit-color-swatch-wrapper {
  padding: 2px;
  border-radius: 8px;
}

.color-swatch::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.color-hex-input {
  font-family: monospace;
  font-size: 0.82rem;
  width: 100px;
  border-radius: 10px !important;
}

/* Q&A pairs and section cards */
.qa-list,
.section-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.qa-pair,
.doc-section {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  position: relative;
}

.remove-pair-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  transition: color 0.12s, background 0.12s;
}

.remove-pair-btn:hover {
  color: var(--danger);
  background: rgba(224, 108, 117, 0.12);
}

.add-pair-btn {
  align-self: flex-start;
  margin-top: 0.25rem;
}

/* Two-column row inside product cards (Item # / Size) */
.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ── Client status ──────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
  vertical-align: middle;
}
.status-dot--active   { background: var(--success); }
.status-dot--inactive { background: var(--muted); }

.item[data-status="inactive"] .name { opacity: 0.55; }

/* ── Danger button variant ──────────────────────── */
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
}
.btn-danger:hover { opacity: 0.85; }

/* ── Inactive clients sub-section (inside sidebar) ─ */
.inactive-section { margin-top: 4px; }

.inactive-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 2px 4px;
}

.inactive-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.inactive-row:hover { border-color: rgba(255,255,255,0.14); color: var(--soft); }
.inactive-row.active { border-color: rgba(85, 194, 184, 0.45); background: rgba(85, 194, 184, 0.06); color: var(--text); }

.inactive-name { flex: 1; font-weight: 600; }

.inactive-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(147, 160, 170, 0.15);
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Admin navigation bar ────────────────────────────── */
.admin-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.admin-nav-link {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.admin-nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

.admin-nav-link.active {
  color: var(--accent);
  background: rgba(85, 194, 184, 0.1);
  border-color: rgba(85, 194, 184, 0.3);
}

/* ── Dashboard nav cards ─────────────────────────────── */
.nav-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-top: 8px;
}

.nav-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.18s, transform 0.18s, box-shadow 0.18s;
}

.nav-card:hover {
  border-color: rgba(85, 194, 184, 0.4);
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.nav-card-icon {
  font-size: 32px;
  line-height: 1;
}

.nav-card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--text);
}

.nav-card-desc {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

/* ── Inline token section ────────────────────────────── */
.token-inline {
  margin-top: 16px;
  padding: 20px 24px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

/* ── Field label row (label + action button side by side) */
.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.field-label-row .field-label { margin: 0; }

/* ── Global Settings Hub section divider ─────────────── */
.section-divider {
  border: none;
  border-top: 1px solid var(--surface-2, #2b3035);
  margin: 24px 0 8px;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
}

/* ── New .md file modal ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.hint-inline {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
/* ── Product accordion ──────────────────────────────────── */
.product-accordion-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.product-accordion-header .p-name {
  flex: 1 1 auto;
  font-weight: 500;
}
.product-accordion-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  flex: 0 0 auto;
  line-height: 1;
}
.product-accordion-toggle:hover { color: var(--text); }
.product-accordion-detail {
  padding: 8px 0 8px 20px;
  border-left: 2px solid var(--line);
  margin-left: 10px;
  margin-bottom: 4px;
}
.product-accordion-detail.hidden { display: none; }
