:root {
  --bg: #f3f4f6; --card: #ffffff; --text: #1d2433; --muted: #5d6778; --border: #d6dbe3;
  --accent: #1f5fbf; --accent-text: #ffffff; --ok: #1b7f3b; --ok-bg: #e5f4ea;
  --bad: #b42318; --bad-bg: #fde8e6; --warn: #8a5300; --warn-bg: #fdf1dc;
  --info: #1f5fbf; --info-bg: #e7effb; --field: #f8f9fb; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --card: #1b212b; --text: #e6e9ef; --muted: #9aa4b5; --border: #2c3442;
    --accent: #4c8ff0; --accent-text: #0b1220; --ok: #4cc27a; --ok-bg: #16301f;
    --bad: #ff7b72; --bad-bg: #3a1a19; --warn: #e3a64a; --warn-bg: #352812;
    --info: #79a8f5; --info-bg: #182a45; --field: #151a22; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }

header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
#title { flex: 1; font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { max-width: 640px; margin: 0 auto; padding: 12px calc(16px + env(safe-area-inset-right)) 32px calc(16px + env(safe-area-inset-left)); }

button { font: inherit; cursor: pointer; }
.icon { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--accent); font-size: 32px; line-height: 1; padding: 0 4px; }
.chip { min-height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 18px; background: var(--card); color: var(--text); font-size: 14px; }
.btn { display: block; width: 100%; min-height: 48px; border: 0; border-radius: 10px; font-weight: 600; font-size: 17px; background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--border); }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow); }
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 20px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.err { color: var(--bad); white-space: pre-wrap; }

label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
input, textarea, select {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px; color: var(--text);
  background: var(--field); border: 1px solid var(--border); border-radius: 10px; -webkit-appearance: none; appearance: none;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
input.code { font-size: 26px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
input.upper { text-transform: uppercase; }

.search { position: sticky; top: calc(61px + env(safe-area-inset-top)); z-index: 4; background: var(--bg); padding: 4px 0 8px; }
.search input { background: var(--card); }

.item { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
        padding: 12px 14px; margin: 0 0 8px; color: var(--text); box-shadow: var(--shadow); }
.item:active { background: var(--field); }
.item .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.item .sub { color: var(--muted); font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .why { font-size: 14px; margin-top: 6px; color: var(--bad); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 13px; font-weight: 600; white-space: nowrap; background: var(--field); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--info-bg); color: var(--info); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); flex: 0 0 auto; }
.kv span:last-child { text-align: right; word-break: break-all; font-variant-numeric: tabular-nums; }

.status-big { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.status-big.ok { color: var(--ok); } .status-big.bad { color: var(--bad); } .status-big.warn { color: var(--warn); } .status-big.info { color: var(--info); }
.reason { white-space: pre-wrap; font-size: 14px; background: var(--bad-bg); color: var(--text); border-radius: 8px; padding: 10px; margin-top: 8px; }

.event { padding: 8px 0; border-bottom: 1px solid var(--border); }
.event:last-child { border-bottom: 0; }
.event .when { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.event .what { font-weight: 600; }
.event .det { font-size: 14px; white-space: pre-wrap; color: var(--muted); word-break: break-word; }

.finding { padding: 8px 10px; border-radius: 8px; margin: 6px 0; font-size: 14px; white-space: pre-wrap; }
.finding.Error { background: var(--bad-bg); color: var(--bad); }
.finding.Warning { background: var(--warn-bg); color: var(--warn); }
.finding.Info { background: var(--info-bg); color: var(--info); }
.check { display: flex; align-items: flex-start; gap: 10px; margin: 12px 0; font-size: 15px; color: var(--text); font-weight: 400; }
.check input { width: 24px; min-height: 24px; height: 24px; flex: 0 0 24px; -webkit-appearance: checkbox; appearance: auto; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 6px; }
.seg button { flex: 1; min-height: 44px; border: 0; background: var(--card); color: var(--text); font-weight: 600; }
.seg button.on { background: var(--accent); color: var(--accent-text); }

.key { font: 600 18px/1.4 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .05em; word-break: break-all; background: var(--field); border-radius: 8px; padding: 10px; text-align: center; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin: 6px 0; }

.banner { background: var(--warn-bg); color: var(--warn); padding: 10px 16px; font-size: 14px; text-align: center; }

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20; max-width: 560px; margin: 0 auto;
         background: var(--text); color: var(--bg); border-radius: 12px; padding: 12px 16px; font-size: 15px; text-align: center; white-space: pre-wrap; }
#sheet-wrap { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
#sheet { width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; background: var(--bg); border-radius: 16px 16px 0 0;
         padding: 16px calc(16px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
#sheet h3 { margin: 4px 0 8px; font-size: 18px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; margin: 24px auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
select { padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23808a9a' stroke-width='2'/%3E%3C/svg%3E");
         background-repeat: no-repeat; background-position: right 14px center; }
