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

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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --text: #1f2937;
  --text-strong: #374151;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-disabled: #c4c4c4;
  --primary: #0D9488;
  --primary-hover: #0B7C72;
  --primary-light: #E6FAF8;
  --primary-tag-bg: #CCFBF1;
  --primary-tag-text: #0F766E;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.04);
  --font: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ─────────────────────────────────────────────── */

.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-md);
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-header h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

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

.login-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

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

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.code-row {
  display: flex;
  gap: 8px;
}

.code-row input { flex: 1; }

.code-row button {
  white-space: nowrap;
  padding: 10px 16px;
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

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

.btn-secondary:hover:not(:disabled) { background: #f3f4f6; }

.btn-full { width: 100%; margin-top: 8px; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* ─── Layout ────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  font-size: 15px;
  font-weight: 600;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-nav a {
  display: block;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
}

.sidebar-nav a:hover {
  background: var(--bg);
  color: var(--text);
}

.sidebar-nav a.active {
  color: var(--primary);
  background: var(--primary-light);
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.sidebar-footer button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
}

.sidebar-footer button:hover { color: var(--text); }

.main-content {
  flex: 1;
  margin-left: 200px;
  padding: 32px;
}

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

.page-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
}

.page-header .page-title { margin-bottom: 0; }

/* ─── Cards ─────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
}

/* ─── Charts ────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.chart-card canvas {
  max-height: 120px;
}

/* ─── Tables ────────────────────────────────────────────── */

.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.table-toolbar select,
.table-toolbar input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  background: var(--surface);
}

.table-toolbar select:focus,
.table-toolbar input:focus {
  border-color: var(--primary);
}

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

th, td {
  text-align: left;
  padding: 14px 24px;
  font-size: 13px;
}

th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.2px;
}

td {
  border-bottom: 1px solid var(--border-light);
  color: var(--text-strong);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }

.td-muted { color: var(--text-secondary); }
.td-primary { color: var(--primary); font-weight: 600; }

/* Tags */
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.tag-admin {
  background: var(--primary-tag-bg);
  color: var(--primary-tag-text);
}

.tag-green  { background: #f0fdf4; color: #15803d; }
.tag-blue   { background: #eff6ff; color: #1d4ed8; }
.tag-yellow { background: #fef3c7; color: #92400e; }
.tag-purple { background: #f3e8ff; color: #7c3aed; }
.tag-red    { background: #fef2f2; color: #dc2626; }
.tag-gray   { background: #f3f4f6; color: var(--text-secondary); }

.td-actions {
  text-align: right;
}

.td-actions a,
.td-actions button {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
  margin-left: 16px;
  text-decoration: none;
}

.td-actions a:first-child,
.td-actions button:first-child { margin-left: 0; }

.td-actions a:hover,
.td-actions button:hover { text-decoration: underline; }

/* ─── Pagination ────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-btns {
  display: flex;
  gap: 8px;
}

.pagination-btns button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-strong);
  cursor: pointer;
}

.pagination-btns button:hover:not(:disabled) { background: var(--bg); }

.pagination-btns button:disabled {
  color: var(--text-disabled);
  cursor: not-allowed;
}

/* ─── Modal ─────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
}

.modal-wide { max-width: 800px; }

.modal h2 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ─── Trajectory Detail ────────────────────────────────── */

.detail-section { margin-bottom: 20px; }

.detail-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.detail-section pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-list { list-style: none; }

.message-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}

.message-item .role {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.message-item .role.user { color: var(--primary); }
.message-item .role.assistant { color: var(--success); }

.message-item .content {
  padding: 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}

/* ─── Link button ───────────────────────────────────────── */

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  padding: 0;
  text-decoration: none;
}

.link-btn:hover { text-decoration: underline; }

/* ─── Empty / Loading ───────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* ─── Responsive ────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .charts-grid { grid-template-columns: 1fr; }
}
