/* ═══ MTS Dashboard — Modern Design System ═══ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.10);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 1.5rem 2rem;
  max-width: 1400px;
}

/* ── Sidebar ── */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 2rem; padding-bottom: 1rem;
  border-bottom: 1px solid #1e293b;
}
.sidebar-brand img { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; }
.sidebar-brand .badge {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.sidebar-brand span { color: #e2e8f0; font-weight: 700; font-size: 1.1rem; }

.sidebar-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #64748b; font-weight: 600; margin: 1.5rem 0 0.5rem 0.5rem;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 0.7rem 1rem; margin-bottom: 4px;
  border-radius: 10px; color: var(--sidebar-text);
  text-decoration: none; font-weight: 500; font-size: 0.9rem;
  transition: all 0.2s ease; border: 1px solid transparent;
}
.nav-item:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
  transform: translateX(2px);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(37,99,235,0.3), rgba(29,78,216,0.2));
  border-color: rgba(59,130,246,0.3);
  color: #fff;
}
.nav-item .icon { font-size: 1.1rem; }

.sidebar-divider { height: 1px; background: #1e293b; margin: 1rem 0; }

/* ── Header ── */
.page-header {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 1rem; margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
}
.page-header img { width: 44px; height: 44px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.08); object-fit: contain; }
.page-header .badge {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; color: #0f172a; }
.page-header .subtitle { color: var(--text-muted); font-size: 0.85rem; }

/* ── Status bar ── */
.status-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: linear-gradient(90deg, #eff6ff, #f0fdf4);
  border-radius: 10px; margin-bottom: 1.5rem; border: 1px solid #dbeafe;
  font-size: 0.82rem; color: var(--text-muted);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.fresh { background: var(--success); }
.status-dot.stale { background: var(--warning); }
.status-dot.dead { background: var(--danger); }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 4px; background: #fff; border-radius: 12px;
  padding: 4px; box-shadow: var(--shadow); border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.tab {
  padding: 8px 24px; border-radius: 8px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; transition: all 0.2s ease;
  border: none; background: transparent; font-size: 0.9rem;
}
.tab:hover { background: #f1f5f9; color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi-card {
  background: linear-gradient(135deg, var(--c1, #3b82f6), var(--c2, #1d4ed8));
  border-radius: var(--radius); padding: 1.1rem 1.25rem; color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10); transition: all 0.2s ease;
  min-height: 100px; display: flex; flex-direction: column; justify-content: space-between;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.14); }
.kpi-card .icon { font-size: 1.6rem; line-height: 1; margin-bottom: 6px; }
.kpi-card .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.85; font-weight: 600; }
.kpi-card .value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }

