:root {
  --bg:       #f2f2f7;
  --bg2:      #ffffff;
  --bg3:      #f2f2f7;
  --border:   #e5e5ea;
  --sep:      #c6c6c8;
  --text:     #1c1c1e;
  --text2:    #8e8e93;
  --accent:   #007aff;
  --accent2:  #0062cc;
  --green:    #34c759;
  --orange:   #ff9500;
  --red:      #ff3b30;
  --radius:   12px;
  --tap:      48px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 70px; }

/* ── HEADER ── */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.header h1 { font-size: 17px; font-weight: 600; flex: 1; }
.header-brand { font-size: 15px; font-weight: 600; color: var(--text); margin-left: 6px; white-space: nowrap; }
.header-tagline { font-size: 11px; color: var(--text2); font-weight: 400; margin-top: -1px; }
.back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 17px; cursor: pointer; min-width: var(--tap); height: var(--tap);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; gap: 4px;
}
.btn-icon {
  background: none; border: none; color: var(--accent);
  font-size: 15px; cursor: pointer; min-width: var(--tap); height: var(--tap);
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: 500;
}
.btn-icon:active { opacity: 0.5; }

/* ── CLIENT NAME TITLE ── */
.client-title {
  background: var(--bg2);
  padding: 12px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.client-title h2 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
}
.client-subtitle {
  font-size: 15px;
  color: var(--text2);
  margin-top: 3px;
}

/* section label between field cards */
.section-label {
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 16px 16px 6px;
}

