:root {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #777777;
  --line: #e5e5e5;
  --line-strong: #cccccc;
  --accent: #000000;
  --warn: #b8860b;
  --warn-bg: #fff8e1;
  --ok: #1f7a1f;
  --ok-bg: #e9f7e9;
  --err: #b00020;
  --err-bg: #fde7ea;
  --top: env(safe-area-inset-top, 0);
  --bot: env(safe-area-inset-bottom, 0);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--fg);
  font-size: 16px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}
body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 56px 1fr 80px;
  align-items: center;
  padding: calc(12px + var(--top)) 8px 12px;
  background: #000; color: #fff;
  font-weight: 700; letter-spacing: 0.12em;
}
.topbar-left { display: flex; justify-content: flex-start; }
.brand { font-size: 18px; text-align: center; }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-right: 8px; }
.back-btn {
  background: none; border: 0; color: #fff;
  font-size: 32px; line-height: 1;
  width: 44px; height: 44px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.back-btn:active { opacity: 0.6; }
.badge {
  background: #fff; color: #000;
  border-radius: 999px;
  font-size: 12px; font-weight: 700;
  padding: 2px 8px; min-width: 18px; text-align: center;
}
.net {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); display: inline-block;
}
.net.offline { background: var(--err); }

/* Screen */
.screen {
  flex: 1;
  padding: 16px 16px calc(72px + var(--bot));
  max-width: 720px; margin: 0 auto; width: 100%;
}
.screen h1 { font-size: 22px; margin: 8px 0 16px; }
.screen h2 { font-size: 17px; margin: 24px 0 8px; }
.screen p.muted { color: var(--muted); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: var(--bot);
}
.tab {
  background: none; border: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0; color: var(--muted); font-size: 11px;
  min-height: 56px;
}
.tab.active { color: var(--fg); }
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { font-size: 11px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 20px;
  background: #000; color: #fff;
  border: 1px solid #000; border-radius: 0;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn:disabled { opacity: 0.4; }
.btn.ghost { background: #fff; color: #000; }
.btn.danger { background: #fff; color: var(--err); border-color: var(--err); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* Inputs */
label.field {
  display: block; margin-bottom: 14px;
}
label.field > .lbl {
  display: block; margin-bottom: 6px;
  font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.input, .textarea, select {
  width: 100%; min-height: 48px;
  padding: 12px 14px;
  background: #fff; color: #000;
  border: 1px solid var(--line-strong); border-radius: 0;
  font: inherit;
}
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .textarea:focus, select:focus { outline: 2px solid #000; outline-offset: -2px; }

/* Pin pad */
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.pinpad .key {
  background: #fff; color: #000;
  border: 1px solid var(--line-strong);
  min-height: 60px; font-size: 22px; font-weight: 600;
  cursor: pointer;
}
.pinpad .key:active { background: #000; color: #fff; }
.pin-display {
  display: flex; justify-content: center; gap: 14px; margin: 24px 0 8px;
}
.pin-display .dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #000; background: #fff;
}
.pin-display .dot.filled { background: #000; }

/* Managers list (login) */
.manager-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.manager-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px;
  border: 1px solid var(--line-strong); background: #fff;
  text-align: left; cursor: pointer;
  min-height: 80px;
}
.manager-card .mn { font-weight: 700; font-size: 15px; }
.manager-card .ml { font-size: 12px; color: var(--muted); }
.manager-card:active { background: #000; color: #fff; }
.manager-card:active .ml { color: #ccc; }

/* Lead list */
.lead-row {
  display: block;
  padding: 14px 0; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.lead-row .title { font-weight: 600; }
.lead-row .meta { font-size: 13px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; }
.status-tag {
  display: inline-block; padding: 2px 8px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.status-tag.pending { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.status-tag.synced  { background: var(--ok-bg);   color: var(--ok);   border: 1px solid var(--ok); }
.status-tag.error   { background: var(--err-bg);  color: var(--err);  border: 1px solid var(--err); }

/* Filters */
.filters { margin-bottom: 12px; }
.filter-search { margin-bottom: 8px; }
.filter-row { display: flex; gap: 8px; }
.filter-row .filter-sel { flex: 1; min-height: 40px; padding: 8px; font-size: 14px; }

/* Calendar day groups */
.cal-day {
  margin-bottom: 16px;
}
.cal-day-head {
  font-weight: 700;
  padding: 8px 0;
  border-bottom: 2px solid #000;
  margin-bottom: 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cal-row {
  display: block; padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.cal-row .time {
  font-weight: 700; font-size: 16px;
}
.cal-row .place { color: var(--muted); font-size: 13px; margin-top: 2px; }
.cal-row.no-time .time { color: var(--muted); font-weight: 400; }

/* Sync bar */
.sync-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; margin-bottom: 8px;
  gap: 10px;
}
.sync-bar .count { font-size: 14px; color: var(--muted); }

/* Floating action button */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(80px + var(--bot));
  width: 56px; height: 56px;
  background: #000; color: #fff;
  border: 0; border-radius: 0;
  font-size: 28px; line-height: 1;
  z-index: 8; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

/* Direction pills */
.dir-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dir-pill {
  background: #fff; color: #000; border: 1px solid var(--line-strong);
  padding: 12px; min-height: 48px; font-weight: 600;
  cursor: pointer;
}
.dir-pill.active { background: #000; color: #fff; border-color: #000; }

/* Accordion */
.acc { border: 1px solid var(--line-strong); margin-bottom: 8px; }
.acc-head {
  width: 100%; background: #fff; color: #000;
  border: 0; border-bottom: 1px solid var(--line-strong);
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px; font-weight: 600; font-size: 15px;
  cursor: pointer; text-align: left;
}
.acc-head .acc-count {
  background: #000; color: #fff; padding: 2px 8px;
  font-size: 12px; min-width: 24px; text-align: center;
}
.acc-head .acc-count.zero { background: #fff; color: var(--muted); border: 1px solid var(--line-strong); }
.acc.closed .acc-head { border-bottom: 0; }
.acc.closed .acc-body { display: none; }
.acc-body { padding: 12px; }

/* Checkbox tiles */
.chk-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 360px) { .chk-list { grid-template-columns: 1fr; } }
.chk {
  display: flex; align-items: center; gap: 10px;
  background: #fff; color: #000;
  border: 1px solid var(--line-strong);
  padding: 12px; min-height: 48px;
  cursor: pointer;
}
.chk input { width: 20px; height: 20px; accent-color: #000; }
.chk.checked { background: #000; color: #fff; border-color: #000; }
.chk.checked input { accent-color: #fff; }

/* Contact row */
.contact-row {
  display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line-strong);
  margin-bottom: 8px;
}
.contact-row .rm {
  background: #fff; color: var(--err); border: 1px solid var(--err);
  padding: 8px; cursor: pointer;
}

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--bot));
  background: #000; color: #fff;
  padding: 12px 18px;
  font-size: 14px;
  z-index: 30;
  max-width: 80%;
  text-align: center;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 20; padding: 16px;
}
.modal {
  background: #fff; max-width: 360px; width: 100%; padding: 20px;
}
.modal h3 { margin: 0 0 12px; }

.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.hidden { display: none !important; }
