:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --text: #172026;
  --muted: #66737f;
  --line: #d8e0e7;
  --accent: #0b6bcb;
  --accent-strong: #07549f;
  --danger: #b42318;
  --danger-bg: #fff2f0;
  --shadow: 0 12px 32px rgba(27, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.app-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.app-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 700;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file-picker span,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  cursor: pointer;
}

.file-picker span {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.file-picker:focus-within span,
.file-picker span:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-button:hover {
  background: var(--surface-muted);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.error-summary .summary-item:first-child strong {
  color: var(--danger);
}

.health-summary .summary-item:nth-child(2) strong {
  color: var(--danger);
}

.payment-summary .summary-item:nth-child(2) strong {
  color: #1f7a3f;
}

.payment-summary .summary-item:nth-child(3) strong {
  color: var(--danger);
}

.pos-summary .summary-item:nth-child(2) strong {
  color: #1f7a3f;
}

.pos-summary .summary-item:nth-child(3) strong {
  color: var(--danger);
}

.summary-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

.summary-item strong {
  font-size: 28px;
  line-height: 1;
}

.results-section {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
  font-size: 18px;
}

.section-title span {
  color: var(--muted);
  font-size: 14px;
}

.chart-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  color: var(--muted);
  font-size: 14px;
}

.chart-controls label {
  color: var(--muted);
}

.chart-controls select {
  min-height: 34px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.chart-wrap {
  position: relative;
  min-height: 320px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.line-chart {
  display: block;
  width: 100%;
  min-width: 760px;
  height: 320px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.chart-empty[hidden] {
  display: none;
}

.chart-grid-line {
  stroke: #dce4ea;
  stroke-width: 1;
}

.chart-axis-line {
  stroke: #9aa8b4;
  stroke-width: 1.5;
}

.chart-line {
  fill: none;
  stroke: var(--danger);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-point {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-point.is-issue {
  cursor: help;
  fill: var(--danger);
  stroke: #7a1b13;
}

.chart-y-label,
.chart-x-label,
.chart-title-y {
  fill: var(--muted);
  font-size: 12px;
}

.chart-y-label {
  text-anchor: end;
}

.chart-x-label {
  text-anchor: middle;
}

.chart-title-y {
  font-weight: 700;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: var(--surface);
}

.compact-table {
  min-width: 760px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: var(--surface-muted);
  color: #33414d;
  font-weight: 700;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.amount-diff {
  color: var(--danger);
  font-weight: 700;
}

.level-error {
  color: var(--danger);
  font-weight: 700;
}

.level-warning {
  color: #946200;
  font-weight: 700;
}

.level-ok {
  color: #1f7a3f;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-error {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge-warning {
  background: #fff7db;
  color: #805300;
}

.badge-ok {
  background: #eaf7ee;
  color: #1f7a3f;
}

.raw-line {
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-cell {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.file-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.placeholder {
  padding: 40px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.placeholder h2 {
  margin: 0 0 8px;
}

.placeholder p {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }
}
