:root {
  --ink: #142036;
  --muted: #5d6a80;
  --faint: #8a95a8;
  --line: #e3e8f0;
  --bg: #f3f5f9;
  --card: #fff;
  --accent: #2457d6;
  --accent-soft: #e8eefc;
  --green: #0d7a53;
  --green-soft: #e5f5ed;
  --amber: #a3500e;
  --amber-soft: #fcefe2;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 54, .05);
  --shadow-md: 0 10px 30px -12px rgba(20, 32, 54, .22), 0 2px 6px rgba(20, 32, 54, .05);
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, "Roboto Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(1100px 420px at 50% -160px, rgba(36, 87, 214, .13), transparent 70%),
    var(--bg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

.login-view {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px 16px;
}
.login-form {
  display: grid;
  gap: 14px;
  width: min(100%, 380px);
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-md);
}
.login-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}
.login-mark svg { width: 21px; height: 21px; }
.login-form h1 { margin: 0 0 4px; font-size: 22px; line-height: 1.25; }
.login-field { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 600; }
.login-field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #cdd6e4;
  border-radius: 9px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
}
.login-field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { min-height: 1.5em; margin: -7px 0 -7px; color: #a42525; font-size: 13px; }
.login-submit {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.login-submit:hover:not(:disabled) { background: #1f49b8; }
.login-submit:disabled { opacity: .62; cursor: default; }

.wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Top bar */
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 22px;
  padding-bottom: 8px;
}

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

.logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(140deg, #3b7bff 0%, #2457d6 55%, #1b3fa8 100%);
  box-shadow: 0 6px 16px -6px rgba(36, 87, 214, .6), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.logo svg { width: 22px; height: 22px; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 18px; line-height: 1.25; letter-spacing: .01em; }
.brand-text span { font-size: 12.5px; color: var(--muted); }

.sync { display: flex; align-items: center; gap: 8px; }

.fresh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, .8);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #19a974;
  box-shadow: 0 0 0 3px rgba(25, 169, 116, .18);
}
.dot.warn { background: #e08a2c; box-shadow: 0 0 0 3px rgba(224, 138, 44, .2); }
.dot.wait { background: #b3bccb; box-shadow: 0 0 0 3px rgba(179, 188, 203, .25); }

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  box-shadow: var(--shadow-sm);
  transition: color .15s, border-color .15s, background .15s;
}
.icon-button:hover { color: var(--accent); border-color: #c9d6f4; background: var(--accent-soft); }
.icon-button:disabled { cursor: default; }
.icon-button[aria-busy="true"] svg { animation: spin .9s linear infinite; color: var(--accent); }

@keyframes spin { to { transform: rotate(360deg); } }

/* Search */
.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 26px 0 18px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px -14px rgba(20, 32, 54, .25), var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
  cursor: text;
}
.search:focus-within {
  border-color: #9db5ee;
  box-shadow: 0 0 0 4px rgba(36, 87, 214, .12), 0 8px 24px -14px rgba(20, 32, 54, .25);
}
.search-icon { position: absolute; left: 18px; width: 20px; height: 20px; color: var(--faint); pointer-events: none; }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 12px 0 50px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
}
.search input::placeholder { color: #9aa4b5; }
.search input::-webkit-search-cancel-button,
.search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

.clear {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: 12px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #eef1f6;
  color: var(--muted);
}
.clear:hover { background: #e2e7ef; color: var(--ink); }
.clear svg { width: 15px; height: 15px; }

kbd {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  margin-right: 16px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 7px;
  background: #f7f9fc;
  color: var(--faint);
  font: 600 13px var(--mono);
}

.summary {
  display: flex;
  align-items: baseline;
  gap: 6px;
  height: 56px;
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .75);
  white-space: nowrap;
  line-height: 56px;
  box-shadow: var(--shadow-sm);
}
.summary-label, .summary-unit { color: var(--muted); font-size: 13px; }
.summary strong { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* Warning */
.warning {
  margin: 0 0 14px;
  padding: 11px 16px;
  border: 1px solid #f3d3b2;
  border-radius: 12px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 14px;
}

/* Toolbar */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -24px 16px;
  padding: 10px 24px;
  background: rgba(243, 245, 249, .86);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  backdrop-filter: saturate(1.6) blur(12px);
}

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  min-width: 0;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #e9edf4;
}
.tabs button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(20, 32, 54, .12); }

