:root {
  color-scheme: light dark;
  --bg: #F4F8FB;
  --surface: #FFFFFF;
  --border: #DDE5EC;
  --text: #14202B;
  --muted: #5E6E7D;
  --accent: #0284C7;
  --accent-text: #FFFFFF;
  --danger: #D93B3B;
  --pin: #D97706;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1B2027;
    --border: #2A313A;
    --text: #E8EDF2;
    --muted: #93A1AE;
    --accent: #38BDF8;
    --accent-text: #06283A;
    --danger: #F06A6A;
    --pin: #FBBF24;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.note { color: var(--accent); }

button, .secondary {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  text-align: center;
}
button:active, .secondary:active { opacity: .7; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.danger { color: var(--danger); }
.icon { border: none; background: none; font-size: 24px; padding: 4px 10px; line-height: 1; }

/* Pairing */
.pair {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 48px) 20px 32px;
  text-align: center;
}
.logo { width: 88px; height: 88px; border-radius: 22px; }
.pair h1 { margin: 16px 0 8px; font-size: 26px; }
#pair-form { display: flex; flex-direction: column; gap: 10px; margin: 24px 0 8px; }
.code-input {
  font: 600 24px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-align: center;
  letter-spacing: 1px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-transform: uppercase;
}

/* History */
.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px;
  background: var(--bg);
}
.title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 22px; }
.title img { width: 26px; height: 26px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: #30A46C; }
.dot.busy { background: var(--accent); }
.dot.bad { background: #E5A02B; }

.search { padding: 0 16px 8px; position: sticky; top: calc(env(safe-area-inset-top) + 50px); z-index: 1; background: var(--bg); }
.search input {
  width: 100%; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
}

.items { list-style: none; margin: 0; padding: 4px 12px calc(env(safe-area-inset-bottom) + 96px); }
.item {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.item:active { transform: scale(.99); }
.item .body { flex: 1; min-width: 0; }
.item .text {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-wrap; word-break: break-word;
}
.item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.item .pinned { color: var(--pin); }
.item img.thumb { max-width: 120px; max-height: 80px; border-radius: 8px; display: block; background: var(--bg); }
.item .placeholder { width: 120px; height: 72px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.item .more { border: none; background: none; color: var(--muted); font-size: 22px; padding: 4px 6px; }
.empty { text-align: center; padding: 48px 24px; }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 10px;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(transparent, var(--bg) 30%);
}
.actions .primary { flex: 2; }
.actions .secondary { flex: 1; }

/* Sheets */
.sheet {
  width: min(520px, 100%); max-width: 100%; margin: auto auto 0; border: none; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
  display: none; flex-direction: column; gap: 10px;
}
.sheet[open] { display: flex; }
.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet button { width: 100%; }
.sheet .cancel { font-weight: 600; }
.sheet-preview { max-height: 30vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 14px; color: var(--muted); padding: 4px 2px 8px; }
.sheet-preview img { max-width: 100%; border-radius: 8px; }
.settings h2 { margin: 4px 0 8px; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field input { font-weight: normal; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.field span { font-weight: normal; }
details { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
summary { font-weight: 600; cursor: pointer; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; overflow-wrap: anywhere; font-size: 13px; background: var(--bg); padding: 8px 10px; border-radius: 8px; }
.copy-row button { width: auto; }

.banner {
  margin: 0 12px 10px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--accent);
}
.banner p { margin: 0 0 10px; }
.plan h3 { margin: 4px 0; font-size: 16px; }
.plan p { margin: 0 0 10px; }
.plan-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.plan-buttons button { width: auto; flex: 1; padding: 10px 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 600; z-index: 10; max-width: calc(100% - 32px); text-align: center;
}
