:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1a1a25;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #888899;
  --accent: #6c5ce7;
  --accent-hover: #7c6ef7;
  --success: #00b894;
  --danger: #e74c3c;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Auth */
.auth-box {
  max-width: 400px;
  margin: 15vh auto;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.auth-box h1 { font-size: 2.5rem; margin-bottom: 8px; }
.accent { color: var(--accent); }
.subtitle { color: var(--text-dim); margin-bottom: 30px; }

#auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
}

.tab.active {
  background: var(--accent);
  color: white;
}

#auth-form input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

#auth-form button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}

#auth-form button[type="submit"]:hover { background: var(--accent-hover); }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-left { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; }
.header-left h1 { font-size: 1.5rem; margin: 0; white-space: nowrap; }
.builder-nav { display: flex; align-items: center; gap: 10px; }
.nav-separator { color: var(--border); font-size: 1.2rem; }
.builder-nav-name { font-weight: 600; font-size: 14px; color: var(--text); }
.header-right { display: flex; align-items: center; gap: 16px; }
#user-email { color: var(--text-dim); font-size: 14px; }

/* Buttons */
.btn-primary {
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 10px 20px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.btn-secondary:hover { border-color: var(--accent); }

#logout-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

/* Projects */
main { padding: 32px; max-width: 1400px; margin: 0 auto; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

#projects-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.project-card:hover { border-color: var(--accent); }
.project-card h4 { font-size: 18px; margin-bottom: 8px; }
.project-card .slug { color: var(--accent); font-size: 13px; margin-bottom: 12px; }
.project-card .meta { display: flex; gap: 12px; color: var(--text-dim); font-size: 12px; }
.project-card .status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; }
.project-card .status.active { background: rgba(0,184,148,0.15); color: var(--success); }
.project-card .status.creating { background: rgba(108,92,231,0.15); color: var(--accent); }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-weight: 500;
}

.btn-sm.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
}

.btn-sm.btn-primary:hover { background: var(--accent-hover); }

.btn-sm.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-sm.btn-secondary:hover { border-color: var(--accent); color: var(--text); }

.btn-sm.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(231,76,60,0.3);
}
.btn-sm.btn-danger:hover { border-color: var(--danger); background: rgba(231,76,60,0.1); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h3 { margin-bottom: 20px; }

.modal-content label {
  display: block;
  color: var(--text-dim);
  font-size: 13px;
  margin: 12px 0 6px;
}

.modal-content input,
.modal-content select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.checkbox-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s;
  margin: 0;
}

.checkbox-group label:hover {
  border-color: var(--accent);
}

.checkbox-group input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.checkbox-group input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-group input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Builder */

.builder-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.builder-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
  align-items: stretch;
}

.builder-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

#builder-messages {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 16px;
  flex: 1;
}

.msg { padding: 10px 14px; margin-bottom: 8px; border-radius: 8px; font-size: 14px; }
.msg.user { background: var(--accent); color: white; margin-left: 20%; }
.msg.system { background: var(--surface2); color: var(--text-dim); margin-right: 20%; }
.msg.error { background: rgba(231,76,60,0.15); color: var(--danger); }

.build-log {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  line-height: 1.5;
  color: var(--text-dim);
}

#builder-prompt {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  font-family: inherit;
}

.builder-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  justify-content: flex-end;
}

.builder-actions select {
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}

.builder-preview { margin-top: 20px; }
.preview-controls { display: flex; gap: 12px; margin-bottom: 12px; }

#preview-frame {
  width: 100%;
  height: 500px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
}

/* File Manager */
.builder-files {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.files-header h4 { font-size: 15px; }
.files-actions { display: flex; gap: 8px; }
.upload-label { cursor: pointer; }

.files-gallery-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.files-gallery-toggle span {
  font-size: 12px;
  color: var(--text-dim);
}

.files-collapse-btn.open { }
.files-collapse-btn.open::after { content: ''; }

.files-body { margin-top: 12px; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 12px;
  transition: border-color 0.2s, background 0.2s;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108,92,231,0.08);
}

.files-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding: 4px;
}

.file-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.file-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.file-preview {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--surface2);
}

.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview audio {
  width: 90%;
  height: 28px;
  margin-top: 4px;
}

.file-preview-icon {
  font-size: 28px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
}

.file-info {
  padding: 8px;
}

.file-info .file-name {
  display: block;
  font-size: 11px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-info .file-size {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

.file-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.file-rename {
  position: absolute;
  top: 4px;
  right: 30px;
  background: rgba(0,0,0,0.6);
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.file-card:hover .file-delete,
.file-card:hover .file-rename { opacity: 1; }
.file-delete:hover { background: rgba(231,76,60,0.4); }
.file-rename:hover { background: rgba(108,92,231,0.4); }

/* Version History */
.builder-versions {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.versions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.versions-header h4 { font-size: 15px; }

.versions-list {
  max-height: 300px;
  overflow-y: auto;
}

.version-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.15s;
}

.version-item:last-child { border-bottom: none; }
.version-item:hover { background: var(--surface2); }

.version-hash {
  font-family: monospace;
  color: var(--accent);
  font-size: 12px;
  min-width: 60px;
}

.version-msg {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.version-date {
  color: var(--text-dim);
  font-size: 11px;
  min-width: 100px;
  text-align: right;
}

.version-actions {
  display: flex;
  gap: 6px;
}

.version-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent);
  color: white;
  margin-left: 4px;
}

/* Diff Modal */
.modal-wide .modal-content,
.modal-wide {
  max-width: 900px;
  width: 95%;
}

.diff-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.diff-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.diff-file {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  font-family: monospace;
}

.diff-file.added { background: rgba(0,184,148,0.15); color: var(--success); }
.diff-file.modified { background: rgba(108,92,231,0.15); color: var(--accent); }
.diff-file.deleted { background: rgba(231,76,60,0.15); color: var(--danger); }

.diff-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 12px;
  font-family: monospace;
  max-height: 500px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
  color: var(--text-dim);
}

/* Responsive */
@media (max-width: 900px) {
  .builder-columns { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  main { padding: 16px; }
  #projects-list { grid-template-columns: 1fr; }
  .modal-content { width: 95%; padding: 20px; }
  .builder-toolbar { flex-wrap: wrap; }
}