.badge {
  min-width: 30px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(20, 32, 54, .07);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tabs button[aria-pressed="true"] .badge { background: var(--accent-soft); color: var(--accent); }

.toolbar-end { display: flex; align-items: center; gap: 14px; }
.count { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.count b { color: var(--ink); font-variant-numeric: tabular-nums; }

.select { position: relative; display: flex; align-items: center; }
.select svg { position: absolute; pointer-events: none; color: var(--faint); }
.select-icon { left: 12px; width: 16px; height: 16px; }
.chevron { right: 10px; width: 16px; height: 16px; }
.select select {
  height: 40px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: 0;
  background: #fff;
  font-size: 14px;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.select select:focus-visible { border-color: #9db5ee; box-shadow: 0 0 0 3px rgba(36, 87, 214, .14); }

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 10px;
  padding: 16px 16px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover { transform: translateY(-2px); border-color: #d3dbe8; box-shadow: var(--shadow-md); }

.card-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }

.code {
  flex: none;
  max-width: 42%;
  overflow: hidden;
  padding: 3px 9px;
  border-radius: 8px;
  background: #eef2f8;
  color: #2b3a55;
  font: 600 13px/1.4 var(--mono);
  letter-spacing: .02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 8px;
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.metric { min-width: 0; }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.metric-total { text-align: right; }
.metric-cost {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.metric-cost .metric-value { margin: 0; font-size: 15px; text-align: right; }
.metric-missing .metric-value { color: var(--muted); font-size: 12px; font-weight: 500; }
.cost-note { margin-inline-start: 4px; color: var(--amber); font-size: 11px; white-space: nowrap; }
.card.is-out { background: #fdfcfb; }
.card.is-out .metric-available .metric-value { color: var(--amber); }

mark { padding: 0 1px; border-radius: 3px; background: #ffe7a3; color: inherit; }

/* Skeleton */
.card.skeleton { pointer-events: none; }
.card.skeleton:hover { transform: none; box-shadow: var(--shadow-sm); }
.bone {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef1f6 0%, #f8f9fc 45%, #eef1f6 90%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.bone.heading-bone { width: 72%; height: 24px; }
.bone.metrics-bone { height: 84px; }

@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Empty */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 64px 20px;
  border: 1px dashed #d5dce7;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .6);
  color: var(--muted);
  text-align: center;
}
.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 6px;
  border-radius: 16px;
  background: #e9edf4;
  color: var(--faint);
}
.empty-icon svg { width: 26px; height: 26px; }
.empty strong { color: var(--ink); font-size: 16px; }
.empty span:last-child { font-size: 13.5px; }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 20px;
  margin-top: 36px;
  padding: 18px 0 32px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12.5px;
}

@media (hover: none) {
  kbd { display: none; }
  .card:hover { transform: none; box-shadow: var(--shadow-sm); border-color: var(--line); }
}

@media (max-width: 860px) {
  .hero { flex-direction: column-reverse; align-items: stretch; gap: 12px; }
  .summary { height: auto; padding: 0; border: 0; background: none; box-shadow: none; line-height: 1.4; }
  .summary strong { font-size: 20px; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .wrap { padding: 0 16px; }
  .topbar-row { flex-wrap: wrap; row-gap: 8px; padding-top: max(16px, env(safe-area-inset-top)); }
  .logo { width: 36px; height: 36px; border-radius: 11px; }
  .brand-text span { display: none; }
  .fresh { height: 34px; padding: 0 12px; font-size: 12.5px; }
  .icon-button { width: 34px; height: 34px; }
  .hero { padding: 16px 0 12px; }
  .search { height: 52px; border-radius: 14px; }
  kbd { display: none; }

  .toolbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 0 0 12px;
    padding: 0;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
  .tabs button { justify-content: center; padding: 0 8px; }
  .toolbar-end { justify-content: space-between; }
  .select select { height: 36px; }

  .grid { grid-template-columns: 1fr; gap: 8px; }
  .card {
    gap: 8px;
    padding: 12px 14px;
    border-radius: 12px;
  }
  .card:hover { transform: none; }
  .name { font-size: 14px; }
  .metric-value { font-size: 20px; }
  footer { flex-direction: column; margin-top: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
