@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Design tokens ─── */
:root {
  --primary: #2563EB;
  --primary-dark: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.25);
  --accent: #06B6D4;
  --danger: #EF4444;
  --success: #10B981;
  --warning: #F59E0B;

  /* Dark mode defaults */
  --bg: #0F172A;
  --surface: #1E293B;
  --surface-2: #334155;
  --surface-3: #475569;
  --border: #334155;
  --text: #F8FAFC;
  --text-muted: #94A3B8;
  --text-placeholder: #64748b;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.25);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
  --transition: all 0.15s ease;

  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
}

html[data-theme="light"] {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --surface-3: #E2E8F0;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #64748b;
  --text-placeholder: #94a3b8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

html { font-size: 14px; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── App layout ─── */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.25s ease;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  z-index: 999;
}

body.sidebar-open .sidebar-overlay {
  opacity: 1;
  visibility: visible;
}

body.sidebar-open .sidebar {
  transform: translateX(0);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 22px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

html[data-theme="light"] .nav-item:hover {
  background: var(--surface-2);
}

.nav-item.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  margin-left: -3px;
}

.nav-item.nav-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-item.nav-disabled:hover {
  background: transparent;
  color: var(--text-muted);
}

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

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.theme-toggle, .logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: var(--transition);
}

.theme-toggle:hover, .logout-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle svg, .logout-btn svg {
  width: 18px;
  height: 18px;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ─── Topbar (mobile header) ─── */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-btn svg { width: 24px; height: 24px; }

/* ─── Container ─── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px;
  width: 100%;
  animation: fadeIn 0.25s ease-out;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-header h2 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.section-title {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 600;
}

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ─── Buttons ─── */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--surface-3);
}

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

.btn-danger:hover {
  filter: brightness(0.92);
  transform: translateY(-1px);
}

/* ─── Forms ─── */
label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}

input::placeholder, textarea::placeholder {
  color: var(--text-placeholder);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

input[type="color"] {
  width: 48px;
  padding: 2px;
  height: 40px;
}

.color-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.color-row input[type="text"] { flex: 1; }

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.inline-form input, .inline-form select {
  flex: 1;
  min-width: 160px;
}

/* ─── Tables ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table tbody tr {
  transition: background 0.15s;
}

.data-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

html[data-theme="light"] .data-table tbody tr:hover {
  background: var(--surface-2);
}

.data-table tr:last-child td { border-bottom: none; }

/* ─── Metrics ─── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-card .metric-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.metric-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-icon svg { width: 20px; height: 20px; }

.metric-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.metric-value {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.metric-trend {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.metric-trend.up { color: var(--success); }
.metric-trend.down { color: var(--danger); }

/* Legacy metric class preserved */
.metric {
  text-align: center;
}

.metric h3 {
  font-size: 2.25rem;
  margin: 0;
  color: var(--primary);
}

.metric p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ─── Tags ─── */
.tag-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-list li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag {
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 500;
}

.count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── Search / inline rows ─── */
.search-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.search-row input { flex: 1; }

/* ─── Modal ─── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal:not(.hidden) {
  opacity: 1;
  visibility: visible;
}

.modal.hidden { display: none !important; }

.modal-content {
  background: var(--surface);
  padding: 28px;
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px);
  transition: transform 0.2s ease-out;
}

.modal:not(.hidden) .modal-content {
  transform: translateY(0);
}

.modal-content.wide {
  max-width: 760px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 { margin: 0; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text); }

.transcript {
  overflow-y: auto;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.transcript-msg {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.transcript-msg.user {
  background: rgba(37, 99, 235, 0.12);
}

.transcript-msg strong {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.transcript-msg p {
  margin: 0;
  white-space: pre-wrap;
}

/* ─── Documents / embed / preview ─── */
.doc-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}

.doc-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.doc-list li:last-child { border-bottom: none; }

.embed-card textarea {
  font-family: monospace;
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.preview-card {
  margin-top: 24px;
}

.features {
  background: var(--surface-2);
  padding: 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  white-space: pre-wrap;
  margin: 12px 0;
  color: var(--text-muted);
}

.meta { color: var(--text-muted); font-size: 0.85rem; margin: 4px 0; }

.workspace-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Auth page ─── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  padding: 40px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--border);
}

.auth-card h1 {
  margin-top: 0;
  font-size: 1.6rem;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius);
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--text-muted);
  transition: var(--transition);
  font-family: inherit;
}

.tab.active {
  background: var(--primary);
  color: white;
}

/* ─── Messages / utility ─── */
.error { color: var(--danger); }
.success { color: var(--success); }
.hint { color: var(--text-muted); font-size: 0.9rem; margin-top: 0; }
.empty { color: var(--text-muted); font-style: italic; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-subtitle {
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto 20px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ─── Toasts ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  color: white;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slideInRight 0.2s ease-out;
}

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

/* ─── Skeleton ─── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Responsive ─── */
@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .main { margin-left: 0; }

  .topbar { display: flex; }

  .container { padding: 20px; }

  .metric-grid { grid-template-columns: 1fr; }

  .card-grid { grid-template-columns: 1fr; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
}
