:root {
  --yellow: #F5C400;
  --yellow-dark: #E0B000;
  --yellow-soft: #FFF8E0;
  --black: #1A1A1A;
  --gray: #4A4A4A;
  --gray-light: #F5F5F5;
  --white: #FFFFFF;
  --border: #E8E8E8;
  --danger: #C62828;
  --radius: 12px;
  --panel-width: 280px;
  --topbar-h: 52px;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-light);
  color: var(--black);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.hidden { display: none !important; }

/* Auth */
#auth-overlay {
  position: fixed; inset: 0; background: var(--black);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.auth-box {
  background: var(--white); padding: 2.5rem 2rem; border-radius: var(--radius);
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.auth-logo {
  display: inline-block; background: var(--yellow); color: var(--black);
  font-weight: 800; font-size: 0.85rem; letter-spacing: 0.04em;
  padding: 0.35rem 0.9rem; border-radius: 4px; margin-bottom: 1.25rem;
}
.auth-box h2 { font-size: 1.3rem; margin-bottom: 0.4rem; }
.auth-box p { color: var(--gray); font-size: 0.95rem; margin-bottom: 1.25rem; }
#auth-password {
  width: 100%; padding: 0.75rem 1rem; border: 2px solid var(--border);
  border-radius: 8px; font-size: 1rem; text-align: center; margin-bottom: 1rem;
}
#auth-password:focus { outline: none; border-color: var(--yellow); }
.auth-error { color: var(--danger); font-size: 0.9rem; margin-top: 0.75rem; }
.btn {
  width: 100%; padding: 0.8rem; background: var(--yellow); color: var(--black);
  border: none; border-radius: 8px; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.btn:hover { background: var(--yellow-dark); }

/* App shell */
#app-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100vh;
}

.topbar {
  flex-shrink: 0;
  background: var(--black); color: var(--white); height: var(--topbar-h);
  display: flex; align-items: center; border-bottom: 3px solid var(--yellow);
}
.topbar-inner {
  width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 1rem;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark { width: 14px; height: 14px; background: var(--yellow); border-radius: 3px; }
.brand-text { font-weight: 700; font-size: 0.95rem; }
.topbar-status { font-size: 0.8rem; color: rgba(255,255,255,0.55); }

.main-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr var(--panel-width);
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  background: var(--white);
}

/* Chat column */
.chat-layout {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--border);
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem 0.9rem;
  background: var(--white);
}
.composer-inner { display: flex; gap: 0.5rem; align-items: flex-end; }
#user-input {
  flex: 1; border: 2px solid var(--border); border-radius: 10px;
  padding: 0.65rem 0.85rem; font-size: 0.92rem; font-family: inherit;
  resize: none; max-height: 110px; line-height: 1.4;
  min-height: 42px;
}
#user-input:focus { outline: none; border-color: var(--yellow); }
#user-input:disabled { background: var(--gray-light); cursor: not-allowed; }
.send-btn {
  width: 42px; height: 42px; border-radius: 10px; background: var(--yellow);
  border: none; color: var(--black); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--yellow-dark); }
.send-btn:disabled { background: var(--border); color: #999; cursor: not-allowed; }

/* Messages */
.msg { display: flex; gap: 0.65rem; max-width: 92%; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 800;
}
.msg.bot .msg-avatar { background: var(--yellow); color: var(--black); }
.msg.user .msg-avatar { background: var(--black); color: var(--yellow); }
.msg-bubble {
  padding: 0.7rem 0.95rem; border-radius: 12px;
  font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap;
}
.msg.bot .msg-bubble { background: var(--yellow-soft); color: var(--black); border-bottom-left-radius: 4px; }
.msg.user .msg-bubble { background: var(--black); color: var(--white); border-bottom-right-radius: 4px; }

.typing { display: flex; gap: 4px; padding: 0.2rem 0; }
.typing span {
  width: 6px; height: 6px; background: var(--gray); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.chip {
  background: var(--white); border: 1.5px solid var(--yellow); color: var(--black);
  padding: 0.3rem 0.7rem; border-radius: 20px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
}
.chip:hover { background: var(--yellow); }

.form-card {
  background: var(--white); border: 2px solid var(--yellow);
  border-radius: 10px; padding: 1rem; margin-top: 0.6rem;
}
.form-card h4 { font-size: 0.9rem; margin-bottom: 0.75rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.form-field label {
  display: block; font-size: 0.75rem; font-weight: 600; color: var(--gray); margin-bottom: 0.2rem;
}
.form-field input, .form-field select {
  width: 100%; padding: 0.45rem 0.55rem; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.88rem; background: #fff;
}
.form-field input:focus, .form-field select:focus { outline: none; border-color: var(--yellow); }
.form-actions { margin-top: 0.85rem; display: flex; gap: 0.5rem; }
.form-actions button {
  padding: 0.5rem 1rem; border-radius: 6px; font-weight: 700; font-size: 0.88rem;
  border: none; cursor: pointer;
}
.form-actions .primary { background: var(--yellow); color: var(--black); }
.form-actions .primary:hover { background: var(--yellow-dark); }

.pdf-card {
  background: var(--white); border: 2px solid var(--yellow);
  border-radius: 10px; padding: 0.9rem 1rem; margin-top: 0.5rem;
}
.pdf-card h4 { font-size: 0.9rem; margin-bottom: 0.3rem; }
.pdf-card p { font-size: 0.82rem; color: var(--gray); margin-bottom: 0.65rem; }
.pdf-card .btn-download {
  display: inline-block; background: var(--yellow); color: var(--black);
  font-weight: 700; font-size: 0.85rem; padding: 0.45rem 0.9rem;
  border-radius: 6px; border: none; cursor: pointer;
}

/* MCP Panel */
.mcp-panel {
  background: #1a1a1a; color: #e5e5e5; padding: 1rem 0.9rem;
  overflow-y: auto; font-size: 0.82rem; min-height: 0;
}
.mcp-header {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 700; font-size: 0.88rem; margin-bottom: 1rem; color: var(--yellow);
}
.mcp-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--yellow);
  box-shadow: 0 0 6px var(--yellow); animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.mcp-section { margin-bottom: 1.1rem; }
.mcp-section h4 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #888; margin-bottom: 0.4rem;
}
.mcp-list { list-style: none; }
.mcp-list li {
  position: relative; padding-left: 0.9rem; margin-bottom: 0.35rem;
  line-height: 1.35; color: #ccc;
}
.mcp-list li::before { content: "•"; position: absolute; left: 0; color: var(--yellow); }
.mcp-list.tech li { font-family: ui-monospace, monospace; font-size: 0.75rem; color: #aaa; }
.mcp-tools { list-style: none; }
.mcp-tools li { margin-bottom: 0.3rem; }
.mcp-tools code {
  background: #2a2a2a; color: var(--yellow); padding: 0.15rem 0.4rem;
  border-radius: 4px; font-size: 0.72rem;
}

@media (max-width: 800px) {
  .main-grid { grid-template-columns: 1fr; }
  .mcp-panel {
    border-top: 1px solid #333;
    max-height: 180px;
  }
  .form-grid { grid-template-columns: 1fr; }
}
