:root {
  --primary: #01186c;
  --primary-soft: #182961;
  --gold: #daa441;
  --white: #ffffff;
  --bg: #f7f8fc;
  --bg-soft: #eef0f7;
  --text: #1a1f3a;
  --text-soft: #5a6280;
  --border: #e4e7f1;
  --error: #c43030;
  --error-bg: #fdecec;
}

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

html, body { height: 100%; }

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'Cormorant', Georgia, 'Times New Roman', serif;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* === LOGIN === */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-soft) 100%);
  padding: 24px;
}

.login-card {
  background: var(--white);
  padding: 48px 40px;
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(1, 24, 108, 0.25);
  width: 100%;
  max-width: 380px;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 260px;
  height: auto;
  margin: 0 auto 8px;
}

.brand-subtitle {
  text-align: center;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  font-size: 12px;
  margin-bottom: 32px;
}

#login-form { display: flex; flex-direction: column; gap: 12px; }

input, textarea, button {
  font-family: inherit;
  font-size: 15px;
}

input[type="password"] {
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}

input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--white);
}

button {
  padding: 14px 16px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: var(--white);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

button:hover { background: var(--primary-soft); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.error-message {
  color: var(--error);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  margin-top: 4px;
}

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

.header-title { display: flex; align-items: center; gap: 12px; }
.header-logo {
  height: 40px;
  width: auto;
  display: block;
}

.header-sub {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-size: 11px;
}

.ghost-btn {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
}

.ghost-btn:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--text-soft);
}

.app-main {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 73px);
}

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-title {
  font-size: 11px;
  font-family: 'Manrope', sans-serif;
  color: var(--text-soft);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.8px;
  margin-bottom: 16px;
}

.brain-list { display: flex; flex-direction: column; gap: 8px; }

.brain-btn {
  text-align: left;
  background: var(--white);
  color: var(--text);
  border: 1.5px solid var(--border);
  padding: 14px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s;
}

.brain-btn:hover {
  border-color: var(--primary);
  background: var(--bg-soft);
}

.brain-btn.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.brain-btn .brain-desc {
  display: block;
  font-weight: 400;
  font-size: 12px;
  margin-top: 4px;
  color: var(--text-soft);
  line-height: 1.4;
}

.brain-btn.active .brain-desc { color: rgba(255, 255, 255, 0.78); }

.sidebar-note {
  margin-top: auto;
  padding-top: 24px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.5;
}

.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
}

.welcome h2 { font-size: 32px; margin-bottom: 12px; }
.welcome p { color: var(--text-soft); max-width: 500px; line-height: 1.6; }

.conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 32px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}

.current-brain {
  font-weight: 600;
  color: var(--primary);
  font-size: 14px;
}

.current-brain::before {
  content: '●';
  color: var(--gold);
  margin-right: 8px;
}

.doc-preview {
  max-width: 95% !important;
  padding: 0 !important;
  border: 1.5px solid var(--gold) !important;
  background: var(--white);
  overflow: hidden;
}

.doc-iframe {
  width: 100%;
  height: 600px;
  border: none;
  display: block;
  background: white;
}

.doc-actions {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
}

.doc-actions button {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--primary);
}

.doc-actions button.secondary {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.doc-actions button.secondary:hover {
  background: var(--primary);
  color: var(--white);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  max-width: 78%;
  padding: 14px 18px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
  font-size: 14.5px;
}

.msg.user {
  background: var(--primary);
  color: var(--white);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  background: var(--white);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg.system {
  background: transparent;
  color: var(--text-soft);
  font-size: 12.5px;
  font-style: italic;
  align-self: center;
  max-width: 100%;
  padding: 4px;
  text-align: center;
}

.msg.error {
  background: var(--error-bg);
  border: 1px solid var(--error);
  color: var(--error);
  align-self: flex-start;
}

.chat-form {
  padding: 16px 32px 24px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  min-height: 60px;
  max-height: 240px;
  font-size: 14px;
  line-height: 1.5;
}

#message-input:focus {
  outline: none;
  border-color: var(--primary);
}

#send-btn {
  padding: 14px 28px;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .app-main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .messages { padding: 20px; }
  .chat-form { padding: 12px 20px 20px; }
}
