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

:root {
  --bg: #080808;
  --panel: #111111;
  --panel-up: #1a1a1a;
  --border: #222222;
  --border-light: #2a2a2a;
  --accent: #7c3aed;
  --accent-light: #a855f7;
  --accent-glow: rgba(124, 58, 237, 0.2);
  --text: #f0f0f0;
  --text-dim: #888888;
  --text-muted: #555555;
  --radius: 12px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

/* ====== HEADER ====== */
.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hdr-link {
  font-size: 13px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 8px;
  transition: all 0.15s;
}
.hdr-link:hover { border-color: var(--accent); color: var(--text); }

.back-btn {
  font-size: 13px;
  color: var(--text-dim);
  transition: color 0.15s;
}
.back-btn:hover { color: var(--text); }

/* ====== HOME CENTER ====== */
.home-center {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
  padding-top: max(15vh, 60px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ====== TOOLBAR ====== */
.toolbar {
  position: relative;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.tb-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  min-height: 36px;
}
.tb-pill:hover, .tb-pill.open {
  border-color: var(--accent);
  background: rgba(124,58,237,0.06);
}

/* ====== DROPDOWNS ====== */
.dd {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 260px;
  max-width: 440px;
  z-index: 110;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  animation: ddIn 0.15s ease;
}
.dd.open { display: block; }

@keyframes ddIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.dd-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
}
.dd-overlay.active { display: block; }

.dd-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.dd-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.dd-row { flex-wrap: nowrap; }

.dd-ratio-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.dd-link {
  display: block;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--accent-light);
}
.dd-link:hover { text-decoration: underline; }

.dd-empty { font-size: 13px; color: var(--text-muted); padding: 8px 0; }

.dd-preset-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }

.dd-preset-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  text-align: left;
  transition: border-color 0.15s;
  width: 100%;
}
.dd-preset-item:hover { border-color: var(--accent); }
.dd-preset-item strong { font-size: 13px; font-weight: 600; }
.dd-preset-text { font-size: 11px; color: var(--text-dim); }

/* ====== OPTIONS (inside dropdowns) ====== */
.opt {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}
.opt:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.opt.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt:disabled { opacity: 0.25; cursor: not-allowed; }
.opt-full { width: 100%; justify-content: flex-start; }
.opt-sub { margin-left: auto; font-size: 11px; opacity: 0.5; }
.dd-row .opt { flex: 1; }

.opt-ratio {
  flex-direction: column;
  padding: 6px 4px;
  gap: 3px;
  min-height: 48px;
}
.r-shape {
  border: 1.5px solid currentColor;
  border-radius: 2px;
  opacity: 0.4;
  transition: opacity 0.15s;
}
.opt-ratio:hover .r-shape, .opt-ratio.active .r-shape { opacity: 1; }
.r-text { font-size: 9px; font-weight: 500; white-space: nowrap; }

/* ====== PROMPT BOX ====== */
.home-prompt-wrap { width: 100%; }

.prompt-box {
  display: flex;
  align-items: flex-end;
  background: var(--panel-up);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.prompt-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.prompt-ref {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px;
  transition: all 0.15s;
}
.prompt-ref:hover { border-color: var(--accent); color: var(--accent-light); }

.prompt-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-family: 'Inter', sans-serif;
  line-height: 1.5;
  resize: none;
  min-height: 80px;
  max-height: 200px;
  padding: 10px 12px;
}
.prompt-box textarea:focus { outline: none; }
.prompt-box textarea::placeholder { color: var(--text-muted); }

.prompt-submit {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px;
  transition: all 0.2s;
}
.prompt-submit:hover { background: var(--accent-light); box-shadow: 0 0 16px var(--accent-glow); }
.prompt-submit:disabled { opacity: 0.4; cursor: not-allowed; }

.ref-previews { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 8px; }
.ref-previews:empty { display: none; }
.ref-preview {
  position: relative; width: 52px; height: 52px;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
}
.ref-preview img { width: 100%; height: 100%; object-fit: cover; }
.ref-remove {
  position: absolute; top: 0; right: 0;
  width: 18px; height: 18px;
  background: rgba(0,0,0,0.8); color: #fff;
  border: none; border-radius: 0 8px 0 6px;
  cursor: pointer; font-size: 12px;
  line-height: 18px; text-align: center;
}

/* ====== RECENT SESSIONS ====== */
.home-recent {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
}

.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.sess-card {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.sess-card:hover {
  border-color: rgba(124,58,237,0.3);
  box-shadow: 0 0 16px var(--accent-glow);
}

.sess-thumb {
  aspect-ratio: 1;
  background: var(--bg);
  overflow: hidden;
}
.sess-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sess-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; opacity: 0.2;
}
.sess-meta {
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-dim);
}

.load-more-wrap { text-align: center; padding-top: 20px; }
.load-more-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
}
.load-more-btn:hover { border-color: var(--accent); color: var(--text); }

/* ====== SESSION PAGE ====== */
.sess-layout {
  display: flex;
  height: 100vh;
}

.sess-left {
  width: 380px;
  min-width: 380px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.sess-left .back-btn {
  display: block;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sess-chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-item {
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.chat-item:hover { background: rgba(255,255,255,0.03); }
.chat-item.active {
  border-color: var(--accent);
  background: rgba(124,58,237,0.06);
}
.chat-item img {
  width: 100%;
  border-radius: 6px;
  display: block;
  margin-bottom: 6px;
}
.chat-prompt {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.sess-input {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sess-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.sess-input-row textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  resize: none;
  min-height: 72px;
  max-height: 150px;
}
.sess-input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.sess-input-row textarea::placeholder { color: var(--text-muted); }

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

.stb-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.12s;
}
.stb-pill:hover { border-color: var(--accent); color: var(--text); }
.stb-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.stb-sep { width: 1px; background: var(--border); margin: 0 2px; }

.sess-action-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border: none;
  color: #fff;
  padding: 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  min-height: 44px;
  transition: opacity 0.2s;
}
.sess-action-btn:hover { opacity: 0.9; }
.sess-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Right panel */
.sess-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.sess-viewer-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.vbar-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
}
.vbar-btn:hover { border-color: var(--accent); }

.sess-viewer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.sess-viewer-empty {
  color: var(--text-muted);
  font-size: 14px;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.viewer-img:hover {
  box-shadow: 0 0 20px var(--accent-glow);
}

.viewer-skeleton {
  width: 400px;
  height: 400px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.shimmer {
  width: 100%; height: 100%;
  background: linear-gradient(90deg, var(--panel) 25%, rgba(124,58,237,0.05) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: shimmer 2s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ====== ADMIN ====== */
.admin-wrap {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 20px;
}

.admin-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.admin-input, .admin-textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
}
.admin-input:focus, .admin-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.admin-textarea { resize: vertical; min-height: 80px; }

.admin-btn {
  align-self: flex-start;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
}
.admin-btn:hover { background: var(--accent-light); }

.admin-table table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.admin-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.preset-text-cell { color: var(--text-dim); max-width: 400px; }
.admin-del {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.admin-del:hover { border-color: #dc2626; color: #dc2626; }
.admin-empty { color: var(--text-muted); font-size: 13px; }

/* ====== ERROR TOAST ====== */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #dc2626;
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
}
.error-toast.visible { transform: translateX(-50%) translateY(0); }

/* ====== MOBILE ====== */
@media (max-width: 768px) {
  .sess-layout { flex-direction: column; height: auto; min-height: 100vh; }
  .sess-left { width: 100%; min-width: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  .sess-right { min-height: 50vh; }
  .sessions-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .home-center { padding-top: max(8vh, 40px); }
}
