/* ============================================================
   Lumen — design tokens
   Minimal, dark, professional AI SaaS UI.
   ============================================================ */
:root {
  --bg: #0a0b0d;
  --bg-elevated: #131519;
  --surface: #16181d;
  --surface-hover: #1b1e24;
  --border: #24272e;
  --border-strong: #34383f;
  --text: #edeef0;
  --text-muted: #8b909b;
  --text-faint: #5c6169;
  --accent: #5b7fff;
  --accent-hover: #7192ff;
  --accent-muted: rgba(91, 127, 255, 0.12);
  --danger: #e5484d;
  --danger-muted: rgba(229, 72, 77, 0.12);
  --success: #3dbd8b;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --font-display: "Sora", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;

  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.35);
  --transition: 150ms ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

p { margin: 0; }

a { color: inherit; text-decoration: none; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

img { display: block; max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Layout ---------- */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 24px 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.logo-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  display: inline-block;
  position: relative;
}
.logo-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  background: var(--bg);
  border-radius: 3px;
}

.main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px 64px;
}

/* ---------- Home: generator ---------- */
.generator {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.generator h1 {
  font-size: 30px;
  line-height: 1.2;
}

.generator .subtitle {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 15px;
}

.upload-box {
  width: 100%;
  margin-top: 32px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-box:hover,
.upload-box.dragover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.upload-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.upload-box .upload-title {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}

.upload-box .upload-hint {
  font-size: 12.5px;
  color: var(--text-faint);
}

.upload-box input[type="file"] { display: none; }

/* Uploaded preview state */
.upload-preview {
  width: 100%;
  margin-top: 32px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}
.upload-preview img {
  width: 100%;
  height: 220px;
  object-fit: cover;
}
.upload-preview .remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(10, 11, 13, 0.72);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-preview .remove-btn:hover { background: rgba(10, 11, 13, 0.9); }

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 500;
  padding: 12px 18px;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
}

.btn-secondary {
  width: 100%;
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }

.btn-primary {
  width: 100%;
  margin-top: 24px;
  background: var(--accent);
  color: #fff;
  padding: 14px 18px;
  font-size: 15px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled {
  background: var(--surface);
  color: var(--text-faint);
  border: 1px solid var(--border);
  cursor: not-allowed;
}

/* Selected template chip */
.selected-template {
  width: 100%;
  margin-top: 14px;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  text-align: left;
}
.selected-template.visible { display: flex; }
.selected-template img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.selected-template .info { flex: 1; min-width: 0; }
.selected-template .info .label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.selected-template .info .name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selected-template .change-btn {
  font-size: 12.5px;
  color: var(--accent);
  background: none;
  border: none;
  padding: 4px 6px;
  flex-shrink: 0;
}
.selected-template .change-btn:hover { color: var(--accent-hover); }

/* ---------- Generate: loading + result ---------- */
.generate-status {
  width: 100%;
  margin-top: 20px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.generate-status.visible { display: flex; }

.progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 3s linear;
}

.status-text {
  font-size: 13px;
  color: var(--text-muted);
}

.result-card {
  width: 100%;
  margin-top: 24px;
  display: none;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.result-card.visible { display: flex; }

.result-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

.result-card img {
  width: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.result-actions {
  display: flex;
  gap: 10px;
}
.result-actions .btn-ghost,
.result-actions .btn-accent {
  flex: 1;
  text-align: center;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 9, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 640px;
  max-height: 82vh;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 17px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.modal-search {
  padding: 14px 20px 0;
  flex-shrink: 0;
}
.modal-search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 13.5px;
}
.modal-search input::placeholder { color: var(--text-faint); }
.modal-search input:focus { border-color: var(--accent); outline: none; }

.modal-categories {
  display: flex;
  gap: 8px;
  padding: 14px 20px 0;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.modal-categories::-webkit-scrollbar { display: none; }

.pill {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.pill:hover { color: var(--text); }
.pill.active {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.modal-grid {
  padding: 16px 20px 20px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.template-item { text-align: left; }
.template-item .thumb-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1.5px solid transparent;
  background: var(--surface);
  aspect-ratio: 1 / 1;
  position: relative;
}
.template-item.selected .thumb-wrap { border-color: var(--accent); }
.template-item img { width: 100%; height: 100%; object-fit: cover; }

.template-item .check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
}
.template-item.selected .check { display: flex; }

.template-item .tname {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 30px 0;
}

/* ============================================================
   Admin
   ============================================================ */
.admin-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar .logo { padding: 6px 8px 22px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link.active { background: var(--accent-muted); color: var(--accent-hover); }
.nav-link svg { flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.admin-main {
  flex: 1;
  padding: 32px 36px 60px;
  max-width: 1080px;
}

.admin-header { margin-bottom: 28px; }
.admin-header h1 { font-size: 22px; }
.admin-header p { margin-top: 6px; color: var(--text-muted); font-size: 14px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 30px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); }
.stat-card .stat-value {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 { font-size: 15px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
.btn-accent:hover { background: var(--accent-hover); }

/* table */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table .row-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}
.table .tpl-name { font-weight: 500; }
.table .tpl-prompt {
  color: var(--text-muted);
  font-size: 12.5px;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.badge.active { background: rgba(61, 189, 139, 0.12); color: var(--success); }
.badge.draft { background: var(--surface-hover); color: var(--text-muted); border: 1px solid var(--border); }

.row-actions { display: flex; gap: 6px; }
.row-actions button, .row-actions a {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.row-actions button:hover, .row-actions a:hover { color: var(--text); background: var(--surface-hover); }
.row-actions .delete-btn:hover { color: var(--danger); border-color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
  font-size: 13.5px;
}

/* form */
.form-grid {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 560px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 7px;
}
.field .hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-body);
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.image-drop {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  background: var(--bg-elevated);
}
.image-drop:hover { border-color: var(--accent); }
.image-drop img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.image-drop .drop-text { font-size: 13.5px; color: var(--text-muted); }
.image-drop input[type="file"] { display: none; }

.status-toggle {
  display: flex;
  gap: 8px;
}
.status-option {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 13.5px;
  color: var(--text-muted);
}
.status-option.active-choice {
  border-color: var(--accent);
  background: var(--accent-muted);
  color: var(--accent-hover);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* mobile top nav for admin */
.mobile-topbar { display: none; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    overflow-x: auto;
  }
  .sidebar .logo { display: none; }
  .sidebar-footer { display: none; }
  .nav-link { flex-shrink: 0; }
  .admin-main { padding: 22px 16px 50px; }
  .stats-row { grid-template-columns: 1fr; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 44px 1fr auto;
    grid-template-areas:
      "thumb name actions"
      "thumb meta actions";
    gap: 3px 12px;
    align-items: center;
  }
  .table td { padding: 0; border-bottom: none; }
  .table td:nth-child(1) { grid-area: thumb; }
  .table td:nth-child(2) { grid-area: name; }
  .table td:nth-child(3) { grid-area: meta; }
  .table td:nth-child(4) { display: none; }
  .table td:nth-child(5) { grid-area: meta; }
  .table td:nth-child(6) { grid-area: actions; }
}

@media (max-width: 520px) {
  .main { padding: 24px 16px 48px; }
  .generator h1 { font-size: 24px; }
  .btn-primary, .btn-secondary { padding: 14px 16px; font-size: 15px; }
  .modal { max-height: 88vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { padding: 16px; }
  .image-drop { flex-direction: column; align-items: flex-start; }
}
