/* ==========================================================================
   PipeDeskHQ — Mobile-First Plumber Job Manager
   ========================================================================== */

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

:root {
  --navy: #0a1628;
  --blue: #1a3a5c;
  --copper: #c67d3a;
  --copper-light: #e8a660;
  --cream: #faf6f0;
  --white: #ffffff;
  --gray-100: #f4f1ec;
  --gray-400: #8b8680;
  --gray-600: #5a5550;
  --success: #2e7d4f;
  --success-bg: #e6f4ec;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warning: #b8860b;
  --warning-bg: #fef7e6;
  --topbar-h: 56px;
  --bottombar-h: 64px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 4px rgba(10,22,40,0.06);
  --shadow-lift: 0 8px 24px rgba(10,22,40,0.10);
}

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--navy);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

h1,h2,h3,h4 { font-family: 'Space Grotesk', sans-serif; letter-spacing: -0.3px; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ============= TOP BAR ============= */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: rgba(250,246,240,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(10,22,40,0.06);
}

.top-bar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700; font-size: 1.2rem;
  color: var(--navy); letter-spacing: -0.5px;
}

.top-bar-logo span { color: var(--copper); }

.top-bar-right { display: flex; align-items: center; gap: 8px; }

/* ============= BOTTOM NAV ============= */
.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 50;
  height: var(--bottombar-h);
  display: flex; align-items: stretch;
  background: var(--white);
  border-top: 1px solid rgba(10,22,40,0.08);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 44px;
  color: var(--gray-400);
  font-size: 0.65rem; font-weight: 500;
  letter-spacing: 0.2px; text-transform: uppercase;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-icon { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; }
.tab-icon svg { width: 22px; height: 22px; }
.tab-label { line-height: 1; }

.tab.active { color: var(--copper); }
.tab.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 32px; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--copper);
}

.tab-add .tab-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--copper); color: var(--white);
  box-shadow: 0 2px 10px rgba(198,125,58,0.35);
}
.tab-add .tab-icon svg { width: 20px; height: 20px; stroke: white; }
.tab-add .tab-label { color: var(--copper); font-weight: 600; }

/* ============= CONTENT ============= */
.content {
  padding: calc(var(--topbar-h) + 16px) 16px calc(var(--bottombar-h) + 16px);
  max-width: 640px; margin: 0 auto;
  min-height: 100vh;
}

/* ============= PAGE HEADER ============= */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

.page-title {
  font-size: 1.5rem; font-weight: 700; color: var(--navy);
}

.page-subtitle {
  font-size: 0.9rem; color: var(--gray-400); margin-top: 2px;
}

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 0 12px;
}

.section-header h2 {
  font-size: 1.1rem; font-weight: 700;
}

/* ============= CARDS ============= */
.card {
  background: var(--white);
  border: 1px solid rgba(10,22,40,0.06);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.card:active { transform: scale(0.985); }
.card + .card { margin-top: 10px; }

@media (hover: hover) {
  .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
}

/* ============= STATS GRID ============= */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-bottom: 8px;
}

.stat-card {
  background: var(--white); border: 1px solid rgba(10,22,40,0.06);
  border-radius: var(--radius-lg); padding: 14px; text-align: center;
  box-shadow: var(--shadow); cursor: default;
}

.stat-card-number {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem; font-weight: 700; color: var(--copper); line-height: 1.1;
}

.stat-card-label {
  font-size: 0.7rem; font-weight: 500; color: var(--gray-400);
  margin-top: 4px; text-transform: uppercase; letter-spacing: 0.3px;
}

/* ============= JOB CARD ============= */
.job-list { }

.job-card {
  display: flex; gap: 12px; align-items: flex-start;
}

.job-card-time {
  flex-shrink: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.8rem; font-weight: 600; color: var(--copper);
  min-width: 90px; padding-top: 2px;
}

.job-card-body { flex: 1; min-width: 0; }

