@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #222633;
  --border: #2a2e3b;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --primary: #6c5ce7;
  --primary-hover: #7d6ff0;
  --primary-bg: rgba(108, 92, 231, 0.12);
  --success: #2ecc71;
  --success-bg: rgba(46, 204, 113, 0.12);
  --error: #e74c3c;
  --error-bg: rgba(231, 76, 60, 0.12);
  --warning: #f39c12;
  --warning-bg: rgba(243, 156, 18, 0.12);
  --font: 'DM Sans', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* ================================================================ */
/* HEADER                                                           */
/* ================================================================ */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 20px; font-weight: 700; color: var(--primary); }
.logo-sub { font-size: 13px; color: var(--text-muted); }
.header-center { display: flex; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 16px; }
.user-info { font-size: 13px; color: var(--text-muted); }

/* Tabs */
.tab-btn {
  padding: 8px 18px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--text-muted);
  font-family: var(--font); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); border-color: var(--border); }
.tab-btn.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }

/* ================================================================ */
/* BUTTONS                                                          */
/* ================================================================ */
.btn {
  padding: 8px 20px; border-radius: 8px; border: none;
  font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.btn-icon:hover { color: var(--text); }

/* ================================================================ */
/* LOGIN                                                            */
/* ================================================================ */
.login-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 80vh; gap: 24px;
}
.login-screen h1 { font-size: 32px; font-weight: 700; color: var(--primary); }
.login-screen p { color: var(--text-muted); font-size: 16px; max-width: 400px; text-align: center; line-height: 1.6; }
.btn-login { padding: 14px 40px; font-size: 16px; border-radius: 12px; }

/* ================================================================ */
/* CONTENT BROWSER                                                  */
/* ================================================================ */
.content-browser {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px;
  border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap;
}
.content-browser select {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px;
  min-width: 180px; max-width: 280px;
}
.search-wrapper { position: relative; }
.search-wrapper input {
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px;
  width: 220px;
}
.search-wrapper input::placeholder { color: #3a3e4e; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  max-height: 300px; overflow-y: auto; display: none; margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.search-result-item {
  padding: 8px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-hover); }

/* ================================================================ */
/* ASSISTANT TAB — SPLIT VIEW                                       */
/* ================================================================ */
#tab-assistant {
  display: flex; flex: 1; overflow: hidden;
}

/* Chat Panel */
.chat-panel {
  flex: 55; display: flex; flex-direction: column; border-right: 1px solid var(--border);
  min-width: 0;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px 20px;
}
.chat-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); text-align: center;
}
.chat-msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; line-height: 1.6; max-width: 90%; }
.chat-msg-user { background: var(--primary-bg); color: var(--text); margin-left: auto; border-bottom-right-radius: 2px; }
.chat-msg-assistant { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 2px; }
.chat-msg-assistant pre.chat-code {
  background: var(--bg); padding: 10px; border-radius: 6px; margin: 8px 0;
  overflow-x: auto; font-family: var(--mono); font-size: 12px; line-height: 1.5;
}
.chat-loading { color: var(--text-muted); display: flex; align-items: center; gap: 8px; }

/* Chat Input */
.chat-input-area {
  border-top: 1px solid var(--border); padding: 12px 16px;
}
.chat-file-preview {
  display: none; align-items: center; gap: 8px; padding: 6px 10px; margin-bottom: 8px;
  background: var(--primary-bg); border-radius: 6px; font-size: 13px;
  justify-content: space-between;
}
.chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px;
  resize: none; outline: none; min-height: 44px; max-height: 120px;
}
.chat-input-row textarea::placeholder { color: #3a3e4e; }
.chat-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.chat-tokens { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }

/* Editor Panel */
.editor-panel-wrap {
  flex: 45; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.editor-panel-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 16px; gap: 12px; }

.editor-meta {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
}
.meta-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.meta-row:last-child { margin-bottom: 0; }
.meta-label { font-size: 13px; color: var(--text-muted); }

.editor-section { display: flex; flex-direction: column; }
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.panel-title { font-size: 14px; font-weight: 600; color: var(--text); }

.editor-textarea {
  width: 100%; min-height: 300px; padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-family: var(--mono); font-size: 13px; line-height: 1.6; resize: vertical; outline: none;
}
.editor-textarea:focus { border-color: var(--primary); }

.editor-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding-top: 8px; border-top: 1px solid var(--border);
}

.editor-select, .editor-select-sm {
  padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px;
}
.editor-select-sm { padding: 4px 8px; font-size: 12px; }

.editor-input {
  width: 100%; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px;
  outline: none; margin-bottom: 10px;
}
.editor-input:focus { border-color: var(--primary); }

.entity-form { padding: 4px 0; }
.entity-form label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; display: block; }

/* ================================================================ */
/* IMPORT TAB                                                       */
/* ================================================================ */
#tab-import { display: none; padding: 24px; max-width: 1200px; margin: 0 auto; }

.imp-editor-area {
  display: grid; grid-template-columns: 1fr 380px; gap: 24px; min-height: 400px;
}
.imp-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column;
}
.imp-panel-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.imp-panel textarea {
  flex: 1; width: 100%; padding: 20px; background: transparent; border: none;
  color: var(--text); font-family: var(--mono); font-size: 13px; line-height: 1.6;
  resize: none; outline: none;
}
.imp-panel textarea::placeholder { color: #3a3e4e; }
.preview-content { padding: 20px; overflow-y: auto; flex: 1; }
.preview-empty { color: var(--text-muted); font-size: 14px; text-align: center; padding-top: 40px; }

.imp-action-bar { display: flex; gap: 8px; margin-bottom: 16px; }

.imp-bottom {
  display: flex; align-items: center; justify-content: space-between; margin-top: 16px;
}
.imp-info { font-size: 13px; color: var(--text-muted); }

/* ================================================================ */
/* STATUS BAR                                                       */
/* ================================================================ */
.status-bar {
  margin: 12px 24px 0; padding: 14px 20px; border-radius: 10px;
  font-size: 14px; line-height: 1.5; display: none;
}
.status-bar.visible { display: block; }
.status-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(46,204,113,0.2); }
.status-error { background: var(--error-bg); color: var(--error); border: 1px solid rgba(231,76,60,0.2); }
.status-info { background: var(--primary-bg); color: var(--primary); border: 1px solid rgba(108,92,231,0.2); }
.validation-list { margin-top: 8px; padding-left: 20px; font-size: 13px; font-family: var(--mono); }
.validation-list li { margin-bottom: 4px; }

/* ================================================================ */
/* SPINNER                                                          */
/* ================================================================ */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: white;
  border-radius: 50%; animation: spin 0.6s linear infinite;
  margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================ */
/* FILE UPLOAD                                                      */
/* ================================================================ */
.file-upload { position: relative; overflow: hidden; }
.file-upload input[type="file"] {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}

/* ================================================================ */
/* LAYOUT                                                           */
/* ================================================================ */
.app-body { display: flex; flex-direction: column; height: calc(100vh - 57px); }

/* ================================================================ */
/* RESPONSIVE                                                       */
/* ================================================================ */
@media (max-width: 1200px) {
  #tab-assistant { flex-direction: column; }
  .chat-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  .editor-panel-wrap { max-height: 50vh; }
  .content-browser { gap: 8px; }
  .content-browser select { min-width: 140px; }
}
@media (max-width: 900px) {
  .imp-editor-area { grid-template-columns: 1fr; }
  .header { padding: 10px 16px; }
  .content-browser { padding: 10px 16px; }
}