/* Drakoyuda Chatbots — theme tokens via data-theme */
:root,
[data-theme="light"] {
  --bg: #f7f4ec;
  --bg-soft: #fcfaf3;
  --surface: #ffffff;
  --surface-muted: #f1ece0;
  --ink: #161a23;
  --ink-soft: #2c3240;
  --muted: #6a6154;
  --border: rgba(22, 26, 35, 0.08);
  --border-strong: rgba(201, 150, 47, 0.5);
  --gold: #c9962f;
  --gold-deep: #876418;
  --accent: #c9962f;
  --accent-ink: #1f1405;
  --danger: #c23a3a;
  --success: #2f9b6a;
  --warning: #c79417;
  --shadow-sm: 0 2px 6px rgba(22, 26, 35, 0.04);
  --shadow-md: 0 10px 30px rgba(22, 26, 35, 0.08);
  --shadow-lg: 0 30px 60px rgba(22, 26, 35, 0.12);
  --radius-sm: 0.55rem;
  --radius-md: 0.9rem;
  --radius-lg: 1.2rem;
}

[data-theme="dark"] {
  --bg: #0d0f14;
  --bg-soft: #12141b;
  --surface: rgba(18, 21, 28, 0.92);
  --surface-muted: rgba(245, 235, 218, 0.06);
  --ink: #f6f0e7;
  --ink-soft: #e2dccf;
  --muted: #a99f8e;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(226, 179, 60, 0.4);
  --gold: #e2b33c;
  --gold-deep: #b88619;
  --accent: #e2b33c;
  --accent-ink: #1f1405;
  --danger: #ff7b72;
  --success: #59d499;
  --warning: #f5c96c;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html { font-size: 16px; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  transition: background 220ms ease, color 220ms ease;
}
body.modal-open { overflow: hidden; }

a { color: inherit; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3, h4 {
  margin: 0;
  font-family: "Fraunces", serif;
  letter-spacing: -0.02em;
  color: var(--ink);
}
h1 { font-size: clamp(1.8rem, 3.2vw, 2.4rem); line-height: 1.1; }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); }
h3 { font-size: 1.2rem; }
h4 { font-size: 1.02rem; line-height: 1.3; }

.kicker {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold-deep);
}
[data-theme="dark"] .kicker { color: var(--gold); }

.muted { color: var(--muted); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, border-color 140ms ease;
  text-decoration: none;
  font-size: 0.9rem;
}
.button:hover { transform: translateY(-1px); }
.button.primary {
  background: var(--gold);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}
.button.primary:hover { background: var(--gold-deep); color: #fff8e7; }
.button.primary.danger { background: var(--danger); color: #fff; box-shadow: 0 10px 24px rgba(194, 58, 58, 0.25); }
.button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}
.button.ghost:hover { background: var(--surface-muted); border-color: var(--border-strong); }
.button.ghost.danger { color: var(--danger); border-color: rgba(194, 58, 58, 0.35); }
.button.ghost.danger:hover { background: rgba(194, 58, 58, 0.1); }
.button.small { padding: 0.45rem 0.8rem; font-size: 0.82rem; }
.button.full { width: 100%; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
input[type="file"] { padding: 0.55rem 0.6rem; }
textarea { resize: vertical; min-height: 200px; font-family: inherit; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(201, 150, 47, 0.12);
}

.form-stack { display: grid; gap: 0.9rem; }
.form-stack label { display: grid; gap: 0.35rem; font-size: 0.88rem; }
.form-stack label > span { color: var(--muted); font-size: 0.82rem; font-weight: 600; letter-spacing: 0.02em; }
.form-row { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }
.form-row label.grow { grid-column: span 2; }
@media (max-width: 640px) { .form-row label.grow { grid-column: span 1; } }

.inline-form { display: inline-flex; margin: 0; }

.flash {
  margin: 0.8rem 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.92rem;
}
.flash-success { background: rgba(47, 155, 106, 0.12); border-color: rgba(47, 155, 106, 0.35); color: var(--success); }
.flash-error { background: rgba(194, 58, 58, 0.12); border-color: rgba(194, 58, 58, 0.4); color: var(--danger); }
[data-theme="dark"] .flash-success { color: var(--success); }
[data-theme="dark"] .flash-error { color: var(--danger); }

/* theme toggle — icon + label */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: border-color 140ms ease, background 140ms ease;
}
.theme-toggle:hover { border-color: var(--border-strong); }
.toggle-icon {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 35%, var(--gold), var(--gold-deep));
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.12);
  position: relative;
}
[data-theme="dark"] .toggle-icon {
  background: var(--ink);
  box-shadow: inset 4px -4px 0 var(--gold);
}