/* ── Section headers ── */
.section-header {
  display: flex; align-items: center; gap: 10px;
  margin: 1.5rem 0 0.75rem 0;
}
.section-header .icon { font-size: 1.3rem; }
.section-header h2 { font-size: 1.1rem; font-weight: 700; color: #0f172a; }
.section-header .sub { color: var(--text-muted); font-size: 0.8rem; }

/* ── Tables ── */
.table-wrap {
  background: #fff; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; }
thead th {
  background: #f8fafc; font-weight: 600; color: #475569;
  text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.03em;
  padding: 10px 16px; border-bottom: 2px solid var(--border); text-align: left;
}
tbody td { padding: 10px 16px; border-bottom: 1px solid #f1f5f9; font-size: 0.85rem; }
tbody tr:hover { background: #eff6ff; }
tbody tr.row-cancelled { background: #fef2f2; }
tbody tr.row-cancelled:hover { background: #fee2e2; }
tbody tr.row-overridden { background: #fefce8; }
tbody tr.row-overridden:hover { background: #fef3c7; }
tbody tr.row-remarked { background: #eff6ff; }
tbody tr.row-remarked:hover { background: #dbeafe; }
tbody tr.row-junk { background: #fee2e2; }
tbody tr.row-junk:hover { background: #fecaca; }

/* Junk measurement / re-measure request pill */
.pill-remeasure {
  display: inline-block; padding: 2px 8px; background: #fee2e2; color: #b91c1c;
  border: 1px solid #fca5a5; border-radius: 10px; font-size: 0.68rem; font-weight: 700;
  margin-left: 4px;
}
.btn-remeasure { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; }
.btn-remeasure:hover { background: #fee2e2; border-color: #f87171; }

.remeasure-chip {
  background: #fee2e2; border: 1px solid #fca5a5; border-radius: 10px;
  padding: 8px 12px; margin-bottom: 0.5rem; display: none;
}
tbody tr:last-child td { border-bottom: none; }

/* ── Chart container ── */
.chart-card {
  background: #fff; border-radius: var(--radius); padding: 1.25rem;
  border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 1rem;
}
.chart-card h3 { font-size: 0.95rem; font-weight: 600; color: #0f172a; margin-bottom: 0.75rem; }
.chart-container { position: relative; height: 280px; }

/* ── 2-column layout ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Login page ── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
}
.login-card {
  background: #fff; border-radius: 20px; padding: 2.5rem; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card .brand { text-align: center; margin-bottom: 2rem; }
.login-card .brand img { width: 56px; height: 56px; border-radius: 12px; margin-bottom: 12px; object-fit: contain; }
.login-card .brand .badge {
  width: 56px; height: 56px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 20px;
  box-shadow: 0 6px 20px rgba(37,99,235,0.3);
}
.login-card h1 { font-size: 1.5rem; font-weight: 700; color: #0f172a; }
.login-card .tagline { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 0.7rem 0.9rem; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 0.95rem; transition: all 0.2s ease;
  background: #fff; color: var(--text);
}
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

.btn {
  display: inline-block; padding: 0.75rem 1.5rem; border: none; border-radius: 10px;
  font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: all 0.2s ease;
  text-decoration: none; text-align: center;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,99,235,0.4); }
.btn-block { width: 100%; }

.alert { padding: 0.75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.85rem; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #16a34a; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

.login-footer { text-align: center; margin-top: 1.5rem; font-size: 0.82rem; color: var(--text-muted); }
.login-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* ── Loading ── */
.loading { text-align: center; padding: 2rem; color: var(--text-muted); }
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Animations ── */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeInUp 0.4s ease-out; }

/* ── Mobile ── */
.mobile-toggle { display: none; }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 1rem; }
  .mobile-toggle {
    display: flex; align-items: center; gap: 8px;
    background: var(--sidebar-bg); color: #fff; border: none;
    padding: 0.6rem 1rem; border-radius: 10px; font-size: 1.1rem;
    cursor: pointer; margin-bottom: 1rem;
  }
  .two-col { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .table-wrap { overflow-x: auto; }
  table { min-width: 600px; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Table toolbar ── */
.table-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: #f8fafc;
  flex-wrap: wrap;
}
.table-toolbar .filter-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  flex-wrap: wrap; padding-top: 8px; border-top: 1px solid #e2e8f0;
}
.table-toolbar .search-input {
  flex: 1; min-width: 150px; padding: 7px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 0.85rem; background: #fff; color: var(--text);
}
.table-toolbar .search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.btn-download {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  background: linear-gradient(135deg, #059669, #047857); color: #fff;
  border: none; border-radius: 8px; font-weight: 600; font-size: 0.82rem;
  cursor: pointer; transition: all 0.2s ease; text-decoration: none;
  white-space: nowrap;
}
.btn-download:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(5,150,105,0.3); }
.table-count { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
.table-wrap table thead th { cursor: default; }
.table-wrap { max-height: 600px; overflow-y: auto; }

/* ── Filterable table styles ── */
.filter-select {
  padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.82rem; background: #fff; color: var(--text); cursor: pointer;
  transition: all 0.15s ease; white-space: nowrap; max-width: 160px;
}
.filter-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.filter-select:hover { border-color: #94a3b8; }
.btn-clear-filters {
  padding: 6px 12px; background: #f1f5f9; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 8px; font-size: 0.78rem;
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.btn-clear-filters:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }

/* ── Column visibility toggle ── */
.btn-cols {
  padding: 7px 12px; background: #f1f5f9; border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-weight: 600; font-size: 0.82rem;
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.btn-cols:hover { background: #e2e8f0; border-color: #94a3b8; }
.col-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15,23,42,0.18); padding: 8px;
  min-width: 190px; max-height: 320px; overflow-y: auto; text-align: left;
}
.col-menu-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  font-size: 0.82rem; color: var(--text); border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.col-menu-item:hover { background: #f1f5f9; }
.col-menu-item input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }
.btn-cols-reset {
  display: block; width: 100%; margin-top: 6px; padding: 6px 8px;
  background: #f1f5f9; border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.78rem; color: var(--text-muted); cursor: pointer;
}
.btn-cols-reset:hover { background: #e0e7ff; color: var(--primary); }

th.sortable { cursor: pointer; user-select: none; transition: background 0.15s; }
th.sortable:hover { background: #e2e8f0; }
th.sortable .sort-arrow { font-size: 0.65rem; color: var(--primary); }

/* ── Remark & Cancel styles ── */
.btn-small {
  background: #f1f5f9; border: 1px solid #cbd5e1; color: #475569;
  padding: 3px 10px; border-radius: 6px; font-size: 0.75rem; cursor: pointer;
  transition: all 0.15s ease; white-space: nowrap;
}
.btn-small:hover { background: #e2e8f0; border-color: #94a3b8; }
.remark-text {
  display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
  white-space: normal; word-break: break-word; cursor: pointer; font-size: 0.78rem; color: #334155;
  padding: 2px 6px; border-radius: 4px; background: #f8fafc; border: 1px solid #e2e8f0;
}
.remark-text:hover { background: #eef2ff; border-color: #c7d2fe; }
.btn-cancel {
  background: #fef2f2; border: 1px solid #fca5a5; color: #dc2626;
  padding: 3px 10px; border-radius: 6px; font-size: 0.75rem; cursor: pointer;
  transition: all 0.15s ease; white-space: nowrap;
}
.btn-cancel:hover { background: #fee2e2; border-color: #f87171; }
.badge-pending {
  display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 0.72rem;
  font-weight: 600; background: #fef3c7; color: #92400e; border: 1px solid #fcd34d;
  white-space: nowrap;
}
.badge-cancelled {
  display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 0.72rem;
  font-weight: 600; background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5;
  white-space: nowrap;
}
.badge-rejected {
  display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 0.72rem;
  font-weight: 600; background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1;
  white-space: nowrap;
}

/* Inline approve/reject icons */
.icon-approve {
  background: none; border: 1px solid #16a34a; color: #16a34a;
  border-radius: 4px; width: 22px; height: 22px; cursor: pointer;
  font-size: 0.8rem; line-height: 1; padding: 0; margin-left: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-approve:hover { background: #16a34a; color: #fff; }
.icon-reject {
  background: none; border: 1px solid #dc2626; color: #dc2626;
  border-radius: 4px; width: 22px; height: 22px; cursor: pointer;
  font-size: 0.8rem; line-height: 1; padding: 0; margin-left: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-reject:hover { background: #dc2626; color: #fff; }

/* Date range bar */
.date-range-bar {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.75rem 1rem; background: var(--card); border-radius: 12px;
  margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}


/* ═══════════════ AI Chat — Codex-style full-height layout ═══════════════ */
.chat-page {
  display: flex; flex-direction: column;
  height: calc(100vh - 3rem);
  min-height: 520px;
}

.chat-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding-bottom: 0.9rem; margin-bottom: 1rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}

.chat-topbar-left { display: flex; align-items: center; gap: 0.8rem; min-width: 0; }

.chat-topbar-title {
  font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em;
  color: var(--text); white-space: nowrap;
}

.chat-model-chip {
  font-size: 0.7rem; font-weight: 600; padding: 0.22rem 0.6rem;
  border-radius: 999px; color: #1d4ed8;
  background: rgba(37,99,235,0.08); border: 1px solid rgba(37,99,235,0.22);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}

.chat-layout { display: flex; flex: 1; min-height: 0; gap: 0; }

.chat-sidebar {
  width: 260px; flex-shrink: 0; display: flex; flex-direction: column;
  min-height: 0; border-right: 1px solid var(--border); padding-right: 1rem;
}

.chat-sidebar-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--text-muted);
  padding: 0.15rem 0.4rem 0.6rem; flex-shrink: 0;
}

.chat-session-list {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 0.15rem; padding-right: 2px; min-height: 0;
}

.chat-session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.55rem 0.7rem; border-radius: 10px; cursor: pointer;
  transition: background 0.15s; border: 1px solid transparent;
}

.chat-session-item:hover { background: rgba(100,116,139,0.10); }

.chat-session-item.active {
  background: rgba(37,99,235,0.10); border-color: rgba(37,99,235,0.25);
}

.chat-session-title {
  font-size: 0.8rem; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}

.chat-session-delete {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.95rem; line-height: 1; padding: 0.15rem 0.25rem; border-radius: 5px;
  flex-shrink: 0;
}

.chat-session-delete:hover { color: var(--danger); background: rgba(220,38,38,0.08); }

.chat-empty-sessions, .chat-error-msg {
  font-size: 0.78rem; color: var(--text-muted); padding: 0.75rem 0.5rem; text-align: center;
}

.chat-error-msg { color: var(--danger); }

.chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; padding-left: 1.5rem;
}

.chat-messages {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 0.5rem 0.25rem 1rem;
  display: flex; flex-direction: column; gap: 1.35rem;
}

.chat-msg {
  width: 100%; max-width: 820px; margin: 0 auto;
  display: flex; gap: 0.85rem;
}

.chat-msg-user { flex-direction: row-reverse; }

.chat-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; margin-top: 0.1rem;
}

.chat-avatar-ai {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}

.chat-avatar-user { background: rgba(100,116,139,0.14); }

.chat-msg-body { flex: 1; min-width: 0; }

.chat-msg-user .chat-msg-body { display: flex; flex-direction: column; align-items: flex-end; }

.chat-msg-role {
  font-size: 0.72rem; font-weight: 700; color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.chat-msg-content {
  font-size: 0.92rem; line-height: 1.65; color: var(--text);
  word-wrap: break-word;
}

.chat-msg-user .chat-msg-content {
  background: rgba(100,116,139,0.10);
  border: 1px solid var(--border);
  padding: 0.65rem 0.95rem; border-radius: 14px 14px 4px 14px;
  text-align: left; max-width: 100%;
}

.chat-msg-error .chat-msg-content { color: var(--danger); }

.chat-msg-content .chat-md-li { margin: 0.15rem 0; }

.chat-md-table {
  border-collapse: collapse; margin: 0.6rem 0; font-size: 0.78rem; width: 100%;
}

.chat-md-table th, .chat-md-table td {
  border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left;
}

.chat-md-table th { background: rgba(100,116,139,0.08); font-weight: 600; }

.chat-tools-used {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.72rem; font-weight: 600; color: #1d4ed8;
  margin-top: 0.5rem; padding: 0.22rem 0.6rem; border-radius: 999px;
  background: rgba(37,99,235,0.07); border: 1px solid rgba(37,99,235,0.20);
}

.chat-msg-time { font-size: 0.66rem; color: var(--text-muted); margin-top: 0.35rem; }

.chat-empty { margin: auto; text-align: center; max-width: 560px; padding: 1.5rem 1rem; }

.chat-empty-icon {
  width: 58px; height: 58px; margin: 0 auto 0.9rem;
  border-radius: 18px; background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.7rem; box-shadow: 0 6px 18px rgba(37,99,235,0.25);
}

.chat-empty h3 { font-size: 1.2rem; margin-bottom: 0.45rem; letter-spacing: -0.02em; }

.chat-empty-sub { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.2rem; line-height: 1.5; }

.chat-suggestions {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem;
}

.chat-suggestion {
  text-align: left; padding: 0.65rem 0.85rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card-bg);
  color: var(--text); font-size: 0.8rem; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.chat-suggestion:hover {
  border-color: var(--primary); box-shadow: 0 2px 10px rgba(37,99,235,0.10);
  transform: translateY(-1px);
}

.chat-upload-hint { font-size: 0.76rem; color: var(--text-muted); margin-top: 1.1rem; }

.chat-composer-wrap {
  width: 100%; max-width: 820px; margin: 0 auto;
  padding: 0.75rem 0.25rem 0.25rem; flex-shrink: 0;
}

.chat-composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 0.55rem 0.55rem 0.55rem 0.7rem;
  box-shadow: 0 4px 14px rgba(15,23,42,0.07);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-composer:focus-within {
  border-color: var(--primary); box-shadow: 0 4px 18px rgba(37,99,235,0.14);
}

.chat-attach-btn {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid transparent; background: rgba(100,116,139,0.08);
  font-size: 1rem; cursor: pointer; line-height: 1;
  transition: border-color 0.15s, background 0.15s;
}

.chat-attach-btn:hover { border-color: var(--primary); background: rgba(37,99,235,0.08); }
.chat-attach-btn:disabled { opacity: 0.5; cursor: wait; }

#chat-input {
  flex: 1; resize: none; border: none; background: transparent;
  color: var(--text); font-size: 0.9rem; font-family: inherit;
  line-height: 1.5; padding: 0.5rem 0; max-height: 150px; outline: none;
}

#chat-input::placeholder { color: var(--text-muted); }

.chat-composer .btn-primary { flex-shrink: 0; }

.chat-attachment-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.45rem;
  padding: 0.32rem 0.7rem; border-radius: 999px; font-size: 0.75rem;
  background: rgba(37,99,235,0.08); border: 1px solid rgba(37,99,235,0.25);
  color: var(--text); white-space: nowrap; max-width: 260px;
}

.chat-attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-attachment-chip button {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.9rem; padding: 0; line-height: 1;
}

.chat-attachment-chip button:hover { color: var(--danger); }

.chat-typing-dots { display: inline-flex; gap: 5px; padding: 0.35rem 0; }

.chat-typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  animation: chatTyping 1.2s infinite;
}

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

@keyframes chatTyping {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.9); }
  30% { opacity: 1; transform: scale(1.1); }
}

@media (max-width: 900px) {
  .chat-page { height: calc(100vh - 5.5rem); }
  .chat-sidebar { width: 100%; max-height: 150px; border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 0.75rem; }
  .chat-layout { flex-direction: column; }
  .chat-main { padding-left: 0; }
  .chat-suggestions { grid-template-columns: 1fr; }
  .chat-model-chip { display: none; }
}

/* ── DO records selection bar ── */
.sel-bar {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 60;
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.3);
  font-size: 0.85rem;
  max-width: calc(100vw - 2rem);
  flex-wrap: wrap;
}
.sel-count { font-weight: 600; white-space: nowrap; }
.sel-label {
  padding: 0.35rem 0.55rem;
  border: 1px solid #475569;
  border-radius: 6px;
  font-size: 0.85rem;
  min-width: 15rem;
}
.sel-label:focus { outline: 2px solid #38bdf8; outline-offset: 1px; }
.sel-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid #475569;
  border-radius: 6px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.82rem;
  cursor: pointer;
}
.sel-btn:hover { background: #334155; }
.sel-btn-primary { background: #2563eb; border-color: #2563eb; }
.sel-btn-primary:hover { background: #1d4ed8; }
