:root {
  --bg-primary: #0D1B2A;
  --bg-secondary: #1B2D45;
  --bg-card: #1E3251;
  --bg-input: #162740;
  --gold: #C8A96E;
  --gold-light: #D4BA85;
  --gold-dark: #A8894E;
  --text-primary: #F0EDE6;
  --text-secondary: #9BAAB8;
  --text-muted: #6B7D8D;
  --border: #2A4060;
  --success: #4CAF50;
  --danger: #E74C3C;
  --warning: #F39C12;
  --info: #3498DB;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.3s ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 18px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.sidebar-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  color: var(--text-secondary);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active { background: var(--bg-card); color: var(--gold); }

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.agent-list {
  list-style: none;
  padding: 0;
}

.agent-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
  color: var(--text-secondary);
}

.agent-list-item:hover { background: var(--bg-card); color: var(--text-primary); }
.agent-list-item.active { background: var(--bg-card); color: var(--gold); }

.agent-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.agent-dot.inactive { background: var(--text-muted); }

.main {
  flex: 1;
  margin-left: 260px;
  padding: 32px;
  max-width: calc(100% - 260px);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
}

.stat-card:hover { border-color: var(--gold-dark); }

.stat-card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
}

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 600;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  font-family: inherit;
}

.btn-primary {
  background: var(--gold);
  color: var(--bg-primary);
}

.btn-primary:hover { background: var(--gold-light); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover { border-color: var(--gold-dark); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger); color: white; }

.btn-sm { padding: 6px 14px; font-size: 13px; }

.btn-icon {
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover { border-color: var(--gold); color: var(--gold); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--gold);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tr:hover { background: rgba(200, 169, 110, 0.05); }

/* Badge */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: rgba(76,175,80,0.15); color: var(--success); }
.badge-warning { background: rgba(243,156,18,0.15); color: var(--warning); }
.badge-danger { background: rgba(231,76,60,0.15); color: var(--danger); }
.badge-info { background: rgba(52,152,219,0.15); color: var(--info); }

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 500px;
  background: var(--bg-input);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--gold);
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chat-input-row input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--gold);
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--gold);
  background: rgba(200, 169, 110, 0.05);
}

.upload-zone svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.upload-zone p {
  color: var(--text-secondary);
  font-size: 14px;
}

.upload-zone .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 18px; }

.modal-body { padding: 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 24px;
}

.tab {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
}

.tab:hover { color: var(--text-primary); }
.tab.active { background: var(--bg-card); color: var(--gold); }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* Loader */
.loader {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-info { background: var(--info); color: white; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; max-width: 100%; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Settings Sub-Navigation */
.settings-nav {
  display: flex;
  gap: 2px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
}

.settings-nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  white-space: nowrap;
}

.settings-nav-item:hover {
  color: var(--text-primary);
  background: rgba(200, 169, 110, 0.06);
}

.settings-nav-item.active {
  background: var(--bg-card);
  color: var(--gold);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.settings-nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.settings-section {
  animation: fadeIn 0.25s ease;
}

/* ── Analytics ── */
.analytics-kpis {
  grid-template-columns: repeat(6, 1fr);
}
@media (max-width: 1200px) {
  .analytics-kpis { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .analytics-kpis { grid-template-columns: repeat(2, 1fr); }
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .analytics-grid { grid-template-columns: 1fr; }
}

.analytics-side {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.trends-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 180px;
  padding: 12px 0 24px;
  position: relative;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.chart-bar {
  width: 100%;
  max-width: 28px;
  background: var(--gold);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
  cursor: default;
  position: relative;
}
.chart-bar:hover {
  opacity: 0.8;
}

.chart-bar-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  border: 1px solid var(--border);
  z-index: 10;
}
.chart-bar:hover .chart-bar-tooltip {
  display: block;
}

.chart-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  position: absolute;
  bottom: -20px;
}

.sentiment-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.sentiment-label {
  width: 70px;
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: capitalize;
}

.sentiment-bar-track {
  flex: 1;
  height: 22px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  overflow: hidden;
}

.sentiment-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}
.sentiment-bar-fill.positive { background: var(--success); }
.sentiment-bar-fill.neutral { background: var(--info); }
.sentiment-bar-fill.negative { background: var(--danger); }

.sentiment-count {
  width: 30px;
  text-align: right;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

.topic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.topic-row:last-child { border-bottom: none; }

.topic-name {
  font-size: 13px;
  color: var(--text-secondary);
}

.topic-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(212, 175, 55, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

.perf-bar-track {
  width: 80px;
  height: 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
}
.perf-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.badge-positive { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-neutral { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-negative { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Learning tab */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--warning);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}

.learning-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg-input);
}

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

.learning-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.learning-question {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.learning-answer {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  white-space: pre-wrap;
}

.learning-gap-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  margin-bottom: 10px;
}

.learning-gap-input:focus {
  outline: none;
  border-color: var(--gold);
}

.learning-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.confidence-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.confidence-high { background: rgba(76, 175, 80, 0.15); color: var(--success); }
.confidence-mid  { background: rgba(243, 156, 18, 0.15); color: var(--warning); }
.confidence-low  { background: rgba(231, 76, 60, 0.15); color: var(--danger); }

.status-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.status-auto_added { background: rgba(76, 175, 80, 0.15); color: var(--success); }
.status-approved   { background: rgba(52, 152, 219, 0.15); color: var(--info); }
.status-rejected   { background: rgba(231, 76, 60, 0.15); color: var(--danger); }
.status-gap        { background: rgba(243, 156, 18, 0.15); color: var(--warning); }

/* Misc */
.hidden { display: none !important; }
.text-gold { color: var(--gold); }
.text-muted { color: var(--text-muted); }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
