:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16191d;
  --muted: #5f6873;
  --border: #e2e5ea;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e6f4f2;
  --call: #0f766e;
  --wa: #128c4a;
  --wa-soft: #e7f6ec;
  --warn-bg: #fff6db;
  --warn-ink: #7a5600;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215;
    --surface: #181c21;
    --surface-2: #20252b;
    --text: #eef1f4;
    --muted: #9aa4af;
    --border: #2b3138;
    --primary: #2dd4bf;
    --primary-ink: #04201d;
    --primary-soft: #12302d;
    --call: #2dd4bf;
    --wa: #4ade80;
    --wa-soft: #143222;
    --warn-bg: #3a2f10;
    --warn-ink: #f5d27a;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1215; --surface: #181c21; --surface-2: #20252b; --text: #eef1f4; --muted: #9aa4af; --border: #2b3138;
  --primary: #2dd4bf; --primary-ink: #04201d; --primary-soft: #12302d; --call: #2dd4bf; --wa: #4ade80; --wa-soft: #143222;
  --warn-bg: #3a2f10; --warn-ink: #f5d27a; --danger: #f87171; --danger-soft: #3a1717; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4rem; }
h2 { font-size: 1.3rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 0 16px; }
.error { color: var(--danger); min-height: 1.2em; font-size: .9rem; }
.status { min-height: 1.2em; font-size: .95rem; }

/* Buttons & fields */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.file-btn input { display: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  font-size: 1.4rem; cursor: pointer; color: inherit;
}
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=tel], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); padding: 28px 22px; border-radius: 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border); text-align: center;
}
.login-card .field { text-align: left; }
.login-logo { font-size: 3rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-ink);
}
.topbar-title { font-size: 1.15rem; margin: 0; }
.menu {
  position: absolute; right: 8px; top: 56px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  display: flex; flex-direction: column; min-width: 240px; overflow: hidden;
}
.menu button { text-align: left; padding: 14px 16px; background: none; border: 0; cursor: pointer; }
.menu button + button { border-top: 1px solid var(--border); }

/* Views */
.view { max-width: 760px; margin: 0 auto; padding: 12px 0 calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }

/* Search + chips */
.search-wrap { padding: 4px 16px 8px; position: sticky; top: 60px; z-index: 10; background: var(--bg); }
.search-wrap input { border-radius: 999px; padding-left: 16px; }
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 8px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .92rem;
}
.chip .count { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.chip.active .count { color: inherit; opacity: .85; }

/* Home: service tiles */
.home { padding: 4px 16px 8px; }
.home-title { font-size: 1.05rem; color: var(--muted); font-weight: 600; margin: 6px 2px 10px; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 520px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px;
  min-height: 108px; padding: 12px 6px 10px; border-radius: var(--radius); cursor: pointer; text-align: center;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.tile:active { transform: scale(.97); }
.tile-icon { font-size: 2rem; line-height: 1.1; }
.tile-name { font-weight: 600; font-size: .86rem; line-height: 1.2; overflow-wrap: anywhere; }
.tile-count {
  margin-top: auto; font-size: .78rem; font-weight: 700; color: var(--primary); background: var(--primary-soft);
  border-radius: 999px; padding: 1px 9px; font-variant-numeric: tabular-nums;
}
.tile-all { background: var(--primary-soft); border-color: transparent; }
.list-head { padding: 0 16px 10px; }
.back-btn {
  background: none; border: 0; color: var(--primary); font-weight: 700; font-size: 1rem;
  min-height: 44px; padding: 0 4px 0 0; cursor: pointer;
}
.list-title { font-size: 1.25rem; margin: 0; }
.list-title .count { color: var(--muted); font-weight: 500; font-size: 1rem; }

/* Contact cards */
.contact-list { list-style: none; margin: 0; padding: 0 16px; display: grid; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.card-head { display: flex; gap: 10px; align-items: flex-start; }
.card-icon {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 1.3rem;
}
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.card-meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.card-notes { margin-top: 6px; font-size: .93rem; overflow-wrap: anywhere; white-space: pre-line; }
.card-foot { margin-top: 8px; color: var(--muted); font-size: .8rem; }
.card-edit { flex: 0 0 auto; }
.phone-row { display: flex; gap: 8px; margin-top: 10px; }
.phone-num { font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.btn-call { flex: 1; justify-content: flex-start; background: var(--primary-soft); color: var(--call); min-height: 44px; padding: 0 14px; }
.btn-wa { flex: 0 0 auto; background: var(--wa-soft); color: var(--wa); min-height: 44px; padding: 0 14px; }

.empty { text-align: center; padding: 40px 24px; }
.empty-icon { font-size: 3rem; }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 28px 16px; margin: 12px 0; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-icon { font-size: 2rem; }
.howto { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { padding-left: 20px; margin: 8px 0 4px; }

/* Preview (import + add) */
.summary {
  margin: 12px 16px; padding: 14px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border);
}
.summary-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: .9rem; }
.stat b { font-size: 1.15rem; display: block; font-variant-numeric: tabular-nums; }
.stat.good b { color: var(--primary); }
.note { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: .9rem; margin: 8px 0; }
.group { margin: 16px 16px 0; }
.group-head {
  display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 6px 2px;
  position: sticky; top: 60px; background: var(--bg); z-index: 5;
}
.group-head .count { color: var(--muted); font-weight: 500; font-size: .9rem; }
.prow {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  margin-bottom: 8px; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: start;
}
.prow.review { border-color: #e0b100; background: linear-gradient(0deg, var(--warn-bg), var(--warn-bg)) padding-box; }
.prow.off { opacity: .5; }
.prow.changed select { border-color: var(--primary); background: var(--primary-soft); }
.prow input[type=checkbox] { width: 22px; height: 22px; margin-top: 10px; accent-color: var(--primary); }
.prow-fields { display: grid; gap: 6px; min-width: 0; }
.prow-line { display: grid; grid-template-columns: 1fr; gap: 6px; }
@media (min-width: 560px) { .prow-line { grid-template-columns: 1.3fr 1fr; } }
.prow input[type=text], .prow select { min-height: 40px; padding: 8px 10px; }
.prow-info { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.prow-info .phones { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-ink); }
.tag.dup { background: var(--surface-2); color: var(--muted); }
.sticky-action {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 15;
  padding: 12px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex; gap: 8px;
}
.sticky-action .btn-primary { flex: 1; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.link-btn { background: none; border: 0; color: var(--primary); font-weight: 600; cursor: pointer; padding: 6px 0; }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: .78rem; font-weight: 600; cursor: pointer;
}
.tab span { font-size: 1.3rem; filter: grayscale(.6); }
.tab.active { color: var(--primary); }
.tab.active span { filter: none; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 12px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.sheet-actions .btn-primary { flex: 1; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cat-row .grow { flex: 1; min-width: 0; }
.cat-row .kw { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  background: #1f2933; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; max-width: calc(100% - 32px);
  box-shadow: 0 8px 30px rgba(0,0,0,.25); font-size: .95rem;
}
