/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: #f5f7fa;
  color: #1a1a2e;
  display: flex;
  min-height: 100vh;
}

/* === Sidebar === */
#sidebar {
  width: 240px;
  background: #1a1a2e;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}
.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: #51b782;
}
.logo-sub {
  display: block;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}
.nav-links {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,0.05);
}
.nav-link.active {
  color: #fff;
  background: rgba(81,183,130,0.1);
  border-left-color: #51b782;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #666;
}
.status-dot.online { background: #51b782; }
.status-dot.offline { background: #e74c3c; }

/* === Main Content === */
#content {
  margin-left: 240px;
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

/* === Page Header === */
.page-header {
  margin-bottom: 28px;
}
.page-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1a1a2e;
}
.page-header p {
  color: #666;
  margin-top: 4px;
  font-size: 0.9rem;
}

/* === Cards === */
.card {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  padding: 24px;
  margin-bottom: 16px;
  transition: box-shadow 0.15s;
}
.card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
}

/* === Grid === */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* === Stat Cards (Dashboard) === */
.stat-card {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.2rem;
}
.stat-icon.green { background: #51b782; }
.stat-icon.blue { background: #3498db; }
.stat-icon.orange { background: #e67e22; }
.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}
.stat-label {
  font-size: 0.8rem;
  color: #666;
  margin-top: 2px;
}

/* === Project Card === */
.project-card {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  padding: 20px 24px;
  cursor: pointer;
  transition: all 0.15s;
}
.project-card:hover {
  border-color: #51b782;
  box-shadow: 0 2px 12px rgba(81,183,130,0.12);
}
.project-name {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.project-domain {
  color: #51b782;
  font-size: 0.85rem;
  font-weight: 500;
}
.project-meta {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 0.8rem;
  color: #999;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-primary {
  background: #51b782;
  color: #fff;
}
.btn-primary:hover { background: #45a06f; }
.btn-secondary {
  background: #e8ecf1;
  color: #1a1a2e;
}
.btn-secondary:hover { background: #dde2e9; }
.btn-danger {
  background: #fee;
  color: #e74c3c;
}
.btn-danger:hover { background: #fdd; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* === Sitemap / Tree === */
.sitemap {
  list-style: none;
}
.sitemap-page {
  margin-bottom: 8px;
}
.sitemap-page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.sitemap-page-header:hover {
  border-color: #51b782;
}
.sitemap-page-header .page-title {
  font-weight: 600;
  flex: 1;
}
.sitemap-page-header .page-slug {
  color: #999;
  font-size: 0.8rem;
}
.sitemap-page-header .page-count {
  font-size: 0.75rem;
  background: #e8ecf1;
  padding: 2px 8px;
  border-radius: 10px;
  color: #666;
}
.sitemap-sections {
  list-style: none;
  margin-left: 24px;
  padding: 8px 0;
  border-left: 2px solid #e8ecf1;
}
.sitemap-sections.hidden { display: none; }
.sitemap-section {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  margin-left: 12px;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.sitemap-section:hover {
  background: rgba(81,183,130,0.06);
}
.sitemap-section .section-num {
  color: #999;
  font-size: 0.75rem;
  width: 24px;
}
.sitemap-section .section-name {
  flex: 1;
  font-weight: 500;
}
.sitemap-section .section-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eaf6ef;
  color: #51b782;
}
.sitemap-section .section-badge.global {
  background: #eef0f8;
  color: #3498db;
}

/* === Editor === */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  height: calc(100vh - 140px);
  min-height: 500px;
}
.editor-preview {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.editor-preview iframe {
  flex: 1;
  border: none;
  width: 100%;
  min-height: 400px;
}
.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.editor-section-info {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  padding: 16px;
}
.editor-section-label {
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.editor-section-name {
  font-size: 1.1rem;
  font-weight: 600;
}
.editor-section-file {
  font-size: 0.8rem;
  color: #51b782;
  margin-top: 2px;
}
.prompt-box {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.prompt-box textarea {
  flex: 1;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  min-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}
.prompt-box textarea:focus {
  border-color: #51b782;
}
.prompt-box .prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* === Diff / Split View === */
.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  height: calc(100vh - 200px);
}
.split-pane {
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e8ecf1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.split-pane-header {
  padding: 10px 16px;
  background: #f8f9fb;
  border-bottom: 1px solid #e8ecf1;
  font-size: 0.85rem;
  font-weight: 600;
}
.split-pane-header.original { color: #e67e22; }
.split-pane-header.modified { color: #51b782; }
.split-pane iframe {
  flex: 1;
  border: none;
  width: 100%;
}
.split-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

/* === Code View === */
.code-view {
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.82rem;
  padding: 16px;
  border-radius: 8px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  line-height: 1.6;
}

/* === Backup List === */
.backup-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: #fff;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  margin-bottom: 8px;
}
.backup-item .backup-name {
  flex: 1;
  font-weight: 500;
  font-size: 0.9rem;
}
.backup-item .backup-date {
  color: #999;
  font-size: 0.8rem;
}
.backup-item .backup-size {
  color: #999;
  font-size: 0.8rem;
}

/* === Loading / Spinner === */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e8ecf1;
  border-top-color: #51b782;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.loading-text {
  font-size: 0.9rem;
  color: #666;
}

/* === Toast notifications === */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #fff;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast.success { background: #51b782; }
.toast.error { background: #e74c3c; }
.toast.info { background: #3498db; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}
.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.3;
}
.empty-state h3 {
  font-size: 1.1rem;
  color: #666;
  margin-bottom: 8px;
}

/* === Editor Tabs === */
.editor-tabs {
  display: flex;
  background: #e8ecf1;
  border-radius: 6px;
  padding: 2px;
}
.editor-tab {
  padding: 6px 16px;
  border: none;
  background: none;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  color: #666;
  transition: all 0.15s;
}
.editor-tab.active {
  background: #fff;
  color: #1a1a2e;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.editor-main {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-main > div {
  min-height: 0;
  flex: 1;
}

/* === Code Editor (textarea) === */
.code-editor {
  flex: 1;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 16px;
  border: none;
  border-radius: 0 0 10px 10px;
  resize: none;
  outline: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.code-editor:focus {
  box-shadow: inset 0 0 0 2px rgba(81,183,130,0.3);
}

/* === Version History === */
.version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  margin-bottom: 8px;
  transition: border-color 0.15s;
}
.version-item:hover {
  border-color: #51b782;
}
.version-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.version-num {
  font-weight: 700;
  font-size: 0.9rem;
  color: #51b782;
  min-width: 30px;
}
.version-date {
  font-size: 0.85rem;
  color: #333;
  font-weight: 500;
}
.version-size {
  font-size: 0.8rem;
  color: #999;
}
.version-actions {
  display: flex;
  gap: 6px;
}

/* === Section Picker Grid === */
.section-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.section-picker-item {
  background: #fff;
  border: 1px solid #e8ecf1;
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-picker-item:hover {
  border-color: #51b782;
  box-shadow: 0 2px 8px rgba(81,183,130,0.1);
}
.section-picker-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.section-picker-file {
  color: #999;
  font-size: 0.8rem;
  flex: 1;
}

/* === Responsive === */
@media (max-width: 980px) {
  #sidebar { width: 60px; }
  .sidebar-header, .nav-link span, .logo-sub, .sidebar-footer span { display: none; }
  .nav-link { justify-content: center; padding: 14px; }
  #content { margin-left: 60px; }
  .editor-layout { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .split-view { grid-template-columns: 1fr; }
}
