:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-2: #6b7280;
  --primary: #0f766e;
  --primary-soft: #e6f4f3;
  --primary-hover: #0d6660;
  --success: #159365;
  --success-soft: #e9fbf4;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --danger: #be185d;
  --danger-soft: #fdf2f8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.07);
  --navy: #071d33;
  --topbar-bg: #071d33;
  --topbar-text: #e5eef8;
  --chat-bg: #071d33;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273549;
  --border: #334155;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --primary: #2dd4bf;
  --primary-soft: #134e4a;
  --primary-hover: #5eead4;
  --success: #4ade80;
  --success-soft: #14532d;
  --warning: #fbbf24;
  --warning-soft: #451a03;
  --danger: #fb7185;
  --danger-soft: #4c0519;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.3);
  --topbar-bg: #020617;
  --topbar-text: #f1f5f9;
  --chat-bg: #020617;
  --metric-1: linear-gradient(135deg, #0f766e, #14b8a6);
  --metric-2: linear-gradient(135deg, #065f46, #34d399);
  --metric-3: linear-gradient(135deg, #075985, #38bdf8);
  --metric-4: linear-gradient(135deg, #831843, #f472b6);
}

[data-theme="light"] {
  --metric-1: var(--primary);
  --metric-2: linear-gradient(135deg, #159365, #34d399);
  --metric-3: linear-gradient(135deg, #0369a1, #38bdf8);
  --metric-4: linear-gradient(135deg, #be185d, #f472b6);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 84px auto 0 0;
  z-index: 10;
  display: flex;
  width: 110px;
  flex-direction: column;
  align-items: center;
  padding: 20px 14px;
  color: var(--text-2);
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  color: #21382c;
  background: #d9e7df;
  font-family: Georgia, serif;
  font-size: 22px;
}

[data-theme="dark"] .brand-mark {
  color: #134e4a;
  background: #2dd4bf;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: Georgia, serif;
  font-size: 20px;
  font-weight: 500;
}

.brand small,
.sidebar-footer small {
  margin-top: 3px;
  color: #aebfb5;
  font-size: 11px;
}

.nav {
  display: grid;
  width: 100%;
  gap: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  min-height: 48px;
  padding: 0;
  border-radius: 0;
  color: #4b5563;
  font-size: 0;
  font-weight: 600;
  text-decoration: none;
  transition: 180ms ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.nav-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: 0;
  font-size: 18px;
}

.sidebar-footer {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
}

.sidebar-footer strong,
.sidebar-footer small {
  display: block;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7bd8a4;
  box-shadow: 0 0 0 5px rgba(123, 216, 164, 0.12);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.page-btn:hover:not(:disabled):not(.disabled):not(.page-ellipsis) {
  border-color: var(--primary);
  color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-btn:disabled,
.page-btn.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.page-ellipsis {
  border: none;
  background: none;
  cursor: default;
  min-width: 16px;
  color: var(--text-2);
}

.main {
  margin-left: 110px;
  padding: 116px 34px 30px;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  display: flex;
  min-height: 84px;
  align-items: center;
  gap: 18px;
  justify-content: space-between;
  padding: 0 34px;
  color: var(--topbar-text);
  background: var(--topbar-bg);
  box-shadow: 0 2px 8px rgba(7, 29, 51, 0.16);
}

.topbar h1,
.topbar p,
.hero h2,
.hero p,
.panel h3,
.panel h4 {
  margin: 0;
}

.topbar h1 {
  margin-top: 3px;
  font-size: 24px;
  font-weight: 700;
}

.eyebrow,
.section-kicker {
  color: var(--text-2);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.24);
}

.button-primary:hover {
  background: var(--primary-hover);
}

.button-secondary {
  color: var(--topbar-text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.menu-button {
  display: none;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #e5eef8;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.section {
  scroll-margin-top: 20px;
}

.hero {
  position: relative;
  display: flex;
  min-height: 178px;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
  padding: 30px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero::after {
  position: absolute;
  right: 18%;
  bottom: -180px;
  width: 390px;
  height: 390px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  content: "";
}

.hero h2 {
  max-width: 600px;
  margin: 12px 0 10px;
  font-size: clamp(28px, 3vw, 42px);
  font-weight: 700;
  line-height: 1.04;
  letter-spacing: -0.03em;
}

.hero p {
  max-width: 560px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
}

.pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pill-soft {
  color: var(--primary);
  border: 1px solid var(--primary-soft);
  background: var(--primary-soft);
}

.pill-light {
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
}

.pill-success {
  color: var(--success);
  background: var(--success-soft);
}

.pill-warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.pill-danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.hero-orb {
  position: relative;
  z-index: 1;
  display: grid;
  width: 126px;
  height: 126px;
  flex: 0 0 auto;
  place-items: center;
  margin-right: 8%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 24px rgba(255, 255, 255, 0.025);
}

.hero-orb span {
  display: grid;
  width: 68px;
  height: 68px;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 34px;
}

.hero-orb i {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d8e6dd;
}

.hero-orb i:nth-of-type(1) {
  top: 2px;
  right: 15px;
}

.hero-orb i:nth-of-type(2) {
  bottom: 9px;
  left: 5px;
}

.hero-orb i:nth-of-type(3) {
  right: -9px;
  bottom: 32px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin: 18px 0 22px;
}

.metric-card,
.panel {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: flex;
  min-height: 178px;
  flex-direction: column;
  padding: 20px;
  border-radius: var(--radius);
  color: var(--text);
  border: 0;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

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

.metric-primary,
.metric-card:nth-child(2),
.metric-card:nth-child(3),
.metric-card:nth-child(4) {
  color: #fff;
}

.metric-primary {
  background: var(--metric-1);
}

.metric-card:nth-child(2) {
  background: var(--metric-2);
}

.metric-card:nth-child(3) {
  background: var(--metric-3);
}

.metric-card:nth-child(4) {
  background: var(--metric-4);
}

.metric-primary .metric-label,
.metric-primary .metric-detail,
.metric-card .metric-label,
.metric-card .metric-detail {
  color: rgba(255, 255, 255, 0.8);
}

.metric-primary .metric-value,
.metric-card:nth-child(2) .metric-value,
.metric-card:nth-child(3) .metric-value,
.metric-card:nth-child(4) .metric-value {
  color: #fff;
}

.metric-head,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 800;
}

.icon-green {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.icon-gold {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.icon-red {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.metric-label {
  margin-top: 22px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.metric-value {
  margin-top: 5px;
  font-size: clamp(25px, 2.5vw, 34px);
  font-weight: 750;
  letter-spacing: -0.03em;
}

.metric-detail {
  margin-top: auto;
  padding-top: 8px;
  color: var(--muted);
  font-size: 10px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.75fr);
  gap: 18px;
  margin-bottom: 18px;
}

.secondary-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.panel {
  scroll-margin-top: 18px;
  padding: 22px;
  border-radius: var(--radius);
}

.panel-header {
  margin-bottom: 18px;
}

.panel h3 {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 650;
}

.panel h4 {
  margin: 20px 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.muted {
  color: var(--text-2);
  font-size: 10px;
}

.date-badge {
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 10px;
  font-weight: 750;
}

.table-wrap {
  overflow-x: auto;
}

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

th {
  padding: 10px 8px;
  color: var(--text-2);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

td {
  padding: 14px 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

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

.source-cell,
.reference-cell {
  display: flex;
  align-items: center;
  gap: 9px;
}

.source-logo {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 10px;
  font-weight: 800;
}

.source-logo-icon {
  font-size: 0;
}

.source-logo-icon svg {
  width: 16px;
  height: 16px;
}

.reference-cell strong,
.reference-cell small {
  display: block;
}

.reference-cell small {
  max-width: 150px;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  text-transform: capitalize;
}

.status::before {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.status-accredited,
.status-completed {
  color: var(--success);
  background: var(--success-soft);
}

.status-pending,
.status-processing {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-rejected,
.status-mismatched,
.status-failed {
  color: var(--danger);
  background: var(--danger-soft);
}

.stack-list,
.compact-list {
  display: grid;
  gap: 10px;
}

.stack-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.stack-item-icon {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 13px;
}

.stack-item-copy {
  min-width: 0;
}

.stack-item-copy strong,
.stack-item-copy small {
  display: block;
}

.stack-item-copy strong {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stack-item-copy small {
  margin-top: 3px;
  color: var(--text-2);
  font-size: 9px;
}

.stack-item-value {
  margin-left: auto;
  text-align: right;
}

.stack-item-value strong,
.stack-item-value small {
  display: block;
}

.stack-item-value strong {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stack-item-value small {
  margin-top: 3px;
  color: var(--text-2);
  font-size: 8px;
  font-weight: 750;
  text-transform: uppercase;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.empty-state-icon {
  font-size: 28px;
  opacity: 0.5;
}

.exceptions-section {
  margin-bottom: 18px;
}

.exception-section {
  margin-bottom: 16px;
}

.exception-section h4 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.exception-section:first-child h4 {
  color: var(--danger);
}

.exception-section:last-of-type h4 {
  color: var(--warning);
}

.exception-section + .exception-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.exception-section .exception-more {
  width: fit-content;
  margin: 10px auto 0;
}

.exception-more {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
  margin-top: 10px;
  transition: all 150ms ease;
}

.exception-more.toggle {
  color: var(--primary);
  background: var(--primary-soft);
  cursor: pointer;
}

.exception-more.toggle:hover {
  background: var(--primary);
  color: #fff;
}

.stack-item-alert {
  border-color: var(--danger);
  background: var(--danger-soft);
  border-left: 3px solid var(--danger);
}

.stack-item-alert .stack-item-icon {
  color: var(--danger);
  background: rgba(190, 24, 93, 0.12);
}

.stack-item-warning {
  border-color: var(--warning);
  background: var(--warning-soft);
  border-left: 3px solid var(--warning);
}

.stack-item-warning .stack-item-icon {
  color: var(--warning);
  background: rgba(180, 83, 9, 0.12);
}

[data-theme="dark"] .stack-item-alert {
  background: rgba(251, 113, 133, 0.08);
  border-color: rgba(251, 113, 133, 0.3);
}

[data-theme="dark"] .stack-item-alert .stack-item-icon {
  background: rgba(251, 113, 133, 0.15);
  color: #fb7185;
}

[data-theme="dark"] .stack-item-warning {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.3);
}

[data-theme="dark"] .stack-item-warning .stack-item-icon {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

.dropzone {
  display: grid;
  min-height: 152px;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface-2);
  text-align: center;
  transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
}

.dropzone:hover,
.dropzone.dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}

.dropzone input {
  display: none;
}

.dropzone strong {
  font-size: 12px;
}

.dropzone small {
  color: var(--text-2);
  font-size: 9px;
}

.upload-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--primary);
}

.import-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.import-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 200ms ease;
}

.import-tab:hover {
  border-color: var(--primary);
  color: var(--text-1);
}

.import-tab.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.import-tab-content {
  display: none;
}

.import-tab-content.active {
  display: block;
}

.import-result,
.assistant-response {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  background: var(--surface-2);
  font-size: 10px;
  line-height: 1.6;
}

.compact-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 10px;
}

.compact-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-item small {
  color: var(--text-2);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 520px;
  margin-bottom: 0;
  border: 1px solid var(--border);
  background: var(--chat-bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #14b8a6);
  color: #fff;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-info strong {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.chat-header-info small {
  font-size: 11px;
  color: #48c98e;
}

.chat-reset-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-left: auto;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-reset-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: flex-start;
}

.chat-messages .message {
  flex-shrink: 0;
  overflow-wrap: break-word;
  max-width: 75%;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  animation: slideUp 250ms ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes tableRowIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.message {
  animation: slideUp 250ms ease-out;
}

.table-wrap tr {
  animation: fadeIn 200ms ease-out;
}

.message-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: #e5eef8;
  border-bottom-left-radius: 4px;
}

.message-text {
  display: block;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message-time {
  display: block;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 4px;
  text-align: right;
}

.message-user .message-time {
  color: rgba(255, 255, 255, 0.7);
}

[hidden] {
  display: none !important;
}

.typing-indicator {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  align-self: flex-start;
  margin-left: 16px;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
}

.typing-indicator .dots {
  display: flex;
  gap: 4px;
}

.typing-indicator .dot {
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.chat-input-form {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input-form input {
  flex: 1;
  height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  transition: border-color 200ms, background 200ms;
}

.chat-input-form input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.chat-input-form input:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.send-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  display: grid;
  place-items: center;
  color: #fff;
  cursor: pointer;
  transition: transform 150ms, box-shadow 150ms;
}

.send-button:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.4);
}

.send-button:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .chat-panel {
    height: 420px;
  }
}

@media (max-width: 480px) {
  .chat-panel {
    height: 360px;
  }

  .message {
    max-width: 85%;
  }
}

footer {
  display: flex;
  justify-content: space-between;
  padding: 8px 2px 0;
  color: var(--text-2);
  font-size: 9px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 320px;
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  color: #fff;
  background: var(--chat-bg);
  box-shadow: var(--shadow-md);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 200ms ease, transform 200ms ease;
  border: 1px solid rgba(255,255,255,0.1);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
  animation: toastIn 200ms ease-out;
}

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

@media (max-width: 1180px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 820px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

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

  .main {
    margin-left: 0;
    padding: 0 16px 24px;
  }

  .menu-button {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    background: var(--surface);
  }

  .topbar {
    min-height: 86px;
  }

  .topbar-actions .button-secondary {
    display: none;
  }

  .hero {
    min-height: 260px;
    padding: 30px;
  }

  .hero-orb {
    display: none;
  }

  .assistant-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar h1 {
    font-size: 21px;
  }

  .topbar-actions .button-primary {
    display: none;
  }

  .hero {
    min-height: 230px;
  }

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

  .metric-card {
    min-height: 150px;
  }

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

  .assistant-form {
    grid-template-columns: 1fr;
  }

  .nav-item {
    min-height: 48px;
    min-width: 44px;
  }

  .send-button,
  .chat-input-form input {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
