:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --line: #d9e0ea;
  --text: #172033;
  --muted: #637083;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --green: #047857;
  --green-soft: #d1fae5;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --orange: #b45309;
  --orange-soft: #ffedd5;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

.muted { color: var(--muted); }
.eyebrow {
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 600;
}
input, select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}
input:focus, select:focus {
  outline: 2px solid var(--blue-soft);
  border-color: var(--blue);
}

.primary, .secondary, .ghost, .link-btn, .danger-btn {
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}
.primary { color: #fff; background: var(--blue); }
.secondary { color: var(--blue); background: var(--blue-soft); border-color: #bfdbfe; }
.ghost { color: var(--muted); background: #fff; border-color: var(--line); }
.link-btn { color: var(--blue); background: transparent; padding-inline: 0; }
.danger-btn { color: var(--red); background: var(--red-soft); border-color: #fecaca; }

.app-view {
  min-height: 100vh;
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-chip {
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tab {
  min-height: 34px;
  padding: 7px 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-weight: 700;
}
.tab.active { color: var(--blue); background: var(--blue-soft); }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  margin-left: 5px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--orange-soft);
  color: var(--orange);
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 16px; }
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}
.metric {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.metric span { display: block; margin-bottom: 8px; color: var(--muted); }
.metric strong { font-size: 26px; }
.metric.success strong, .good { color: var(--green); }
.metric.danger strong { color: var(--red); }
.metric.warn strong, .warn-text { color: var(--orange); }

.two-column {
  display: grid;
  grid-template-columns: minmax(280px, .8fr) minmax(480px, 1.4fr);
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card:not(.safety-item) { padding: 14px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.stack { display: grid; gap: 8px; }
.attention-item {
  padding: 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.attention-item strong { display: block; margin-bottom: 3px; }

.table-wrap { overflow: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}
td.subject, td.description {
  max-width: 360px;
  white-space: normal;
}
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
}
.chip.ok { color: var(--green); background: var(--green-soft); }
.chip.fail { color: var(--red); background: var(--red-soft); }
.chip.review { color: var(--orange); background: var(--orange-soft); }
.chip.neutral { color: var(--muted); background: var(--surface-2); }
.amount-in { color: var(--green); font-weight: 800; }
.amount-out { color: var(--red); font-weight: 800; }

.safety-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.safety-item {
  display: grid;
  gap: 8px;
  padding: 14px;
}
.safety-item span { color: var(--muted); font-weight: 700; }
.safety-item p { color: var(--muted); line-height: 1.45; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.error-line { min-height: 18px; color: var(--red); }

dialog {
  width: min(520px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 900px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 540px) {
  .app-view { padding: 12px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .topbar-actions { width: 100%; justify-content: space-between; }
}