.job-card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem; font-weight: 600; color: var(--navy);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.job-card-customer {
  font-size: 0.85rem; color: var(--gray-600);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.job-card-address {
  font-size: 0.78rem; color: var(--gray-400); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.job-card-amount {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem; font-weight: 600; color: var(--copper); margin-top: 4px;
}

/* ============= CUSTOMER CARD ============= */
.customer-card {
  display: flex; align-items: center; gap: 12px;
}

.customer-card-avatar {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600; font-size: 1rem; color: var(--blue);
}

.customer-card-info { flex: 1; min-width: 0; }

.customer-card-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem; font-weight: 600; color: var(--navy);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.customer-card-phone { font-size: 0.85rem; color: var(--gray-400); }
.customer-card-city { font-size: 0.78rem; color: var(--gray-400); }

.customer-card-meta {
  flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end;
}

/* ============= BADGES ============= */
.badge {
  display: inline-flex; align-items: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.4px; padding: 4px 10px; border-radius: 100px;
  white-space: nowrap;
}

.badge-scheduled { color: var(--copper); background: rgba(198,125,58,0.12); }
.badge-in_progress { color: var(--blue); background: rgba(26,58,92,0.1); }
.badge-completed { color: var(--success); background: var(--success-bg); }
.badge-cancelled { color: var(--gray-400); background: var(--gray-100); }
.badge-neutral { color: var(--gray-600); background: var(--gray-100); }

/* ============= BUTTONS ============= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 24px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem; font-weight: 600; letter-spacing: -0.2px;
  border: none; border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }

.btn-primary {
  color: var(--white); background: var(--copper);
  box-shadow: 0 2px 8px rgba(198,125,58,0.25);
}
.btn-primary:active { background: #b06e30; transform: scale(0.97); }

.btn-secondary {
  color: var(--navy); background: transparent;
  border: 1.5px solid rgba(10,22,40,0.15);
}
.btn-secondary:active { background: var(--gray-100); }

.btn-danger {
  color: var(--white); background: var(--danger);
  box-shadow: 0 2px 8px rgba(192,57,43,0.2);
}
.btn-danger:active { background: #a93226; transform: scale(0.97); }

.btn-link {
  color: var(--copper); background: none; padding: 8px 0;
  min-height: auto; font-size: 0.9rem;
}
.btn-link:hover { text-decoration: underline; }

.btn-sm { min-height: 36px; padding: 8px 16px; font-size: 0.85rem; }
.btn-full { display: flex; width: 100%; }

.btn-icon {
  min-height: 44px; min-width: 44px; padding: 10px;
  border-radius: var(--radius); color: var(--gray-600);
}
.btn-icon:active { background: var(--gray-100); }

.btn-back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.9rem; font-weight: 500; color: var(--copper);
  padding: 8px 0; min-height: 44px;
}
.btn-back svg { width: 20px; height: 20px; }

/* ============= FORMS ============= */
.form { margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem; font-weight: 600; color: var(--navy);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  display: block; width: 100%; min-height: 48px;
  padding: 12px 14px; font-size: 1rem; color: var(--navy);
  background: var(--white);
  border: 1.5px solid rgba(10,22,40,0.12);
  border-radius: var(--radius);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none; appearance: none;
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--gray-400); }

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(198,125,58,0.15);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b8680' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

.form-textarea { min-height: 100px; resize: vertical; }

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

.input-prefix {
  position: relative; display: flex; align-items: center;
}

.input-prefix .prefix {
  position: absolute; left: 14px;
  font-size: 1rem; font-weight: 500; color: var(--gray-400);
  pointer-events: none;
}

.input-prefix .form-input { padding-left: 30px; }

/* ============= SEARCH BAR ============= */
.search-bar {
  position: relative; display: flex; align-items: center;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute; left: 14px;
  width: 20px; height: 20px; color: var(--gray-400);
  pointer-events: none;
}

.search-input {
  display: block; width: 100%; min-height: 48px;
  padding: 12px 14px 12px 44px;
  font-size: 0.95rem; color: var(--navy);
  background: var(--white);
  border: 1.5px solid rgba(10,22,40,0.08);
  border-radius: var(--radius);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.search-input::placeholder { color: var(--gray-400); }
.search-input:focus { border-color: var(--copper); box-shadow: 0 0 0 3px rgba(198,125,58,0.12); }

/* ============= DETAIL PAGE ============= */
.detail-header {
  text-align: center; padding: 20px 0 16px;
}

.detail-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--gray-100);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem; font-weight: 700; color: var(--blue);
  margin: 0 auto 12px;
}

.detail-name {
  font-size: 1.4rem; font-weight: 700; margin-bottom: 4px;
}

.detail-phone {
  font-size: 1rem; color: var(--copper); font-weight: 500;
  display: block; margin-bottom: 4px;
}

.detail-email {
  font-size: 0.9rem; color: var(--gray-600); margin-bottom: 2px;
}

.detail-address {
  font-size: 0.85rem; color: var(--gray-400); margin-bottom: 4px;
}

.detail-notes {
  font-size: 0.85rem; color: var(--gray-600);
  background: var(--gray-100); border-radius: var(--radius);
  padding: 10px 14px; margin-top: 8px; text-align: left;
}

