:root {
  --bg: #0d0d0f;
  --bg-2: #141417;
  --bg-3: #1b1b20;
  --border: #26262c;
  --border-2: #34343c;
  --text: #ececf1;
  --text-dim: #9a9aa5;
  --text-faint: #5b5b63;
  --accent: #d9a53f;
  --accent-hover: #e6b654;
  --accent-text: #171310;
  --danger: #e5534b;
  --ok: #4cae6a;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 650; margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 550;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 8px 14px;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
}
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border-2); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: #4a4a55; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--border-2); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }

input[type=text], input[type=password], textarea, select {
  width: 100%;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--text-dim); margin: 0 0 6px; font-weight: 550; }

.logo-badge {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
  flex: none;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  height: 58px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.topbar .brand { display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 15.5px; color: var(--text); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-dim); font-size: 13px; }

/* ---------- dashboard ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 34px 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; }
.page-head h1 { font-size: 21px; }

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 18px;
}
.project-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  display: flex; flex-direction: column;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.thumb {
  height: 150px;
  background: #101012;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.thumb iframe {
  width: 1280px; height: 800px;
  transform: scale(0.21);
  transform-origin: 0 0;
  border: 0;
  pointer-events: none;
  background: #fff;
}
.thumb .thumb-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 13px;
}
.project-card .meta { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.project-card .meta .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card .meta .sub { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.card-del { background: none; border: none; color: var(--text-faint); padding: 4px 6px; border-radius: 6px; font-size: 15px; flex: none; }
.card-del:hover { color: var(--danger); background: var(--bg-3); }

.empty-state { text-align: center; color: var(--text-faint); padding: 90px 0; }
.empty-state .big { font-size: 17px; color: var(--text-dim); margin-bottom: 8px; }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  width: 340px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px 30px;
  text-align: center;
}
.login-card .logo-badge { width: 44px; height: 44px; font-size: 21px; border-radius: 11px; margin-bottom: 14px; }
.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card .sub { color: var(--text-faint); font-size: 13px; margin-bottom: 24px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 14px; }
.login-card button { width: 100%; padding: 10px; font-size: 14px; }

.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

/* ---------- editor ---------- */
.editor-layout { display: flex; flex-direction: column; height: 100vh; }
.editor-main { flex: 1; display: flex; min-height: 0; }

.chat-pane {
  width: 390px; flex: none;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  min-height: 0;
}
.chat-history { flex: 1; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }

.msg { max-width: 100%; }
.msg .bubble {
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble { background: var(--bg-3); border: 1px solid var(--border-2); }
.msg.assistant .bubble { background: rgba(217,165,63,.08); border: 1px solid rgba(217,165,63,.25); }
.msg.error .bubble { background: rgba(229,83,75,.08); border: 1px solid rgba(229,83,75,.35); color: #f0a29d; }
.msg .who { font-size: 11px; color: var(--text-faint); margin-bottom: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.msg .imgs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.msg .imgs img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border-2); }
.msg .ver-link { display: inline-block; margin-top: 6px; font-size: 12px; cursor: pointer; color: var(--accent); }

.composer { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; flex: none; }
.composer textarea { resize: none; height: 76px; font-size: 13.5px; }
.composer-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.composer-row select { width: auto; flex: 1; min-width: 0; font-size: 12.5px; padding: 7px 10px; }
.composer-row .btn-primary { flex: none; }

.attach-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: 7px; padding: 3px 8px 3px 4px; font-size: 12px; color: var(--text-dim);
}
.chip img { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; }
.chip button { background: none; border: none; color: var(--text-faint); padding: 0 2px; font-size: 14px; }
.chip button:hover { color: var(--danger); }

.working {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-dim); font-size: 13px; padding: 4px 2px;
}
.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.preview-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.preview-toolbar {
  height: 46px; flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.seg { display: flex; background: var(--bg-3); border: 1px solid var(--border-2); border-radius: 8px; overflow: hidden; }
.seg button { border-radius: 0; background: transparent; color: var(--text-dim); padding: 6px 13px; font-size: 12.5px; }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.preview-toolbar select { width: auto; font-size: 12.5px; padding: 6px 9px; }

.preview-body { flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: center; overflow: auto; background: #09090b; padding: 0; }
.preview-frame-wrap { flex: 1; align-self: stretch; }
.preview-frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.preview-frame-wrap.fixed {
  flex: none; align-self: center; margin: 14px;
  border: 1px solid var(--border-2); border-radius: 8px; overflow: hidden;
  box-shadow: 0 10px 34px rgba(0,0,0,.55);
}
.res-info { color: var(--text-faint); font-size: 12px; white-space: nowrap; }

.code-view { flex: 1; margin: 0; overflow: auto; padding: 18px; font: 12.5px/1.55 'Cascadia Code', Consolas, monospace; color: #cdd3de; background: #0b0b0d; white-space: pre-wrap; word-break: break-all; display: none; }

.banner {
  background: rgba(217,165,63,.1); border-bottom: 1px solid rgba(217,165,63,.3);
  color: var(--accent); font-size: 12.5px; padding: 6px 14px; display: flex; gap: 10px; align-items: center;
}
.banner button { padding: 3px 10px; font-size: 12px; }

/* ---------- admin ---------- */
.admin-table { width: 100%; border-collapse: collapse; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.admin-table th { color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.admin-table tr:last-child td { border-bottom: none; }
.tag { display: inline-block; background: rgba(217,165,63,.12); color: var(--accent); font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }

.add-user-form { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 22px; flex-wrap: wrap; }
.add-user-form > div { flex: 1; min-width: 160px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-2); border: 1px solid var(--border-2);
  border-radius: 12px; padding: 24px; width: 380px;
}
.modal h2 { font-size: 16px; margin-bottom: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c2c33; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a44; }
::-webkit-scrollbar-track { background: transparent; }