/* brand */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: var(--ink);
}
.brand-lockup img {
  width: 42px; height: 42px;
  border-radius: 0.85rem;
  background: var(--surface);
  object-fit: cover;
  border: 1px solid var(--border);
}
.brand-lockup div { display: flex; flex-direction: column; line-height: 1.05; }
.brand-lockup strong {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 1.2rem;
}
.brand-lockup-login img { width: 54px; height: 54px; border-radius: 1rem; }
.brand-lockup-small img { width: 36px; height: 36px; border-radius: 0.6rem; }

/* =================== login =================== */
.login-body {
  background:
    radial-gradient(circle at 18% -10%, rgba(201, 150, 47, 0.18), transparent 40%),
    radial-gradient(circle at 90% 110%, rgba(22, 26, 35, 0.05), transparent 40%),
    var(--bg);
}
[data-theme="dark"] .login-body {
  background:
    radial-gradient(circle at 18% -10%, rgba(226, 179, 60, 0.18), transparent 40%),
    radial-gradient(circle at 90% 110%, rgba(88, 112, 255, 0.16), transparent 40%),
    var(--bg);
}
.login-stage { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.login-card {
  width: min(440px, 100%);
  padding: 2.2rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 1rem;
}
.login-card .lead { margin: 0; color: var(--muted); line-height: 1.55; }
.login-footer { display: flex; justify-content: center; margin-top: 0.5rem; }

/* =================== admin shell =================== */
.admin-body {
  background: var(--bg);
}
.admin-shell {
  width: min(1320px, calc(100% - 1.2rem));
  margin: 0 auto;
  padding: 1.6rem 0.2rem 3rem;
}
.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: center;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}
.admin-nav { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.user-chip {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(201, 150, 47, 0.14);
  color: var(--gold-deep);
  font-size: 0.82rem;
  font-weight: 600;
}
[data-theme="dark"] .user-chip { background: rgba(226, 179, 60, 0.14); color: var(--gold); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.4rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 700; }
.stat-value { font-family: "Fraunces", serif; font-size: 2rem; letter-spacing: -0.02em; color: var(--ink); }
.stat-card.actions { justify-content: center; gap: 0.5rem; flex-direction: row; flex-wrap: wrap; }
.stat-card.actions .button { flex: 1 1 auto; min-width: 0; }

.empty-hero {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  margin-bottom: 1.5rem;
}
.empty-hero h2 { margin-bottom: 0.5rem; }
.empty-hero p { color: var(--muted); max-width: 40rem; margin: 0 auto; line-height: 1.6; }

.group { margin-bottom: 2rem; }
.group-head {
  display: flex; justify-content: space-between; gap: 0.8rem; align-items: flex-end;
  margin-bottom: 0.8rem; padding: 0 0.2rem;
  flex-wrap: wrap;
}
.group-head h3 { font-size: 1.6rem; }
.group-kicker { display: block; color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; font-weight: 700; margin-bottom: 0.3rem; }

.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.9rem;
}
.bot-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.bot-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.bot-card.archived { opacity: 0.75; filter: grayscale(0.2); }
.bot-cover {
  aspect-ratio: 16 / 9;
  background: var(--surface-muted);
  overflow: hidden;
  position: relative;
}
.bot-cover img { width: 100%; height: 100%; object-fit: cover; }
.bot-cover-empty {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-family: "Fraunces", serif;
  font-size: 2.6rem;
  color: var(--gold);
  background: linear-gradient(135deg, rgba(201, 150, 47, 0.14), rgba(22, 26, 35, 0.04));
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.bot-body { padding: 0.9rem 1rem 1rem; display: grid; gap: 0.5rem; }
.bot-preview { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.5; min-height: 2.6em; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bot-meta { color: var(--muted); font-size: 0.78rem; display: flex; gap: 0.4rem; align-items: center; }
.bot-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.4rem; }

.archived-group { opacity: 0.9; }

.admin-section { margin-top: 2.5rem; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.8rem;
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: grid; gap: 0.35rem;
}
.admin-card.self {
  border-color: var(--border-strong);
  background: linear-gradient(160deg, rgba(201, 150, 47, 0.06), transparent 70%), var(--surface);
}
.admin-card .kicker { margin-bottom: 0.3rem; }
.admin-card .created { color: var(--muted); font-size: 0.78rem; margin: 0; }
.admin-card-actions { display: flex; gap: 0.4rem; margin-top: 0.4rem; flex-wrap: wrap; }

/* =================== modals =================== */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(18, 22, 30, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
[data-theme="dark"] .modal-backdrop { background: rgba(0, 0, 0, 0.75); }
.modal-card {
  position: relative; z-index: 1;
  width: min(560px, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem 1.5rem;
  box-shadow: var(--shadow-lg);
  display: grid; gap: 0.9rem;
}
.modal-card.wide { width: min(820px, 100%); }
.modal-card.slim { width: min(420px, 100%); }
.modal-card h3 { padding-right: 2rem; }
.modal-close {
  position: absolute; top: 0.7rem; right: 0.9rem;
  width: 2rem; height: 2rem;
  border-radius: 999px;
  border: 0; background: var(--surface-muted);
  color: var(--ink); cursor: pointer;
  font-size: 1.1rem; line-height: 1;
}
.modal-close:hover { background: var(--border-strong); color: var(--accent-ink); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 0.3rem; }
.modal-actions.spread { justify-content: flex-start; }
.modal-actions .spacer { flex: 1; }
.doc-list { display: grid; gap: 0.4rem; }
.doc-list .kicker { font-size: 0.72rem; }
.doc-list ul { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 0.35rem; }
.doc-list li { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); background: var(--surface-muted); font-size: 0.88rem; }
.doc-link { color: var(--ink); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }

.danger-details { margin-top: 0.8rem; border-top: 1px dashed var(--border); padding-top: 0.8rem; }
.danger-details summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.doc-remove-list { display: grid; gap: 0.35rem; margin-top: 0.6rem; }
.doc-remove-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); background: var(--surface-muted); }
.doc-remove-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =================== public bot page =================== */
.public-body {
  background:
    radial-gradient(circle at 10% -10%, rgba(201, 150, 47, 0.14), transparent 40%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
[data-theme="dark"] .public-body {
  background:
    radial-gradient(circle at 10% -10%, rgba(226, 179, 60, 0.16), transparent 40%),
    var(--bg);
}
.public-header {
  width: min(1100px, calc(100% - 1.4rem));
  margin: 0 auto;
  padding: 1.3rem 0;
  display: flex; justify-content: space-between; gap: 0.6rem; align-items: center;
  flex-wrap: wrap;
}
.public-header-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.public-stage {
  width: min(1100px, calc(100% - 1.4rem));
  margin: 0 auto;
  padding-bottom: 3rem;
  display: grid; gap: 2rem;
}
.public-hero {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
@media (max-width: 720px) { .public-hero { grid-template-columns: 1fr; } }
.public-hero-image {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-muted);
  box-shadow: var(--shadow-sm);
}
.public-hero-image img { width: 100%; height: 100%; object-fit: cover; }
.public-hero-monogram {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-family: "Fraunces", serif;
  font-size: clamp(3rem, 10vw, 5rem);
  color: var(--gold);
  background: linear-gradient(135deg, rgba(201, 150, 47, 0.16), rgba(22, 26, 35, 0.06));
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.public-hero-copy .kicker { margin-bottom: 0.4rem; }
.public-hero-copy h1 { margin-bottom: 0.4rem; }
.public-description {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.7rem 1.9rem;
  box-shadow: var(--shadow-sm);
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--ink-soft);
}
.public-description p { margin: 0 0 1rem; }
.public-description p:last-child { margin-bottom: 0; }

.public-docs { display: grid; gap: 0.8rem; }
.public-docs h2 { margin-bottom: 0.4rem; }
.public-doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.public-doc-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.8rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
}
@media (max-width: 640px) { .public-doc-list li { grid-template-columns: auto 1fr; } .public-doc-list li .doc-actions { grid-column: 1 / -1; justify-content: flex-end; } }
.doc-badge {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  background: rgba(201, 150, 47, 0.18);
  color: var(--gold-deep);
  padding: 0.35rem 0.55rem;
  border-radius: 0.5rem;
}
[data-theme="dark"] .doc-badge { color: var(--gold); background: rgba(226, 179, 60, 0.18); }
.doc-body { display: grid; gap: 0.1rem; min-width: 0; }
.doc-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-body span { font-size: 0.78rem; }
.doc-actions { display: flex; gap: 0.4rem; align-items: center; }

.public-footer {
  width: min(1100px, calc(100% - 1.4rem));
  margin: 2rem auto 2rem;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.82rem; color: var(--muted);
}
.empty-stage {
  min-height: 60vh;
  display: grid; place-items: center;
  padding: 2rem;
  text-align: center;
}
