@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;
  transition: width 0.25s ease;
  z-index: 50;
  overflow: hidden;
}

/* Mobile: hidden by default, slide in */
@media (max-width: 768px) {
  .sidebar { width: 200px; transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar.open { transform: translateX(0); }
}

.sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 51;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  font-size: 18px;
  color: var(--text-secondary);
  line-height: 1;
}

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }
  .sidebar.open ~ .sidebar-toggle { left: 212px; }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  z-index: 49;
}

.sidebar.open ~ .sidebar-overlay {
  display: block;
}

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

.logo-icon { display: none; }

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

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  vertical-align: middle;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  overflow: hidden;
}

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

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

.sidebar-collapse {
  padding: 8px 20px 4px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transition: justify-content 0.2s;
}

.sidebar-collapse:hover { color: var(--text-secondary); }

.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;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-footer button .nav-icon { width: 16px; height: 16px; }

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

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

@media (max-width: 768px) {
  .main-content { margin-left: 0; padding-top: 60px; }
}

/* ─── Collapsed state (desktop) ──────────────────────────── */

.sidebar-collapsed .sidebar { width: 56px; }
.sidebar-collapsed .nav-label { opacity: 0; width: 0; }
.sidebar-collapsed .logo-full { display: none; }
.sidebar-collapsed .logo-icon { display: inline; }
.sidebar-collapsed .sidebar-logo { padding: 16px 0; text-align: center; }
.sidebar-collapsed .sidebar-nav a { padding: 10px 0; justify-content: center; gap: 0; }
.sidebar-collapsed .sidebar-footer { padding: 12px 0; text-align: center; }
.sidebar-collapsed .sidebar-footer button { justify-content: center; gap: 0; width: 100%; }
.sidebar-collapsed .sidebar-footer .nav-label { opacity: 0; width: 0; }
.sidebar-collapsed .sidebar-collapse { justify-content: center; padding: 8px 0 4px; }
.sidebar-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
.sidebar-collapsed .main-content { margin-left: 56px; }

.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: 160px;
}

/* ─── 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-active   { background: #dcfce7; color: #166534; }
.tag-disabled { background: #fee2e2; color: #991b1b; }
.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;
  position: relative;
  overflow: visible;
  white-space: nowrap;
}

.td-actions .actions-trigger {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  user-select: none;
}

.td-actions .actions-panel {
  display: none;
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 6px 8px;
  gap: 4px;
  z-index: 10;
  white-space: nowrap;
}

.td-actions:hover .actions-panel {
  display: flex;
}

.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: 4px 8px;
  text-decoration: none;
  border-radius: 4px;
}

.td-actions a:hover,
.td-actions button:hover { background: var(--bg); }

/* ─── Icon with tooltip ────────────────────────────────── */

.icon-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: default;
}

.icon-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #1f2937;
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  margin-bottom: 4px;
}

.icon-tip:hover::after { opacity: 1; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.status-active { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.status-dot.status-disabled { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

/* ─── 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) {
  .charts-grid { grid-template-columns: 1fr; }
}
