:root {
  color-scheme: light dark;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #eef4f5;
  --text: #162326;
  --muted: #637477;
  --border: #d7e1e3;
  --accent: #0f5f6d;
  --accent-2: #dceff2;
  --danger: #a13d3d;
  --shadow: 0 8px 24px rgba(24, 53, 58, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1719;
    --surface: #162124;
    --surface-2: #1d2b2e;
    --text: #eff6f7;
    --muted: #a9b9bc;
    --border: #2c3b3f;
    --accent: #5fb7c7;
    --accent-2: #17363d;
    --danger: #f09a9a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-header {
  background: var(--accent);
  color: #fff;
  padding: max(18px, env(safe-area-inset-top)) 18px 20px;
}
.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}
.eyebrow { margin: 0 0 4px; font-size: 0.78rem; letter-spacing: .08em; text-transform: uppercase; opacity: .82; }
h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.25rem); line-height: 1.05; }
.subtitle { margin: 7px 0 0; opacity: .88; }
.icon-btn { min-height: 44px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12); color: #fff; border-radius: 12px; padding: 0 14px; }

.container { max-width: 1080px; margin: 0 auto; padding: 18px; }
.search-panel { margin-top: -34px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); }
.search-wrap { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 0 12px; }
.search-wrap > span { font-size: 1.35rem; color: var(--muted); }
.search-wrap input { min-width: 0; width: 100%; min-height: 52px; border: 0; background: transparent; color: var(--text); font-size: 16px; }
.search-wrap input:focus { outline: none; }
.clear-btn { border: 0; background: transparent; color: var(--muted); font-size: 1.6rem; min-width: 40px; min-height: 40px; }
.quick-row, .category-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin; padding-top: 12px; }
.category-row { padding-bottom: 2px; }
.chip { flex: 0 0 auto; min-height: 40px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 0 13px; }
.chip.active { background: var(--accent-2); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); font-weight: 700; }

.status-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 18px 2px 12px; color: var(--muted); font-size: .92rem; }
.status-row strong { color: var(--text); }
.offline-badge { background: #f5d48f; color: #49340a; border-radius: 999px; padding: 5px 9px; font-weight: 700; font-size: .8rem; }

.contacts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr)); gap: 12px; }
.contact-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 15px; box-shadow: var(--shadow); min-width: 0; }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.contact-main { flex: 1; min-width: 0; }
.contact-name { margin: 0; font-size: 1.08rem; line-height: 1.25; overflow-wrap: anywhere; }
.contact-meta { margin: 5px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.4; }
.favorite-btn { flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 12px; font-size: 1.35rem; }
.favorite-btn.active { color: #b88200; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: .76rem; color: var(--accent); background: var(--accent-2); border-radius: 999px; padding: 4px 8px; }
.phone-box { margin-top: 13px; padding: 11px; border-radius: 12px; background: var(--surface-2); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.phone-label { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.phone-number { margin-top: 2px; font-weight: 800; font-size: 1.1rem; letter-spacing: .02em; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.card-actions a, .card-actions button { flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--border); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.call-btn { background: var(--accent); color: #fff; border-color: var(--accent) !important; font-weight: 700; }
.copy-btn { background: var(--surface); color: var(--text); }
.notes { margin: 11px 0 0; color: var(--muted); font-size: .88rem; }

.empty-state { text-align: center; padding: 54px 18px; color: var(--muted); }
.empty-state h2 { color: var(--text); margin-bottom: 6px; }
.empty-icon { font-size: 2.4rem; }
.info-card { margin: 18px 0 8px; border: 1px dashed var(--border); border-radius: 14px; padding: 14px 16px; color: var(--muted); }
.info-card h2 { color: var(--text); margin: 0 0 6px; font-size: 1rem; }
.info-card p { margin: 0; line-height: 1.45; }

.toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: #111; color: white; border-radius: 999px; padding: 10px 14px; opacity: 0; pointer-events: none; transition: .18s ease; z-index: 100; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: .94; transform: translateX(-50%) translateY(0); }
.install-dialog { width: min(92vw, 420px); border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text); padding: 0; }
.install-dialog::backdrop { background: rgba(0,0,0,.5); }
.install-dialog form { padding: 20px; }
.install-dialog h2 { margin-top: 0; }
.primary-btn { width: 100%; min-height: 44px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; }

@media (max-width: 480px) {
  .container { padding: 14px; }
  .search-panel { padding: 11px; border-radius: 16px; }
  .card-actions { flex-direction: column; }
}
