:root {
  --red: #d70015;
  --red-dark: #b80012;
  --ink: #17202c;
  --muted: #687384;
  --line: #dfe3e8;
  --soft: #f5f7f9;
  --blue-soft: #eef5ff;
  --blue: #245da8;
  --green: #15803d;
  --danger-soft: #fff0f1;
  --shadow: 0 8px 30px rgba(25, 33, 45, 0.06);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

button, input, select { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--red);
  border-radius: 5px;
  font-size: 22px;
  font-weight: 800;
  font-style: italic;
}

.text-button {
  padding: 8px 4px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.text-button:hover { color: var(--red); }

.account-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.account-actions form { margin: 0; }

.account-name {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.app-shell {
  min-height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.sidebar nav { display: grid; gap: 6px; }

.sidebar nav a {
  position: relative;
  padding: 12px 14px;
  border-radius: 7px;
  color: #344050;
  font-weight: 600;
  text-decoration: none;
}

.sidebar nav a:hover { background: var(--soft); }

.sidebar nav a.active {
  color: var(--red);
  background: #fff4f5;
}

.sidebar nav a.active::before {
  position: absolute;
  inset: 9px auto 9px -18px;
  width: 3px;
  content: "";
  background: var(--red);
}

.sidebar-note {
  margin: auto 4px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.content {
  width: 100%;
  max-width: 1500px;
  padding: 30px 34px 48px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

h1 {
  margin-bottom: 4px;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 12px;
  font-size: 17px;
}

.page-heading p, .muted { color: var(--muted); }

.filters {
  display: grid;
  grid-template-columns:
    minmax(160px, 1.2fr)
    minmax(136px, 0.8fr)
    minmax(136px, 0.8fr)
    minmax(228px, auto)
    96px;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

label, legend {
  color: #3f4a59;
  font-size: 13px;
  font-weight: 650;
}

input, select {
  width: 100%;
  height: 42px;
  margin-top: 7px;
  padding: 0 12px;
  border: 1px solid #cbd2da;
  border-radius: 6px;
  outline: none;
  color: var(--ink);
  background: #fff;
}

input:focus, select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(215, 0, 21, 0.1);
}

.granularity {
  display: flex;
  min-width: 228px;
  margin: 0;
  padding: 0;
  border: 0;
}

.granularity legend { margin-bottom: 7px; }

.granularity label { flex: 1; }

.granularity input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.granularity span {
  display: grid;
  height: 42px;
  place-items: center;
  border: 1px solid #cbd2da;
  border-left: 0;
  color: #3f4a59;
  background: #fff;
  cursor: pointer;
}

.granularity label:first-of-type span {
  border-left: 1px solid #cbd2da;
  border-radius: 6px 0 0 6px;
}

.granularity label:last-of-type span { border-radius: 0 6px 6px 0; }

.granularity input:checked + span {
  border-color: var(--red);
  color: #fff;
  background: var(--red);
}

.primary-button, .secondary-button, .danger-button {
  min-height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--red);
  color: #fff;
  background: var(--red);
}

.primary-button:hover { background: var(--red-dark); }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.primary-button.full { width: 100%; }

.secondary-button {
  border: 1px solid #bfc7d0;
  color: #303b49;
  background: #fff;
}

.danger-button {
  border: 1px solid #edb7bd;
  color: #b11124;
  background: var(--danger-soft);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-strip article {
  min-height: 134px;
  padding: 22px;
  border-right: 1px solid var(--line);
}

.metric-strip article:last-child { border-right: 0; }
.metric-strip p { margin-bottom: 8px; color: #566171; font-weight: 650; }
.metric-strip strong { display: block; color: var(--red); font-size: 25px; }
.metric-strip small { color: var(--muted); }

.panel {
  margin-bottom: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.panel-heading {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 { margin: 0; }

.export-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.export-toolbar > div:first-child { display: grid; }
.export-toolbar span { color: var(--muted); font-size: 12px; }
.export-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.legend { display: flex; gap: 24px; color: var(--muted); font-size: 13px; }
.legend span::before {
  width: 24px;
  height: 3px;
  display: inline-block;
  margin: 0 8px 3px 0;
  content: "";
  background: var(--red);
}
.legend .web-line::before { background: #657181; }

.chart { min-height: 300px; padding: 8px 12px 2px; }
.chart svg { width: 100%; height: 300px; overflow: visible; }
.chart-empty {
  display: grid;
  min-height: 280px;
  margin: 0;
  place-items: center;
  color: var(--muted);
}
.grid-line { stroke: #e4e8ed; stroke-dasharray: 4 4; }
.axis-label { fill: #687384; font-size: 11px; }
.file-path, .web-path { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.file-path { stroke: var(--red); }
.web-path { stroke: #657181; }

.table-wrap { width: 100%; overflow: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 11px 16px;
  border-bottom: 1px solid #e7eaee;
  text-align: left;
  white-space: nowrap;
}

th { color: #4a5564; background: #fafbfc; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }

.freshness-note {
  padding: 12px 16px;
  border: 1px solid #bdd3f6;
  border-radius: 6px;
  color: var(--blue);
  background: var(--blue-soft);
  font-size: 13px;
}

.flash {
  margin-bottom: 18px;
  padding: 11px 14px;
  border: 1px solid #bad7c3;
  border-radius: 6px;
  color: var(--green);
  background: #effaf2;
}

.flash.error {
  border-color: #efbdc3;
  color: #a20e20;
  background: var(--danger-soft);
}

.range-notice {
  margin: 0 0 20px;
  padding: 13px 16px;
  border: 1px solid #f1cf75;
  border-radius: 7px;
  color: #744c00;
  background: #fff9e8;
  font-weight: 600;
}

.hidden { display: none !important; }

.form-panel summary, .customer-item summary {
  padding: 16px 18px;
  font-weight: 750;
  cursor: pointer;
}

.customer-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
  border-top: 1px solid var(--line);
}

.customer-form .primary-button { align-self: end; justify-self: start; }

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  color: #3f4a59;
}

.check-row input {
  width: 17px;
  height: 17px;
  margin: 0;
}

.customer-list { display: grid; gap: 12px; }
.customer-item { margin: 0; }
.customer-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.customer-item summary span:first-child { display: grid; }
.customer-item summary small { color: var(--muted); font-weight: 500; }
.credential-state { color: var(--muted); font-size: 12px; font-weight: 500; }

.item-actions {
  display: flex;
  gap: 10px;
  padding: 0 18px 18px;
}

.status {
  padding: 3px 8px;
  border-radius: 99px;
  color: #45505e;
  background: #edf0f3;
  font-size: 12px;
  font-weight: 700;
}
.status.success { color: var(--green); background: #eaf7ed; }
.status.failed { color: #a20e20; background: var(--danger-soft); }
.status.running { color: #875c00; background: #fff6d8; }
.error-cell { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }

.narrow-panel { max-width: 560px; padding: 22px; }
.stack-form { display: grid; gap: 16px; }
.stack-form .primary-button { justify-self: start; }
.login-panel .stack-form .primary-button { justify-self: stretch; }

.empty-state {
  max-width: 620px;
  padding: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  background: var(--soft);
}

.login-page {
  position: relative;
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 32px;
}

.data-lines {
  position: absolute;
  inset: 0 62% 0 0;
  opacity: 0.8;
  background:
    radial-gradient(circle at 28% 24%, var(--red) 0 3px, transparent 4px),
    radial-gradient(circle at 42% 58%, #cbd2da 0 4px, transparent 5px),
    radial-gradient(circle at 14% 74%, var(--red) 0 3px, transparent 4px),
    repeating-radial-gradient(ellipse at -10% 60%, transparent 0 22px, #e3e7eb 23px 24px, transparent 25px 36px);
}

.login-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 500px);
  padding: 42px 44px 34px;
  border: 1px solid #cdd3da;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

.login-panel h1 { margin-bottom: 22px; text-align: center; font-size: 34px; }
.login-panel h2 { margin-bottom: 24px; text-align: center; font-size: 22px; }
.security-note { margin: 26px 0 0; color: #4d5866; text-align: center; }

@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .granularity { min-width: 0; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip article:nth-child(2) { border-right: 0; }
  .metric-strip article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 16px; }
  .brand { gap: 9px; font-size: 17px; }
  .brand-mark { width: 32px; height: 32px; }
  .app-shell { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 8px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar nav { display: flex; min-width: max-content; }
  .sidebar nav a { padding: 9px 12px; font-size: 13px; }
  .sidebar nav a.active::before, .sidebar-note { display: none; }
  .content { padding: 22px 16px 36px; }
  .filters, .customer-form { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: 1fr; }
  .metric-strip article { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-strip article:last-child { border-bottom: 0; }
  .export-toolbar { align-items: stretch; flex-direction: column; }
  .export-actions { display: grid; }
  .legend { display: none; }
  .customer-item summary { align-items: start; flex-direction: column; }
  .item-actions { align-items: stretch; flex-direction: column; }
  .item-actions button { width: 100%; }
  .login-page { align-items: start; padding: 40px 16px; }
  .data-lines { inset: auto 0 0; height: 35%; }
  .login-panel { padding: 32px 24px; }
  .login-panel h1 { font-size: 27px; }
}
