:root {
  --primary: #25D366;
  --primary-dark: #128C7E;
  --primary-light: #dcf8c6;
  --accent: #34b7f1;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #111b21;
  --text-muted: #667781;
  --border: #e9edef;
  --danger: #e53935;
  --warning: #f9a825;
  --success: #25D366;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; padding-bottom: 70px; }

/* Top bar */
.topbar {
  background: var(--primary-dark);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar .status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #f44336; display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.topbar .status-dot.ok { background: #8bc34a; }
.topbar .status-info { font-size: 11px; opacity: 0.85; }

/* Main content */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text);
}
.card .muted { color: var(--text-muted); font-size: 13px; }

/* Form elements */
label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 10px;
  font-weight: 500;
}
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* prevent iOS zoom */
  background: white;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.15);
}
textarea { resize: vertical; min-height: 70px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  min-height: 44px;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-accent { background: var(--accent); color: white; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-group .btn { flex: 1; }

/* Segmented (Lead / Order toggle) */
.segment {
  display: flex;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.segment label {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  text-align: center;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 14px;
}
.segment input { display: none; }
.segment input:checked + span {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: block;
  margin: -10px -12px;
  padding: 10px 12px;
  border-radius: 6px;
}

/* Phone input row with paste */
.phone-row {
  display: flex;
  gap: 8px;
}
.phone-row input { flex: 1; }
.paste-btn {
  padding: 0 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

/* Result badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-lead { background: #fff3cd; color: #856404; }
.badge-order { background: var(--primary-light); color: var(--primary-dark); }
.badge-warn { background: #ffebee; color: var(--danger); }

/* Search results */
.contact-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.contact-card.lead { border-left-color: var(--warning); }
.contact-card .name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
  color: var(--text);
}
.contact-card .phone {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 6px;
  font-family: ui-monospace, monospace;
}
.contact-card .meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 6px;
}
.contact-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.contact-card .actions .btn {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  min-height: 36px;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
  padding: 6px 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.bottom-nav a.active { color: var(--primary-dark); }
.bottom-nav .icon { font-size: 22px; }

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 14px;
}
.alert-info { background: #e3f2fd; color: #0277bd; border-left: 4px solid #0288d1; }
.alert-warning { background: #fff8e1; color: #795548; border-left: 4px solid var(--warning); }
.alert-danger { background: #ffebee; color: #b71c1c; border-left: 4px solid var(--danger); }
.alert-success { background: var(--primary-light); color: var(--primary-dark); border-left: 4px solid var(--primary); }

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-box {
  background: white;
  padding: 32px 24px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-box h1 {
  text-align: center;
  color: var(--primary-dark);
  margin-bottom: 4px;
  font-size: 22px;
}
.login-box .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

/* Filter row */
.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Lists */
.list-item {
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.list-item .label-name { font-weight: 600; }
.list-item .label-code { color: var(--text-muted); font-size: 12px; font-family: monospace; }

/* Modal */
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
}
.modal {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.2s ease-out;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h3 { margin-bottom: 12px; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.stat-box {
  background: var(--surface);
  padding: 14px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}
.stat-box .num { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.stat-box .lbl { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Desktop refinements */
@media (min-width: 768px) {
  body { padding-bottom: 20px; }
  .bottom-nav { position: sticky; bottom: auto; top: 0; border: 0; border-bottom: 1px solid var(--border); margin-bottom: 0; }
  .bottom-nav { display: none; }
  .topbar-nav {
    display: flex; gap: 4px; margin-left: auto;
  }
  .topbar-nav a {
    color: white; text-decoration: none; padding: 8px 14px;
    border-radius: 6px; font-size: 14px;
  }
  .topbar-nav a.active, .topbar-nav a:hover { background: rgba(255,255,255,0.15); }
}

@media (max-width: 767px) {
  .topbar-nav { display: none; }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Locked field (read-only display for category users) */
.locked-field {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  font-weight: 600;
  display: flex;
  align-items: center;
}

/* Utility */
.mt { margin-top: 12px; }
.mt-lg { margin-top: 20px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap { gap: 8px; }