/* form section title */
.form-section-title {
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 20px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

/* ── LOGO ── */
.logo-circle {
  width: 38px; height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #fff;
}
.logo-circle img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* ── SEARCH (pull-to-reveal) ── */
.search-wrap {
  padding: 8px 16px 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.search-input-wrap {
  flex: 1;
  position: relative;
}
.search-wrap input {
  width: 100%;
  background: #e5e5ea;
  border: none;
  border-radius: 12px;
  padding: 9px 14px 9px 36px;
  color: var(--text);
  font-size: 15px;
  font-family: 'Montserrat', sans-serif;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7' stroke='%238e8e93' stroke-width='2'/%3E%3Cpath d='m20 20-3.5-3.5' stroke='%238e8e93' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  transition: padding-right .15s;
}
.search-wrap input::placeholder { color: #8e8e93; }
.search-wrap input:focus { outline: none; }
.search-clear-btn {
  display: none;
  background: #aeaeb2;
  border: none;
  border-radius: 50%;
  width: 26px; height: 26px;
  min-width: 26px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.sort-btn {
  background: var(--bg2);
  border: none;
  border-radius: 10px;
  width: 40px; height: 36px;
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sort-btn.sort-active { color: var(--accent); }
.sort-menu {
  background: var(--bg2);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.18);
  overflow: hidden;
  min-width: 210px;
}
.sort-option {
  display: block;
  width: 100%;
  padding: 13px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  font-family: 'Montserrat', sans-serif;
  text-align: left;
  cursor: pointer;
}
.sort-option:last-child { border-bottom: none; }
.sort-option.sort-active { color: var(--accent); font-weight: 600; }

/* ── CLIENT LIST ── */
.client-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* grouped card (Memento style) */
.client-group {
  background: var(--bg2);
  border-radius: 14px;
  margin: 0 16px 20px;
  overflow: hidden;
}
.client-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg2);
}
.client-item:last-child { border-bottom: none; }
.client-item:active { background: var(--bg3); }
.client-item .info { flex: 1; min-width: 0; }
.client-item .name {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.client-landmark {
  font-size: 15px;
  color: var(--text);
  font-weight: 300;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.client-chevron {
  color: #c7c7cc;
  font-size: 18px;
  font-weight: 300;
  flex-shrink: 0;
}

.to-badge {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.to-badge.overdue  { background: rgba(255,59,48,.1);  color: var(--red); }
.to-badge.soon     { background: rgba(255,149,0,.1);  color: var(--orange); }
.to-badge.ok       { background: rgba(52,199,89,.1);  color: var(--green); }
.to-badge.none     { background: var(--bg3);           color: var(--text2); }
.to-badge.badge-new { background: rgba(0,122,255,.1); color: var(--accent); }

.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,122,255,.35);
  z-index: 20;
}
.fab::before, .fab::after {
  content: '';
  position: absolute;
  background: #fff;
  border-radius: 2px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.fab::before { width: 2px; height: 20px; }
.fab::after  { width: 20px; height: 2px; }
.fab:active { opacity: 0.8; }

/* ── TABS ── */
.tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  gap: 4px;
}
.tab-btn {
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: block; padding-bottom: 20px; }

/* ── FIELD CARDS (label top, value bottom) ── */
.field-card {
  background: var(--bg2);
  border-radius: var(--radius);
  margin: 10px 16px 0;
  overflow: hidden;
}
.field-row {
  padding: 10px 14px 11px;
  border-bottom: 1px solid var(--border);
}
.field-row:last-child { border-bottom: none; }
.field-label {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 2px;
}
.field-value {
  font-size: 16px;
  color: var(--text);
  line-height: 1.3;
}
.field-value a { color: var(--accent); text-decoration: none; }
.field-value.muted { color: var(--text2); }

/* ── ACTION BUTTONS ── */
.actions {
  display: flex;
  gap: 10px;
  margin: 12px 16px 0;
}
.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  background: var(--bg2);
  border: none;
  border-radius: var(--radius);
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}
.action-btn:active { opacity: 0.5; }
.action-btn .icon { font-size: 24px; }

/* ── SECTION HEADER ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 6px;
}
.section-header h3 {
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .4px;
  font-weight: 400;
}
.section-header .add-btn {
  background: none; border: none;
  color: var(--accent); font-size: 15px;
  cursor: pointer; font-weight: 500;
}
.add-circle-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  border: none; cursor: pointer;
  position: relative; flex-shrink: 0;
}
.add-circle-btn::before, .add-circle-btn::after {
  content: '';
  position: absolute;
  background: #fff;
  border-radius: 2px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.add-circle-btn::before { width: 2px; height: 14px; }
.add-circle-btn::after  { width: 14px; height: 2px; }
.add-circle-btn:active  { opacity: 0.75; }

/* ── TASKS ── */
.task-item {
  background: var(--bg2);
  border-radius: var(--radius);
  margin: 0 16px 8px;
  padding: 12px 14px;
  cursor: pointer;
}
.task-item:active { opacity: 0.7; }
.task-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.task-title { font-size: 16px; font-weight: 500; }
.task-meta { font-size: 15px; color: var(--text2); margin-top: 4px; }

.status-badge {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-new       { background: rgba(0,122,255,.1);   color: var(--accent); }
.status-in_progress { background: rgba(255,149,0,.1); color: var(--orange); }
.status-done      { background: rgba(52,199,89,.1);   color: var(--green); }

/* ── FORMS ── */
.form-body { flex: 1; padding: 16px; overflow-y: auto; background: var(--bg); }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 15px;
  color: var(--text2);
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  appearance: none;
  text-align: left;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-group input[type="date"] { min-height: 50px; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; display: block; width: 100%; }

.form-input {
  width: 100%; height: 48px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 14px; color: var(--text); font-size: 16px;
  font-family: inherit; appearance: none; display: block; box-sizing: border-box;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input.form-input-sm { height: 40px; font-size: 15px; padding: 0 10px; }
select.form-input { background-image: none; }

.send-chip {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: 20px;
  background: var(--bg2); color: var(--text2); font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.send-chip.active { border-color: var(--accent); color: var(--accent); background: rgba(0,122,255,.08); }

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

.form-footer {
  padding: 12px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
}
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { opacity: 0.8; }
.btn-secondary {
  padding: 12px;
  background: var(--bg3);
  color: var(--accent);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn-secondary:active { opacity: 0.7; }
.btn-danger {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  background: none;
  color: var(--red);
  border: 1px solid rgba(255,59,48,.25);
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
}

/* equipment tags */
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tag {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 14px;
  display: flex; align-items: center; gap: 6px;
}
.tag .remove {
  background: none; border: none; color: var(--text2);
  font-size: 16px; cursor: pointer; padding: 0;
}
.tag-input-row { display: flex; gap: 8px; margin-top: 8px; }
.tag-input-row input { flex: 1; }
.tag-input-row button {
  padding: 0 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 8px 10px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 10px;
  cursor: pointer;
}
.nav-btn .nav-icon,
.nav-btn svg.nav-icon { width: 26px; height: 26px; flex-shrink: 0; }
.nav-btn { font-size: 11px; }
.nav-btn.active { color: var(--accent); }
.has-nav { padding-bottom: 70px; }
.nav-label { display: flex; align-items: baseline; justify-content: center; gap: 3px; }
.nav-count { font-size: 11px; font-weight: 400; }
.nav-count.alert { color: var(--red); }

/* ── TASKS SCREEN ── */
.task-list-item {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 13px 16px;
  cursor: pointer;
}
.task-list-item:active { background: var(--bg3); }
.task-list-item .client-name { font-size: 16px; font-weight: 500; }.task-list-item .task-work-line { font-size: 15px; color: var(--text2); margin-top: 3px; }
.task-list-item .task-info { font-size: 15px; color: var(--text2); margin-top: 3px; }

select option { background: var(--bg2); }

/* ── LEAD STATUS BADGES ── */
.lead-new         { background: rgba(0,122,255,.1);   color: var(--accent); }
.lead-in_progress { background: rgba(255,149,0,.1);   color: var(--orange); }
.lead-deal        { background: rgba(52,199,89,.1);   color: var(--green); }
.lead-lost        { background: var(--bg3);            color: var(--text2); }

.lead-source {
  font-size: 12px;
  color: var(--text2);
}

.copy-btn {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: rgba(0,122,255,.08);
  border: none;
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.copy-btn:active { opacity: 0.5; }

/* ── SWIPE-TO-ACTION ── */
.swipe-row {
  position: relative;
  overflow: hidden;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.swipe-row:last-child { border-bottom: none; }
.swipe-action-btn {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 0;
  overflow: hidden;
  background: var(--orange);
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  padding: 0;
}
.swipe-label {
  color: white;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Montserrat', -apple-system, sans-serif;
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
}
.swipe-row .client-item {
  position: relative;
  z-index: 1;
  border-bottom: none;
  will-change: transform;
}

/* ── EQUIPMENT FORM: blocks, chips & segmented controls ── */
.eq-block {
  background: var(--bg2);
  border-radius: var(--radius);
  margin: 10px 0 0;
  padding: 14px 16px;
}
.eq-block .form-group:last-child { margin-bottom: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  color: var(--text2);
  font-size: 15px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  font-family: inherit;
  white-space: nowrap;
}
.chip.chip-on {
  background: rgba(0,122,255,.1);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.seg-group {
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  background: var(--bg2);
}
.seg-btn {
  flex: 1;
  padding: 10px 4px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text2);
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.seg-active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ── Equipment display: ownership & flush tags ── */
.eq-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 13px;
  white-space: nowrap;
}
.eq-tag-own  { background: rgba(0,122,255,.13); color: var(--accent); }
.eq-tag-days { background: rgba(255,196,0,.25); color: #8a6000; }

/* ── DESKTOP ── */
@media (min-width: 600px) {
  html { background: #d1d1d6; }

  .screen.active {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(0,0,0,.18);
    background: var(--bg);
  }

  .bottom-nav {
    left:  calc(50% - 240px);
    right: calc(50% - 240px);
  }

  .fab {
    right: calc(50% - 220px);
  }
}
