:root {
  color-scheme: light;
  --canvas: #f5f7f4;
  --surface: #ffffff;
  --surface-muted: #eef3ee;
  --ink: #1b2821;
  --muted: #637168;
  --line: #d8e0d9;
  --teal: #0c766f;
  --teal-soft: #d8efea;
  --green: #2e774b;
  --green-soft: #e1f0e3;
  --coral: #c85844;
  --coral-soft: #f9e3df;
  --gold: #ab7612;
  --gold-soft: #f8edcf;
  --radius: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px max(24px, calc((100vw - 1440px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  position: relative;
  display: block;
  border: 2px solid var(--teal);
}

.brand-mark::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  right: -2px;
  bottom: -2px;
  background: var(--gold);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: 18px;
  font-weight: 720;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}

.status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 50%;
  background: var(--gold);
}

.status-dot.ready { background: var(--green); }
.status-dot.error { background: var(--coral); }

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 24px 44px;
}

.filter-band {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select {
  min-height: 36px;
  padding: 7px 9px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #c6d1c7;
  border-radius: var(--radius);
  outline: none;
}

input:focus,
select:focus { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal-soft); }

.filter-band label { min-width: 144px; }
.filter-band select { min-width: 170px; }

.button {
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { color: #fff; background: var(--teal); border-color: var(--teal); }
.button.primary:hover:not(:disabled) { background: #075d57; }
.button.secondary { color: var(--ink); background: var(--surface); border-color: #c6d1c7; }
.button.secondary:hover:not(:disabled) { background: var(--surface-muted); }

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

.metric-card {
  min-height: 124px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--teal);
  border-radius: var(--radius);
}

.metric-card.profit-card { border-top-color: var(--green); }
.metric-card.alert-card { border-top-color: var(--gold); }
.metric-card p { margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin-bottom: 8px; font-size: 24px; font-weight: 730; line-height: 1; letter-spacing: 0; }
.metric-card span { color: var(--muted); font-size: 12px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  align-items: start;
}

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

.chart-section {
  min-width: 0;
  padding: 0 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chart-section:first-child { grid-column: 1 / -1; }

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.section-heading.compact { padding: 0 0 14px; }

.chart-key {
  color: var(--muted);
  font-size: 12px;
}

.chart { width: 100%; height: 260px; margin-top: 4px; }

.import-panel {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

#import-form { display: grid; gap: 14px; }
.file-input input { max-width: 100%; padding: 6px; font-size: 12px; }
.file-status {
  min-height: 18px;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.import-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.template-link {
  display: inline-block;
  margin-top: 14px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.template-link:hover { text-decoration: underline; }

.import-result {
  min-height: 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.import-result.success { color: var(--green); }
.import-result.error { color: var(--coral); }
.import-result.pending { color: var(--muted); }

.chart-message {
  display: grid;
  place-items: center;
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.history-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.history-table-wrap { overflow-x: auto; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); background: var(--surface-muted); font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { color: var(--muted); text-align: center; }

.history-delete {
  min-height: 30px;
  padding: 6px 9px;
  color: var(--coral);
  background: transparent;
  border: 1px solid #e3b3aa;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 700;
}

.history-delete:hover:not(:disabled) { background: var(--coral-soft); }
.history-delete:disabled { cursor: not-allowed; opacity: .5; }

@media (max-width: 1200px) {
  .topbar { padding-inline: 24px; }
  .summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 1fr; }
  .import-panel {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    column-gap: 22px;
    row-gap: 12px;
  }
  .import-panel .section-heading { grid-column: 1; grid-row: 1; }
  .import-panel form { grid-column: 2; grid-row: 1; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
  .import-panel .file-status, .import-panel .import-actions { grid-column: 1 / -1; }
  .import-panel .template-link, .import-panel .import-result { grid-column: 2; }
}

@media (max-width: 900px) {
  .topbar { padding-inline: 20px; }
  .dashboard-content { grid-template-columns: 1fr; }
  .chart-section:first-child { grid-column: auto; }
  .import-panel { display: block; }
  .import-panel .section-heading { margin-bottom: 14px; }
  .import-panel form { display: grid; }
  .import-panel .template-link, .import-panel .import-result { display: block; }
}

@media (max-width: 640px) {
  .topbar { min-height: 0; align-items: flex-start; padding: 13px 16px; }
  .brand { gap: 10px; }
  .brand-mark { width: 25px; height: 25px; flex: 0 0 auto; }
  .status-wrap { padding-top: 3px; font-size: 12px; }
  main { padding: 16px 14px 32px; }
  .filter-band { align-items: stretch; }
  .filter-band label, .filter-band select, .filter-band .button { width: 100%; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
  .metric-card { min-height: 108px; padding: 13px; }
  .metric-card strong { font-size: 20px; }
  .workspace, .dashboard-content { gap: 16px; }
  .chart { height: 230px; }
  .section-heading { padding-inline: 14px; }
  .import-panel { padding: 16px; }
  .import-actions { gap: 7px; }
  th, td { padding: 11px 12px; }
}

@media (max-width: 420px) {
  .topbar { gap: 12px; }
  .status-wrap span:last-child { display: none; }
  .summary { grid-template-columns: 1fr; }
  .import-actions { grid-template-columns: 1fr; }
  .button { width: 100%; }
}
