:root {
  --bg: #f6f7fb;
  --card: #fff;
  --muted: #6b7280;
  --accent: #0f172a;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --glass: rgba(255,255,255,0.85);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 100%);
  color: var(--accent);
}

/* Layout */
.app {
  display: flex;
  height: 100vh;
  gap: 20px;
  padding: 24px;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.brand-info h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.brand-info p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

/* Navigation */
.nav {
  margin-bottom: 24px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.nav button:hover {
  background: #f8fafc;
}

.nav button.active {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

.nav button .icon {
  font-size: 18px;
}

/* Commune Selector */
.commune-selector {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid #f1f5f9;
}

.commune-selector label {
  font-size: 13px;
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.commune-selector select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 14px;
  color: var(--accent);
  cursor: pointer;
  transition: border-color 0.2s;
}

.commune-selector select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Stats */
.stats {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  padding: 14px;
  border-radius: 10px;
  margin-top: 16px;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.stats-row:last-child {
  margin-bottom: 0;
}

.stats-label {
  color: var(--muted);
}

.stats-value {
  font-weight: 700;
  color: var(--primary);
}

/* Main Content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}

/* Header */
.header {
  background: var(--card);
  border-radius: 16px;
  padding: 20px 24px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left h2 {
  font-size: 22px;
  color: var(--accent);
}

.header-left p {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  padding: 8px 14px;
  border-radius: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

/* Chat Container */
.chat-container {
  flex: 1;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scrollbar */
.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.chat-log::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
}

.empty-state .icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
  color: var(--muted);
  max-width: 500px;
  margin: 0 auto 24px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 700px;
  margin: 0 auto;
}

.suggestion-chip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
}

/* Messages */
.message {
  display: flex;
  gap: 12px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
}

.message-content {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}

.message.user .message-content {
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.bot .message-content {
  background: #f8fafc;
  color: var(--accent);
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.message.bot .message-content.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--error);
}

/* Typing Indicator */
.typing {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: typing 1.4s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-8px);
  }
}

/* Structured Response */
.structured-response {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.response-section {
  padding: 12px;
  background: #fff;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
}

.section-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 14px;
}

.section-content {
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
}

.tag {
  background: #eff6ff;
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-family: 'Courier New', monospace;
}

/* Chat Input Area */
.chat-input-area {
  padding: 20px 24px;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-container {
  flex: 1;
  background: #fff;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  transition: border-color 0.2s;
}

.input-container:focus-within {
  border-color: var(--primary);
}

.chat-input {
  width: 100%;
  border: none;
  padding: 14px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  background: transparent;
}

.chat-input:focus {
  outline: none;
}

.send-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 14px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.4);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.input-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

kbd {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: monospace;
}

/* Responsive */
@media (max-width: 1024px) {
  .app {
    flex-direction: column;
    padding: 12px;
  }
  
  .sidebar {
    width: 100%;
    padding: 16px;
  }
  
  .message-content {
    max-width: 85%;
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
  
  .suggestions {
    flex-direction: column;
  }
  
  .suggestion-chip {
    width: 100%;
  }
}