.detail-amount {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem; font-weight: 700; color: var(--copper);
  margin-top: 8px;
}

.detail-actions {
  display: flex; gap: 8px; justify-content: center;
  flex-wrap: wrap; padding: 12px 0 16px;
}

/* ============= CALENDAR ============= */
.calendar-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-month-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem; font-weight: 700; color: var(--navy);
}

.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 2px; background: var(--white);
  border-radius: var(--radius-lg); padding: 12px;
  box-shadow: var(--shadow); border: 1px solid rgba(10,22,40,0.06);
}

.cal-header {
  text-align: center; font-size: 0.7rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--gray-400); padding: 6px 0;
}

.cal-cell {
  position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  aspect-ratio: 1; border-radius: var(--radius);
  cursor: pointer; transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.cal-cell:active { background: var(--gray-100); }

.cal-empty { cursor: default; }

.cal-day {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.88rem; font-weight: 500; color: var(--navy);
}

.cal-today { border: 2px solid var(--copper); }
.cal-today .cal-day { font-weight: 700; }

.cal-selected { background: var(--copper); }
.cal-selected .cal-day { color: var(--white); font-weight: 700; }
.cal-selected.cal-today { border-color: var(--copper); }

.cal-has-jobs::after {
  content: ''; position: absolute; bottom: 4px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--copper);
}

.cal-selected.cal-has-jobs::after { background: var(--white); }

.cal-dot {
  position: absolute; bottom: 3px;
  font-size: 0.55rem; font-weight: 700;
  color: var(--copper);
}

.cal-selected .cal-dot { color: var(--white); }

/* ============= CHIPS ============= */
.chip-grid {
  display: flex; flex-wrap: wrap; gap: 8px;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  font-size: 0.85rem; font-weight: 500;
  color: var(--navy); background: var(--white);
  border: 1.5px solid rgba(10,22,40,0.1);
  border-radius: 100px; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.chip:active { transform: scale(0.95); }

.chip-active {
  color: var(--copper); background: rgba(198,125,58,0.1);
  border-color: var(--copper);
}

/* ============= CONFLICT WARNING ============= */
.conflict-warning {
  padding: 14px 16px; border-radius: var(--radius);
  border-left: 4px solid var(--danger);
  background: var(--danger-bg); color: #8b2820;
  font-size: 0.88rem; line-height: 1.5;
  margin-bottom: 16px;
}

.conflict-warning strong { display: block; margin-bottom: 4px; }

/* ============= TOAST ============= */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottombar-h) + 16px);
  left: 16px; right: 16px;
  z-index: 110;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; pointer-events: none;
}

.toast {
  width: 100%; max-width: 400px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 500;
  pointer-events: auto;
  transform: translateY(20px); opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
}

.toast-show { transform: translateY(0); opacity: 1; }

.toast-success { background: var(--success); color: var(--white); box-shadow: 0 4px 16px rgba(46,125,79,0.3); }
.toast-error { background: var(--danger); color: var(--white); box-shadow: 0 4px 16px rgba(192,57,43,0.3); }

/* ============= LOADING & EMPTY ============= */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 48px 24px;
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(198,125,58,0.2);
  border-top-color: var(--copper); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 40px 24px;
}

.empty-state-icon { margin-bottom: 16px; color: var(--gray-400); }
.empty-state-icon svg { width: 48px; height: 48px; }

.empty-state-text { font-size: 0.9rem; color: var(--gray-400); margin-bottom: 16px; }

.error-state {
  text-align: center; padding: 40px 24px; color: var(--danger);
}

.error-state p { margin-bottom: 16px; }

/* ============= RESPONSIVE ============= */
@media (max-width: 374px) {
  .stats-grid { gap: 6px; }
  .stat-card-number { font-size: 1.25rem; }
  .content { padding-left: 12px; padding-right: 12px; }
}

@media (min-width: 768px) {
  .content { padding-left: 24px; padding-right: 24px; max-width: 720px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-bar { height: calc(var(--bottombar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
  .content { padding-bottom: calc(var(--bottombar-h) + 16px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============= SMS REMINDER BADGES ============= */
.reminder-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.reminder-sent {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}
.reminder-pending {
  background: rgba(234, 179, 8, 0.15);
  color: #a16207;
}
.reminder-no-phone {
  background: rgba(156, 163, 175, 0.15);
  color: #6b7280;
}

/* ===== TOGGLE SWITCH (follow-up opt-out on customer detail) ===== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #374151;
  border-radius: 28px;
  transition: background 0.2s;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: #d97706;
}
.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}
