:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #191f28;
  --muted: #6b7684;
  --line: #e5e8eb;
  --blue: #3182f6;
  --blue-dark: #1b64da;
  --blue-soft: #e8f3ff;
  --green: #00a67e;
  --green-soft: #e8faf4;
  --red: #e42939;
  --red-soft: #fff0f1;
  --amber: #f59f00;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); min-height: 100vh; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.shell { width: min(100%, 680px); margin: 0 auto; padding: env(safe-area-inset-top) 18px calc(40px + env(safe-area-inset-bottom)); }
.topbar { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; color: #fff; background: linear-gradient(145deg, #56a1ff, #246fe5); font-size: 20px; font-weight: 800; box-shadow: 0 5px 14px rgba(49,130,246,.25); }
.brand h1 { margin: 0; font-size: 16px; line-height: 1.35; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 12px; }
.pill { flex: none; padding: 7px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.online { color: #087f5b; background: var(--green-soft); }
.pill.offline { color: #b42332; background: var(--red-soft); }
.pill.neutral { color: var(--muted); background: #e9edf1; }

.card { border: 1px solid rgba(229,232,235,.85); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.pairing-view { min-height: calc(100vh - 110px); display: grid; align-items: center; padding: 24px 0 80px; }
.pairing-card { padding: 34px 26px 28px; text-align: center; }
.lock-mark { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 20px; border-radius: 18px; color: var(--blue); background: var(--blue-soft); font-size: 25px; font-weight: 800; }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .04em; }
h2 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.pair-help { margin: 14px auto 26px; max-width: 420px; line-height: 1.65; }
.muted { color: var(--muted); }
label { display: block; margin: 0 0 8px; text-align: left; font-size: 13px; font-weight: 700; }
input { width: 100%; height: 56px; padding: 0 16px; border: 1.5px solid #d7dce1; border-radius: 14px; outline: none; color: var(--text); background: #fbfcfd; font-size: 20px; font-weight: 750; letter-spacing: .08em; text-align: center; text-transform: uppercase; }
input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(49,130,246,.11); background: #fff; }
.field-error { min-height: 20px; margin: 7px 0 3px; color: var(--red); font-size: 12px; text-align: left; }
.security-copy { margin: 18px 0 0; color: #8b95a1; font-size: 11px; }

.button { min-height: 50px; border: 0; border-radius: 14px; padding: 0 18px; cursor: pointer; font-weight: 750; transition: transform .12s ease, background .12s ease, opacity .12s ease; }
.button:active:not(:disabled) { transform: scale(.985); }
.button:disabled, .segment:disabled, .switch:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { color: #fff; background: var(--blue); }
.button.primary:hover:not(:disabled) { background: var(--blue-dark); }
.button.secondary { color: #333d4b; background: #e9edf1; }
.button.danger-outline { margin-top: 10px; color: var(--red); background: var(--red-soft); }
.button.danger { color: #fff; background: var(--red); }
.button.wide { width: 100%; }
.button-icon { display: inline-block; min-width: 20px; margin-right: 4px; }

.status-card { margin-top: 9px; padding: 24px; }
.status-heading { display: flex; align-items: center; justify-content: space-between; }
.status-dot { width: 13px; height: 13px; border-radius: 50%; box-shadow: 0 0 0 7px #edf0f2; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 7px var(--green-soft); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 7px var(--red-soft); }
.status-dot.neutral { background: #b0b8c1; }
#device-message { margin: 9px 0 21px; min-height: 21px; font-size: 14px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.metrics div { min-width: 0; padding: 12px 7px; border-radius: 13px; background: #f6f8fa; text-align: center; }
.metrics dt { color: var(--muted); font-size: 11px; }
.metrics dd { overflow: hidden; margin: 4px 0 0; font-size: 13px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.last-seen { margin: 14px 0 -4px; color: #8b95a1; font-size: 11px; text-align: right; }

.section { margin-top: 34px; }
.section-title-row { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section > h2 { margin-bottom: 12px; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.offline-help { margin: 10px 2px 0; color: var(--red); font-size: 12px; line-height: 1.5; }
.setting-card { margin-bottom: 10px; padding: 19px; }
.setting-card.horizontal { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.setting-copy h3 { margin: 0; font-size: 15px; }
.setting-copy p { margin: 4px 0 15px; color: var(--muted); font-size: 12px; }
.setting-card.horizontal .setting-copy p { margin-bottom: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: #f0f2f4; }
.segmented.thirds { grid-template-columns: repeat(3, 1fr); }
.segment { height: 40px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; font-weight: 700; }
.segment.active { color: var(--blue); background: #fff; box-shadow: 0 2px 7px rgba(0,0,0,.06); }
.switch { position: relative; flex: none; width: 51px; height: 30px; padding: 0; border: 0; border-radius: 999px; cursor: pointer; background: #c9d0d8; transition: background .18s ease; }
.switch-knob { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.18); transition: transform .18s ease; }
.switch[aria-checked="true"] { background: var(--blue); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(21px); }

.legend { color: #8b95a1; font-size: 11px; }
.history-card { padding: 6px 18px; }
.command-list { margin: 0; padding: 0; list-style: none; }
.command-row { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 16px 0; border-bottom: 1px solid #edf0f2; }
.command-row:last-child { border-bottom: 0; }
.command-name { margin: 0; font-size: 14px; font-weight: 750; }
.command-detail { grid-column: 1; margin: 0; color: var(--muted); font-size: 11px; }
.command-time { grid-column: 1; margin: 1px 0 0; color: #a1a9b2; font-size: 10px; }
.command-badge { grid-column: 2; grid-row: 1 / span 2; align-self: center; padding: 6px 9px; border-radius: 999px; background: #edf0f2; color: var(--muted); font-size: 11px; font-weight: 750; }
.command-badge.queued { color: #1967d2; background: var(--blue-soft); }
.command-badge.delivered { color: #8a5a00; background: #fff4d6; }
.command-badge.applied { color: #087f5b; background: var(--green-soft); }
.command-badge.failed, .command-badge.expired { color: #b42332; background: var(--red-soft); }
.empty { margin: 0; padding: 26px 0; color: var(--muted); text-align: center; font-size: 13px; }

footer { padding: 34px 0 0; text-align: center; }
footer p { margin: 9px 0 0; color: #a1a9b2; font-size: 10px; }
.text-button { border: 0; padding: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.toast { position: fixed; z-index: 10; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100vw - 36px); padding: 12px 17px; border-radius: 12px; color: #fff; background: rgba(25,31,40,.93); box-shadow: 0 8px 30px rgba(0,0,0,.2); font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dialog { width: min(400px, calc(100vw - 36px)); padding: 28px; border: 0; border-radius: 22px; box-shadow: 0 18px 60px rgba(0,0,0,.2); text-align: center; }
.dialog::backdrop { background: rgba(25,31,40,.45); backdrop-filter: blur(2px); }
.dialog-mark { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 15px; border-radius: 16px; color: var(--red); background: var(--red-soft); font-size: 24px; font-weight: 800; }
.dialog p { margin: 10px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

@media (min-width: 700px) {
  .shell { padding-left: 0; padding-right: 0; }
  .topbar { min-height: 90px; }
  .status-card { padding: 28px; }
}

@media (max-width: 390px) {
  .shell { padding-left: 14px; padding-right: 14px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .pairing-card { padding-left: 20px; padding-right: 20px; }
}

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