:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-2: #475569;
  --border: #E2E8F0;
  --muted: #F1F5F9;
  --accent: #0369A1;
  --accent-text: #FFFFFF;
  --wa: #15803D;
  --error: #B91C1C;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
section { max-width: 720px; margin: 0 auto; padding-bottom: calc(24px + var(--safe-bottom)); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  padding: calc(8px + var(--safe-top)) 8px 8px 16px; background: var(--bg);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
#detail .topbar { flex-direction: column; align-items: stretch; gap: 0; padding-left: 4px; border-bottom: 1px solid var(--border); }
#detail .topbar h1 { padding: 0 12px 4px; font-size: 22px; }
.back-btn {
  align-self: flex-start; display: flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 12px 0 4px;
  border: 0; border-radius: 999px; background: none; color: var(--accent); font: inherit; font-weight: 500; cursor: pointer;
}
.back-btn:active { background: var(--muted); }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: none; color: var(--text-2); cursor: pointer; transition: background .15s;
}
.icon-btn:active { background: var(--muted); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Search */
.search-wrap {
  position: sticky; top: calc(60px + var(--safe-top)); z-index: 9; margin: 0 16px; display: flex; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding-left: 12px;
  box-shadow: var(--shadow);
}
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-wrap svg { color: var(--text-2); width: 20px; height: 20px; }
.search-wrap input {
  flex: 1; min-height: 48px; border: 0; background: none; padding: 0 12px; font: inherit; color: inherit; outline: none;
}
.search-wrap:focus-within { border-color: var(--accent); }
.status { margin: 12px 16px 4px; font-size: 13px; color: var(--text-2); }
.status.offline { color: var(--error); }

/* Cards */
.cards { list-style: none; margin: 0; padding: 4px 16px; display: grid; gap: 8px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); color: inherit; text-decoration: none;
  transition: transform .15s, border-color .15s;
}
.card:active { transform: scale(.98); border-color: var(--accent); }
.card h2 { margin: 0; font-size: 17px; font-weight: 600; }
.card .loc { margin: 2px 0 0; font-size: 14px; color: var(--text-2); }
.kv { margin: 2px 0 0; font-size: 14px; color: var(--text-2); }
.kv span { font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--muted); color: var(--text-2); }
.empty { padding: 40px 16px; text-align: center; color: var(--text-2); }

/* Detail */
.detail { padding: 12px 16px; display: grid; gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel h3 { margin: 0; padding: 10px 16px 2px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.contact { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 16px; border-top: 1px solid var(--border); }
.panel h3 + .contact { border-top: 0; }
.c-main { flex: 1; min-width: 0; }
.contact .name { font-weight: 600; }
.contact .role { font-weight: 400; color: var(--text-2); }
.contact .phone { font-size: 14px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.round { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: none; transition: opacity .15s; }
.round:active { opacity: .8; }
.round svg { width: 20px; height: 20px; }
.call { background: var(--accent); color: var(--accent-text); }
.wa { background: var(--wa); color: #fff; }
.row { margin: 0 16px; padding: 8px 0; border-top: 1px solid var(--border); }
.panel h3 + .row { border-top: 0; }
.panel .row:last-child { padding-bottom: 12px; }
.row .tags { margin-top: 0; }
.k { font-size: 14px; color: var(--text-2); flex: none; }
.kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.kv-row .v { text-align: right; min-width: 0; }
.v { white-space: pre-wrap; overflow-wrap: anywhere; }
.v a { color: var(--accent); }

/* Login */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.login h1 { margin: 12px 0 24px; font-size: 24px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 8px; }
.login label { font-size: 14px; color: var(--text-2); }
#pin {
  width: 100%; min-width: 0; min-height: 56px; font-size: 28px; letter-spacing: .5em; text-align: center; padding-left: .5em;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: inherit;
}
#pin:focus { border-color: var(--accent); outline: none; }
.error { min-height: 1.5em; margin: 0; font-size: 14px; color: var(--error); }
.btn-primary {
  min-height: 48px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn-primary:disabled { opacity: .5; cursor: default; }

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

/* Secret fields (Display = secret) */
.kv-row:has(.secret) { align-items: center; padding-block: 0; }
.secret { display: flex; align-items: center; gap: 0; white-space: nowrap; }
.secret span { font-variant-numeric: tabular-nums; white-space: pre; text-align: right; }
