:root {
  color-scheme: light;
  --ink: #18211d;
  --muted: #66716b;
  --line: #dce2de;
  --paper: #f7f9f7;
  --surface: #ffffff;
  --green: #16784a;
  --green-soft: #e4f3ea;
  --amber: #9b6100;
  --amber-soft: #fff0cc;
  --red: #b23a3a;
  --red-soft: #fae6e4;
  --cyan: #0b6673;
  --cyan-soft: #dff2f3;
  --shadow: 0 12px 36px rgba(24, 33, 29, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", "Aptos", "PingFang SC", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button, .file-action {
  min-height: 36px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: white;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

button:hover, .file-action:hover { background: var(--green); border-color: var(--green); }
button:active, .file-action:active { transform: translateY(1px); }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.secondary:hover { border-color: var(--ink); }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 12px; height: 34px; background: var(--green); border-radius: 2px; flex: 0 0 auto; }
h1, h2, p { margin: 0; }
h1 { font-family: "Charter", "Songti SC", serif; font-size: 19px; font-weight: 700; }
.brand-block p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.file-action { display: inline-flex; align-items: center; }
.file-action input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

main { width: min(1500px, 100%); margin: 0 auto; padding: 0 28px 40px; }

.stats-overview { background: var(--surface); border-bottom: 1px solid var(--line); }
.stats-toolbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 16px;
}
.stats-toolbar h2 { font-family: "Charter", "Songti SC", serif; font-size: 17px; }
.stats-toolbar p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.range-control {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, auto));
  gap: 1px;
  overflow: hidden;
  flex: 0 0 auto;
  padding: 1px;
  border-radius: 4px;
  background: var(--line);
}
.range-option {
  min-height: 32px;
  padding: 5px 11px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}
.range-option:hover { border: 0; background: #edf2ef; color: var(--ink); }
.range-option.active { background: var(--ink); color: white; }
.range-option.active:hover { background: var(--green); color: white; }

.metrics {
  display: grid;
  grid-template-columns: repeat(8, minmax(100px, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.metrics > div { padding: 18px 16px; border-right: 1px solid var(--line); }
.metrics > div:last-child { border-right: 0; }
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: block; margin-top: 4px; font-family: "Charter", serif; font-size: 24px; line-height: 1; }

.trend-panel { padding: 16px 16px 12px; }
.trend-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.trend-header h3 { margin: 0; font-size: 13px; font-weight: 650; }
.trend-legend { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 12px; }
.trend-legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-line { width: 18px; height: 2px; display: inline-block; background: var(--cyan); }
.legend-line.successful { height: 0; border-top: 2px dashed var(--green); background: transparent; }
.chart-frame { position: relative; width: 100%; min-height: 248px; }
#trendChart { display: block; width: 100%; height: 248px; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}
.chart-empty.visible { display: grid; }
.chart-tooltip {
  position: absolute;
  top: 16px;
  display: none;
  min-width: 138px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 24px rgba(24, 33, 29, 0.12);
  pointer-events: none;
}
.chart-tooltip.visible { display: grid; gap: 4px; }
.chart-tooltip strong { font-size: 12px; }
.chart-tooltip span { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 11px; }
.chart-tooltip b { color: var(--ink); }

.tabs { display: flex; gap: 22px; margin-top: 22px; border-bottom: 1px solid var(--line); }
.tab { min-height: 40px; padding: 8px 2px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tab:hover { background: transparent; border-color: var(--line); color: var(--ink); }
.tab.active { color: var(--ink); border-color: var(--green); font-weight: 650; }

.view { display: none; }
.view.active { display: block; animation: reveal 180ms ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.view-toolbar > div { display: flex; align-items: baseline; gap: 10px; }
.view-toolbar h2 { font-family: "Charter", "Songti SC", serif; font-size: 17px; }
.view-toolbar span { color: var(--muted); font-size: 12px; }
select, input[type="password"], input[type="text"], textarea { border: 1px solid var(--line); border-radius: 4px; background: white; color: var(--ink); padding: 0 10px; }
select, input[type="password"], input[type="text"] { height: 36px; }
textarea { width: 100%; min-height: 92px; padding-block: 9px; resize: vertical; line-height: 1.5; }
select:focus, input:focus { outline: 2px solid rgba(22, 120, 74, 0.22); border-color: var(--green); }
textarea:focus { outline: 2px solid rgba(22, 120, 74, 0.22); border-color: var(--green); }

.table-shell { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #f1f4f2; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfb; }
td { max-width: 340px; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: "SFMono-Regular", "Cascadia Mono", monospace; font-size: 12px; }
.actions-column { width: 248px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { min-height: 30px; padding: 4px 8px; font-size: 12px; }

.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; border-radius: 3px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.badge.available, .badge.completed, .badge.success { color: var(--green); background: var(--green-soft); }
.badge.cooling, .badge.queued, .badge.retrying { color: var(--amber); background: var(--amber-soft); }
.badge.leased, .badge.running { color: var(--cyan); background: var(--cyan-soft); }
.badge.disabled, .badge.invalid, .badge.failed { color: var(--red); background: var(--red-soft); }
.empty-row { height: 120px; text-align: center; color: var(--muted); }

.dialog-backdrop { position: fixed; inset: 0; display: none; place-items: center; padding: 20px; background: rgba(24, 33, 29, 0.52); z-index: 20; }
.dialog-backdrop.visible { display: grid; }
.dialog { width: min(420px, 100%); padding: 24px; border-radius: 6px; background: white; box-shadow: var(--shadow); }
.dialog h2 { margin-bottom: 20px; font-size: 20px; }
.dialog label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.dialog input { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-error { min-height: 18px; margin-top: 8px; color: var(--red); font-size: 12px; }
.account-test-dialog { width: min(540px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; }
.account-test-dialog h2 { margin-bottom: 5px; }
.test-account { margin-bottom: 20px; color: var(--muted); overflow-wrap: anywhere; }
.account-test-dialog label { margin-top: 14px; }
.test-status { min-height: 18px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.test-result[hidden] { display: none; }
.test-result { margin-top: 10px; }
.test-result img { display: block; width: 100%; max-height: 360px; border: 1px solid var(--line); background: #f1f4f2; object-fit: contain; }
.test-meta { padding-top: 8px; color: var(--muted); font-size: 12px; }

.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(420px, calc(100vw - 44px)); padding: 12px 15px; border-radius: 4px; background: var(--ink); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: 160ms ease; z-index: 30; }
.toast.visible { opacity: 1; transform: none; }
.toast.error { background: var(--red); }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; padding: 14px 16px; }
  main { padding: 0 16px 28px; }
  .stats-toolbar { align-items: flex-start; }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .metrics > div:nth-child(4n) { border-right: 0; }
  .metrics > div:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .topbar { flex-direction: column; }
  .header-actions { width: 100%; justify-content: stretch; }
  .header-actions > * { flex: 1; justify-content: center; }
  .stats-toolbar { flex-direction: column; padding: 14px 12px 12px; }
  .range-control { width: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .range-option { padding-inline: 6px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics > div { border-bottom: 1px solid var(--line); }
  .metrics > div:nth-child(2n) { border-right: 0; }
  .tabs { gap: 14px; overflow-x: auto; }
  .view-toolbar { align-items: flex-start; flex-direction: column; padding: 14px 0; }
  .view-toolbar select { width: 100%; }
  .trend-panel { padding-inline: 10px; }
  .trend-header { align-items: flex-start; flex-direction: column; gap: 6px; }
  #trendChart { height: 228px; }
}
