:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d7dde5;
  --text: #17202a;
  --muted: #667085;
  --green: #178c5f;
  --blue: #2f6fed;
  --amber: #c47a16;
  --red: #c23b3b;
  --ink: #263238;
  --chart-volume: #9bd8be;
  --chart-nhe: #f0aaa6;
  --chart-cadence: #f2cc86;
  --chart-average: #536b80;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.pill {
  height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
}

button.pill {
  cursor: pointer;
}

.period-form {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 4px;
}

.period-label,
.period-separator {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.period-label {
  font-weight: 700;
  padding-left: 6px;
}

.period-form input {
  height: 30px;
  width: 132px;
  border: 1px solid #e3e9f1;
  border-radius: 5px;
  color: var(--text);
  font: 13px Inter, Arial, sans-serif;
  padding: 5px 7px;
}

.period-form .pill {
  height: 30px;
  padding: 6px 9px;
}

.action {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

main {
  padding: 18px 22px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
}

.auth-shell {
  min-height: calc(100vh - 69px);
  display: grid;
  place-items: center;
  padding: 22px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 12px 32px rgba(23, 32, 42, .08);
}

.auth-card h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

.auth-card label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.auth-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.auth-row input {
  height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: 14px Inter, Arial, sans-serif;
  padding: 8px 10px;
}

.auth-row button:disabled {
  opacity: .72;
  cursor: wait;
}

.auth-error {
  min-height: 16px;
  color: var(--red);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 9px;
}

.content {
  display: grid;
  gap: 14px;
  min-width: 0;
}

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

.card,
.panel,
aside {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.card {
  padding: 12px;
  min-height: 86px;
  display: grid;
  align-content: space-between;
}

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

.value {
  font-weight: 800;
  font-size: 22px;
  line-height: 1.15;
  margin-top: 6px;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
}

.blue { color: var(--blue); }
.green { color: var(--green); }
.amber { color: var(--amber); }
.red { color: var(--red); }

.panel {
  padding: 14px;
  min-width: 0;
}

.panel h2,
aside h2 {
  margin: 0 0 12px;
  font-size: 14px;
  letter-spacing: 0;
}

.panel-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-titlebar h2 {
  margin: 0;
}

.copy-button {
  height: 30px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 6px 9px;
  font: 700 12px Inter, Arial, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}

.copy-button:disabled {
  opacity: .7;
  cursor: wait;
}

.chart {
  width: 100%;
  height: 390px;
  display: block;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
}

.green-bg { background: var(--chart-volume); }
.red-bg { background: var(--chart-nhe); }
.amber-bg { background: var(--chart-cadence); }
.blue-bg { background: var(--chart-average); }

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 1100px;
  background: #fff;
}

th,
td {
  padding: 8px 9px;
  border-bottom: 1px solid #e8edf3;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: #475467;
  font-weight: 700;
  z-index: 1;
}

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

tfoot td {
  background: #e2f0d9;
  font-weight: 700;
}

aside {
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.side-metric {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.side-metric:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.bar {
  height: 9px;
  background: #e8edf3;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}

.bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

#barOper {
  background: var(--amber);
}

.mini {
  display: grid;
  gap: 7px;
  font-size: 12px;
}

.mini-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #edf1f5;
  padding-bottom: 6px;
}

.coord-list {
  display: grid;
  gap: 8px;
}

.coord-item {
  border: 1px solid #e3e9f1;
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.coord-empty {
  border: 1px solid #e3e9f1;
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  padding: 10px;
}

.coord-btn {
  width: 100%;
  border: 0;
  background: #f8fafc;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  font: 700 12px Inter, Arial, sans-serif;
  cursor: pointer;
  text-align: left;
}

.coord-btn span:last-child {
  color: var(--muted);
}

.sup-list {
  display: none;
  padding: 7px 10px 9px;
}

.coord-item.open .sup-list {
  display: grid;
  gap: 6px;
}

.sup-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #344054;
  font-size: 12px;
  border-bottom: 1px solid #edf1f5;
  padding-bottom: 5px;
}

.sup-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.coord-note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  margin-top: 6px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip {
  position: fixed;
  min-width: 190px;
  max-width: min(260px, calc(100vw - 16px));
  background: #1f2a35;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 7px;
  box-shadow: 0 12px 28px rgba(23, 32, 42, .22);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
  z-index: 20;
}

.chart-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip strong {
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}

.chart-tooltip div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 3px 0;
  color: rgba(255, 255, 255, .82);
}

.chart-tooltip b {
  color: #fff;
  font-weight: 800;
}

.chart-tooltip .tooltip-total {
  border-top: 1px solid rgba(255, 255, 255, .16);
  margin-top: 4px;
  padding-top: 7px;
}

@media (max-width: 1150px) {
  main { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
}

@media (max-width: 760px) {
  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .filters,
  .period-form {
    width: 100%;
  }

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

  .period-label,
  .period-separator {
    display: none;
  }

  .period-form input {
    width: 100%;
  }

  .period-form .pill {
    grid-column: 1 / -1;
  }

  main { padding: 12px; }
  .cards { grid-template-columns: 1fr; }
}
