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

:root {
  --green-dark: #1a472a;
  --green-mid: #2d8a4e;
  --green-light: #e8f5e9;
  --gray-50: #f8f9fa;
  --gray-100: #f1f3f5;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-500: #868e96;
  --gray-700: #495057;
  --gray-900: #212529;
  --sidebar-width: 260px;
  --chat-width: 340px;
  --topbar-height: 52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-900);
  height: 100vh;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  height: var(--topbar-height);
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-file {
  font-size: 13px;
  opacity: 0.8;
  background: rgba(255,255,255,0.1);
  padding: 3px 10px;
  border-radius: 4px;
}
.unsaved-badge {
  font-size: 11px;
  font-weight: 600;
  background: #f59e0b;
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--green-mid); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #236b3d; }
.btn-secondary { background: rgba(255,255,255,0.15); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.25); }
.btn-ghost { background: transparent; color: rgba(255,255,255,0.7); }
.btn-ghost:hover { color: #fff; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--gray-500);
  padding: 4px;
  border-radius: 4px;
}
.btn-icon:hover { background: var(--gray-200); color: var(--gray-700); }

/* Layout */
.editor-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-200);
}
.sidebar-header h2 { font-size: 14px; font-weight: 700; color: var(--gray-700); }

.file-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.file-tree .loading {
  padding: 16px;
  color: var(--gray-500);
  font-size: 13px;
  text-align: center;
}

.tree-item {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--gray-700);
  transition: background 0.1s;
  gap: 6px;
}
.tree-item:hover { background: var(--gray-50); }
.tree-item.active { background: var(--green-light); color: var(--green-dark); font-weight: 600; }
.tree-item .icon { font-size: 14px; opacity: 0.6; }
.tree-dir { font-weight: 600; }
.unsaved-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  display: inline-block;
  margin-left: auto;
  flex-shrink: 0;
}
.tree-indent { padding-left: 28px; }

/* Sidebar History Section */
.sidebar-section {
  border-top: 1px solid var(--gray-200);
  max-height: 240px;
  display: flex;
  flex-direction: column;
}
.sidebar-section h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-700);
  padding: 10px 14px;
}

.history-panel {
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 8px;
}

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
  background: var(--gray-50);
  cursor: pointer;
}
.history-item:hover { background: var(--gray-100); }
.history-item .history-desc { color: var(--gray-700); margin-bottom: 2px; }
.history-item .history-meta { color: var(--gray-500); font-size: 11px; }
.history-item .history-actions { margin-top: 4px; }
.history-item .btn-rollback {
  font-size: 11px;
  padding: 2px 8px;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 4px;
  cursor: pointer;
}
.history-item .btn-rollback:hover { background: #fee2e2; }
.history-item.rolled-back { opacity: 0.5; }
.history-item.rolled-back .history-desc { text-decoration: line-through; }

/* Preview Area */
.preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
}
.preview-label { font-size: 13px; font-weight: 600; color: var(--gray-700); }

.preview-container {
  flex: 1;
  position: relative;
  background: #fff;
}

.preview-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  position: absolute;
  top: 0;
  left: 0;
}

.preview-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  font-size: 15px;
}

/* Confirmation Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal p { font-size: 14px; color: var(--gray-700); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn { min-width: 80px; text-align: center; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-cancel { background: var(--gray-200); color: var(--gray-700); }
.btn-cancel:hover { background: var(--gray-300); }

/* Responsive: stack panels on narrow screens */
@media (max-width: 900px) {
  .editor-layout { flex-direction: column; height: auto; overflow-y: auto; }
  .sidebar { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--gray-200); }
  .preview-area { min-height: 300px; }
  .chat-panel { width: 100%; border-left: none; border-top: 1px solid var(--gray-200); }
  .topbar-right { gap: 4px; }
  .topbar-right .btn { font-size: 11px; padding: 5px 8px; }
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; height: auto; padding: 8px; gap: 8px; }
  .topbar-left { width: 100%; justify-content: center; }
  .topbar-right { width: 100%; justify-content: center; flex-wrap: wrap; }
}
