:root {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e2ec;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --accent: #0f9f8f;
  --warning: #f97316;
  --danger: #dc2626;
  --shadow: 0 14px 40px rgba(20, 35, 60, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
.file-button {
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 750;
  padding: 0.72rem 0.95rem;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover,
.file-button:hover {
  background: var(--brand-dark);
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.18);
  transform: translateY(-1px);
}

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

.secondary:hover {
  background: #e9eef5;
}

.small {
  padding: 0.45rem 0.65rem;
  font-size: 0.82rem;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
}

.app-shell {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1640px;
  margin: 0 auto 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  letter-spacing: 0;
}

.actions,
.export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.hero-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  max-width: 1640px;
  margin: 0 auto 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.hero-band > div {
  background: var(--surface);
  padding: 20px;
}

.hero-band span,
.metric span,
.compare-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.hero-band strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1640px;
  margin: 0 auto;
}

aside {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

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

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 14px;
  font-weight: 850;
}

.panel-title small,
.muted {
  color: var(--muted);
  font-weight: 500;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field span,
.sub-title {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.input-shell {
  position: relative;
}

input,
select {
  width: 100%;
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  outline: 0;
  padding: 0.68rem 0.75rem;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.input-shell em {
  position: absolute;
  top: 50%;
  right: 10px;
  color: var(--muted);
  font-style: normal;
  transform: translateY(-50%);
  pointer-events: none;
}

.input-shell input {
  padding-right: 42px;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.error-box {
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
  padding: 0.8rem;
  margin-bottom: 12px;
}

.events-zone {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.event-form {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1fr 1fr auto;
  gap: 8px;
}

.event-list,
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  padding: 8px;
}

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

.metric {
  padding: 16px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.05rem, 1.6vw, 1.45rem);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

canvas {
  display: block;
  width: 100%;
  min-height: 210px;
}

.table-wrap {
  max-height: 620px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.72rem;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: rgba(37, 99, 235, 0.09);
}

tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--surface-alt);
  font-weight: 850;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.compare-card,
.history-item {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.history-item {
  width: 100%;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dark {
  color-scheme: dark;
  --bg: #101418;
  --surface: #181d23;
  --surface-alt: #202731;
  --text: #edf2f7;
  --muted: #a7b0bd;
  --line: #303946;
  --brand: #3b82f6;
  --brand-dark: #60a5fa;
  --accent: #2dd4bf;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .summary-grid,
  .compare-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .hero-band {
    grid-template-columns: 1fr;
    display: grid;
  }

  .form-grid,
  .charts-grid,
  .summary-grid,
  .compare-grid,
  .event-form {
    grid-template-columns: 1fr;
  }

  .actions,
  .export-buttons {
    width: 100%;
  }

  .actions button,
  .export-buttons button,
  .file-button {
    flex: 1 1 145px;
    justify-content: center;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  aside,
  .charts-grid,
  .compare-grid,
  .history-list {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .layout,
  .content {
    display: block;
  }

  .panel,
  .metric,
  .hero-band {
    box-shadow: none;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
  }
}
