:root {
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe4ef;
  --panel: #ffffff;
  --bg: #f5f7fb;
  --blue: #2563eb;
  --cyan: #0891b2;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
input, textarea, select, button { font: inherit; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.12), transparent 28%),
    radial-gradient(circle at 80% 0%, rgba(8, 145, 178, 0.16), transparent 30%),
    #eef4fb;
}
.auth-card {
  width: min(440px, 100%);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.brand-mark, .logo span {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #fff;
  font-weight: 900;
}
.auth-card h1 { margin: 18px 0 8px; font-size: 2rem; }
.auth-card p, .muted { color: var(--muted); }
.stack-form { display: grid; gap: 16px; }
label { display: grid; gap: 8px; color: #334155; font-weight: 700; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
}
input[type="file"] {
  padding: 10px;
}
textarea { resize: vertical; }
.field-help {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
}
.primary-btn, .secondary-btn {
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary-btn { background: var(--blue); color: #fff; }
.secondary-btn { background: #e8eef8; color: #1e3a8a; }
.subtle-link { display: inline-block; margin-top: 18px; color: var(--blue); font-weight: 700; }
.notice {
  padding: 12px 14px;
  border-radius: 8px;
  margin: 16px 0;
  font-weight: 700;
}
.notice.error { background: #fee2e2; color: #991b1b; }
.notice.success { background: #dcfce7; color: #166534; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 270px 1fr; }
.sidebar {
  background: #101827;
  color: #dbeafe;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.logo { display: flex; align-items: center; gap: 12px; font-size: 1.05rem; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a {
  padding: 12px;
  border-radius: 8px;
  color: #cbd5e1;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar-user { margin-top: auto; display: grid; gap: 8px; color: #cbd5e1; }
.sidebar-user span { color: #94a3b8; font-size: 0.9rem; overflow-wrap: anywhere; }
.sidebar-user a { color: #93c5fd; font-weight: 800; }
.main { padding: 28px; overflow: hidden; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h1 { margin: 4px 0 0; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.eyebrow { color: var(--cyan); text-transform: uppercase; letter-spacing: 0; font-size: 0.78rem; font-weight: 900; }
.model-pill {
  background: #e0f2fe;
  color: #075985;
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 800;
}
.hero-panel, .panel, .chat-panel, .tasks-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}
.hero-panel {
  padding: clamp(22px, 4vw, 38px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.hero-actions, .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.hero-panel h2 { margin: 8px 0; font-size: clamp(1.8rem, 4vw, 3.4rem); max-width: 760px; }
.hero-panel p { color: var(--muted); max-width: 760px; line-height: 1.65; }
.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { padding: 22px; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.panel-head h2 { margin: 0; }
.panel-head p { margin: 6px 0 0; color: var(--muted); }
.list { display: grid; gap: 10px; }
.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.list-row span { display: grid; gap: 4px; }
.list-row small, .task-card small { color: var(--muted); }
.workspace-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.workspace-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 12px;
}
.workspace-card h3 { margin: 0; }
.workspace-card p { color: var(--muted); min-height: 44px; }

.agent-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  height: calc(100vh - 145px);
}
.chat-panel, .tasks-panel { min-height: 0; padding: 18px; display: flex; flex-direction: column; }
.messages {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 6px;
}
.message {
  display: flex;
}
.message div {
  max-width: min(760px, 86%);
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.message.user { justify-content: flex-end; }
.message.user div { background: var(--blue); color: #fff; }
.message.assistant div { background: #eef4fb; color: var(--ink); }
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding-top: 14px;
}
.task-list { overflow: auto; display: grid; gap: 12px; padding-right: 4px; }
.task-list.compact { overflow: visible; }
.task-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  background: #fff;
}
.report-workspace-form {
  margin-bottom: 20px;
}
.instruction-card {
  border: 1px solid #bae6fd;
  background: #f0f9ff;
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 10px;
}
.instruction-card h3 {
  margin: 0;
  font-size: 1.25rem;
}
.instruction-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.period-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.report-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
}
.report-output {
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 680px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 18px;
  line-height: 1.55;
}
.chart-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}
.pdf-link {
  width: fit-content;
  margin-bottom: 14px;
}
.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.download-row .pdf-link {
  margin-bottom: 0;
}
.analysis-dashboard {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}
.kpi-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.kpi-grid strong {
  display: block;
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  color: var(--ink);
}
.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #f8fafc;
}
.chart-card h3 {
  margin: 0 0 14px;
  font-size: 1rem;
}
.bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(120px, 2fr) auto;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  color: #334155;
  font-size: 0.9rem;
}
.bar-row span {
  overflow-wrap: anywhere;
}
.bar-row div {
  height: 12px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.bar-row i {
  display: block;
  height: 100%;
  min-width: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), #60a5fa);
}
.bar-row i.teal {
  background: linear-gradient(90deg, var(--cyan), #67e8f9);
}
.bar-row b {
  color: var(--ink);
}
.mini-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background: #fff;
}
.mini-table-wrap h3 {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.mini-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  font-size: 0.9rem;
}
.mini-table th,
.mini-table td {
  border-bottom: 1px solid #e8eef8;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}
.mini-table th {
  background: #f8fafc;
  color: #334155;
  font-size: 0.78rem;
  text-transform: uppercase;
}
.vehicle-period-table th:nth-child(n+4),
.vehicle-period-table td:nth-child(n+4) {
  text-align: center;
}
.mini-table tr.danger-row td,
.mini-table tr.danger-row strong,
.mini-table td.danger-cell {
  color: var(--red);
}
.feature-list {
  display: grid;
  gap: 12px;
}
.feature-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
  display: grid;
  gap: 6px;
}
.feature-list span {
  color: var(--muted);
  line-height: 1.45;
}
.report-output.small {
  max-height: 360px;
  margin-top: 14px;
}
.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}
.empty-state strong {
  color: var(--ink);
}
.report-history {
  display: grid;
  gap: 12px;
}
.report-history details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}
.report-history summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.report-history summary span {
  color: var(--muted);
  font-size: 0.9rem;
}
.task-card p { color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.priority {
  width: fit-content;
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 8px;
}
.priority.low { background: #dcfce7; color: #166534; }
.priority.medium { background: #fef3c7; color: #92400e; }
.priority.high { background: #fee2e2; color: #991b1b; }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .main { padding: 18px; }
  .grid.two, .agent-layout, .report-layout, .period-grid { grid-template-columns: 1fr; }
  .agent-layout { height: auto; }
  .chat-panel { min-height: 70vh; }
  .hero-panel, .topbar { align-items: stretch; flex-direction: column; }
  .composer { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
