:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #555555;
  --hairline: #000000;
  --bar-track: #f0f0f0;
  --bar-fill: #000000;
  --danger-fg: #000000;
  --card-bg: #ffffff;
  --hover-bg: #f5f5f5;
  /* Semantic colors for bar fill by usage level */
  --ok: #10b981;       /* emerald-500  0-74%  */
  --warn: #f59e0b;     /* amber-500   75-89% */
  --danger: #ef4444;   /* red-500     90-100% */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --muted: #555555;
    --hairline: #000000;
    --bar-track: #f0f0f0;
    --bar-fill: #000000;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: contain;
}

button { font-family: inherit; }
.mono { font-family: "SF Mono", "JetBrains Mono", "Menlo", "Consolas", "Roboto Mono", monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ===== Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 2px solid var(--hairline);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.topbar .actions { display: flex; gap: 8px; }

.icon-btn {
  background: transparent;
  border: 1.5px solid var(--hairline);
  color: var(--fg);
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--hover-bg); }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.cards {
  flex: 1;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card-bg);
  border: 2px solid var(--hairline);
  border-radius: 0;
  padding: 16px 16px 18px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1.5px solid var(--hairline);
}
.card-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.3px;
}
.status-dot {
  width: 14px;
  height: 14px;
  border: 2px solid var(--hairline);
  background: transparent;
  display: inline-block;
}
.status-dot.ok    { background: var(--ok); border-color: var(--ok); }
.status-dot.warn  { background: var(--warn); border-color: var(--warn); }
.status-dot.err   { background: var(--danger); border-color: var(--danger); border-style: dashed; }

.metric { padding: 10px 0; }
.metric + .metric { border-top: 1px dashed var(--hairline); margin-top: 6px; padding-top: 14px; }

.metric-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.metric-row.sub { margin-top: 6px; font-size: 13px; }
.metric-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
}
.metric-pct {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
}
.pct-value {
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
}
.pct-unit {
  font-size: 16px;
  margin-left: 2px;
  color: var(--muted);
}
.metric-sub { font-size: 13px; }

.bar {
  margin-top: 10px;
  height: 14px;
  background: var(--bar-track);
  border: 1.5px solid var(--hairline);
  position: relative;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--ok);
  transition: width 0.4s ease-out, background-color 0.3s ease;
}
.bar-fill.warn   { background: var(--warn); }
.bar-fill.danger { background: var(--danger); }

.card-error {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1.5px dashed var(--hairline);
  font-size: 13px;
  color: var(--danger-fg);
  background: var(--bg);
  word-break: break-word;
}

.statusbar {
  border-top: 2px solid var(--hairline);
  padding: 10px 18px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  font-size: 12px;
  background: var(--bg);
}
.status-line { display: inline-flex; gap: 6px; align-items: center; }
.status-line .mono { font-size: 12px; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 18px;
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 480px;
  border: 2px solid var(--hairline);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  max-height: 90dvh;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 2px solid var(--hairline);
}
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-foot {
  padding: 12px 16px;
  border-top: 2px solid var(--hairline);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-hint code { background: var(--bar-track); padding: 1px 4px; font-family: "SF Mono", monospace; }
.field input[type=password],
.field input[type=text],
.field select {
  font-family: inherit;
  font-size: 15px;
  border: 1.5px solid var(--hairline);
  background: var(--bg);
  color: var(--fg);
  padding: 10px 12px;
  border-radius: 0;
  outline: none;
  width: 100%;
  appearance: none;
}
.field input:focus, .field select:focus { box-shadow: inset 0 0 0 2px var(--fg); }
.field select { padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--fg) 50%), linear-gradient(135deg, var(--fg) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; }
.field input[type=checkbox] {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--hairline);
  background: var(--bg);
  cursor: pointer;
  vertical-align: middle;
  margin-right: 8px;
  position: relative;
  top: -2px;
}
.field input[type=checkbox]:checked {
  background: var(--fg);
}
.field input[type=checkbox]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 0px;
  width: 5px;
  height: 10px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  border: 1.5px solid var(--hairline);
  background: var(--bg);
  color: var(--fg);
  padding: 9px 18px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
}
.btn:active { background: var(--hover-bg); }
.btn.primary { background: var(--fg); color: var(--bg); }
.btn.primary:active { background: var(--muted); }
.btn.ghost { background: transparent; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  z-index: 30;
  border: 1.5px solid var(--fg);
  pointer-events: none;
}
.toast[hidden] { display: none; }

/* ===== Pull-to-refresh indicator ===== */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--fg);
  transform-origin: 0 50%;
  transform: scaleX(0);
  transition: transform 0.1s linear;
  z-index: 50;
  pointer-events: none;
}

/* ===== Sleep when no data ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
}

/* ===== Small screens ===== */
@media (max-width: 380px) {
  .pct-value { font-size: 32px; }
  .topbar .title { font-size: 17px; }
}
