/* BAAC Field Route — World-Class Mobile UI
 * Design System: Material 3 + BAAC Green
 * Typography: Sarabun (Thai-optimized)
 * Icons: Lucide SVG
 */


:root {
  color-scheme: light dark;
  /* === Material 3 Color Tokens (BAAC Green) === */
  --md-primary: #0a8f3c;
  --md-on-primary: #ffffff;
  --md-primary-container: #c8f7d5;
  --md-on-primary-container: #003d1a;
  --md-secondary: #4a6741;
  --md-on-secondary: #ffffff;
  --md-secondary-container: #cce8c4;
  --md-on-secondary-container: #0a2007;
  --md-tertiary: #c9a227;
  --md-on-tertiary: #ffffff;
  --md-tertiary-container: #f5e6a3;
  --md-on-tertiary-container: #3d3000;
  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-surface: #fdfdf5;
  --md-on-surface: #1a1c18;
  --md-surface-variant: #e0e4d7;
  --md-on-surface-variant: #44483d;
  --md-outline: #74796e;
  --md-outline-variant: #c4c8bb;
  --md-surface-container-low: #f3f3eb;
  --md-surface-container: #edeee6;
  --md-surface-container-high: #e8e8e0;
  --md-inverse-surface: #2f312a;
  --md-inverse-on-surface: #f1f1e9;

  /* === Brand (backward compat) === */
  --baac-green: #0a8f3c;
  --baac-green-dark: #067029;
  --baac-green-deeper: #044d1c;
  --baac-green-light: #2cb357;
  --baac-green-muted: #c8f7d5;
  --baac-gold: #c9a227;
  --baac-gold-light: #f5e6a3;
  --baac-gold-muted: #fdf8e8;

  /* === Semantic Status === */
  --risk-good: #16a34a;
  --risk-warning: #e6a817;
  --risk-bad: #d32f2f;
  --status-active: #0a8f3c;
  --status-attention: #e6a817;
  --status-overdue: #d32f2f;
  --status-completed: #1976d2;
  --status-inactive: #9e9e9e;

  /* === Surface === */
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #eef1ef;
  --text: #1a1c18;
  --text-secondary: #44483d;
  --text-muted: #74796e;
  --border: #c4c8bb;
  --border-light: #e0e4d7;

  /* === Elevation (Material 3) === */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 6px -1px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px -2px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 8px 24px -4px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.04);

  /* === Spacing (8px grid) === */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;

  /* === Radius (Material 3) === */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* === Typography (Sarabun) === */
  --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 28px;
  --font-headline: 22px;
  --font-title: 16px;
  --font-body: 15px;
  --font-body-sm: 13px;
  --font-label: 12px;
  --line-height-thai: 1.6;

  /* === Touch Target === */
  --touch-min: 44px;
  --touch-lg: 48px;

  /* === Status === */
  --pending: #e6a817;
  --visited: #16a34a;
  --skipped: #9e9e9e;
  --danger: #d32f2f;
  --info: #1976d2;

  /* === Safe Area === */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* iOS: no rubber-band bounce on page level (inner scroll areas keep momentum) */
  overscroll-behavior-y: none;
}

html, body {
  height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-body);
  line-height: var(--line-height-thai);
  color: var(--text);
  background: var(--bg);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.hidden { display: none !important; }

/* ===== Lucide SVG Icons ===== */
.icon {
  width: 20px;
  height: 20px;
  stroke-width: 2;
  vertical-align: middle;
  display: inline-block;
  flex-shrink: 0;
}
.btn-icon .icon {
  width: 20px;
  height: 20px;
}
.sheet-tab .icon {
  width: 16px;
  height: 16px;
  margin-right: 4px;
}
.fab .icon {
  width: 24px;
  height: 24px;
}
.logo-icon .icon {
  width: 22px;
  height: 22px;
  color: var(--md-primary);
}

/* ===== Login Screen ===== */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--baac-green-deeper);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(42, 179, 87, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(201, 162, 39, 0.08) 0%, transparent 40%);
  padding: var(--sp-5);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--sp-10) var(--sp-8);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-xl);
  animation: cardEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--sp-4);
  background: var(--baac-green-muted);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-1);
  letter-spacing: -0.3px;
}

.login-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: var(--sp-6);
  line-height: 1.5;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-top: var(--sp-1);
}

/* Features Section */
.features-section {
  padding: 24px 20px 40px;
  max-width: 480px;
  margin: 0 auto;
}

.features-section h2 {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text);
}

.features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 12px;
  text-align: center;
}

.feature-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.feature-card h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.feature-card p {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin: 0;
}

.features-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 20px;
}

/* ===== Landing Page ===== */
.landing-page {
  min-height: 100vh;
  background: #fff;
  color: #1a1a1a;
  overflow-x: hidden;
}
.landing-page.login-mode .lp-login-overlay { opacity: 1; pointer-events: auto; }
.landing-page.login-mode .lp-hero,
.landing-page.login-mode .lp-features,
.landing-page.login-mode .lp-cta-section { display: none; }

/* Hero — Modern BAAC Branding */
.lp-hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px 40px;
  background: linear-gradient(135deg, #f0faf4 0%, #e8f5e9 30%, #fff 70%, #f8fdf9 100%);
  position: relative;
  overflow: hidden;
}
/* Subtle animated background pattern */
.lp-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 50%, rgba(10, 143, 60, 0.03) 0%, transparent 50%),
              radial-gradient(circle at 70% 80%, rgba(10, 143, 60, 0.02) 0%, transparent 40%);
  animation: heroFloat 20s ease-in-out infinite;
  pointer-events: none;
}
@keyframes heroFloat {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(2%, -1%) rotate(1deg); }
  66% { transform: translate(-1%, 2%) rotate(-1deg); }
}
.lp-hero-inner { max-width: 480px; position: relative; z-index: 1; }

/* BAAC Logo — SVG-based, not emoji */
.lp-logo {
  width: 80px;
  height: 80px;
  margin: 0 auto 24px;
  background: linear-gradient(135deg, #0a8f3c 0%, #067029 100%);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(10, 143, 60, 0.25);
  position: relative;
}
.lp-logo::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 24px;
  border: 2px solid rgba(10, 143, 60, 0.15);
  pointer-events: none;
}
.lp-logo svg {
  width: 48px;
  height: 48px;
  fill: white;
}

.lp-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 143, 60, 0.08);
  color: #0a8f3c;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 24px;
  margin-bottom: 28px;
  letter-spacing: 0.3px;
  border: 1px solid rgba(10, 143, 60, 0.12);
}
.lp-badge::before {
  content: '🏛️';
  font-size: 14px;
}

.lp-title {
  font-size: 52px;
  font-weight: 800;
  line-height: 1.05;
  color: #0a8f3c;
  margin: 0 0 8px;
  letter-spacing: -1.5px;
}
.lp-title-accent {
  display: block;
  font-size: 56px;
  background: linear-gradient(135deg, #0a8f3c 0%, #067029 50%, #044d1c 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lp-subtitle {
  font-size: 18px;
  color: #555;
  line-height: 1.6;
  margin: 0 0 36px;
  font-weight: 400;
}

/* Trust indicators */
.lp-trust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}
.lp-trust-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #666;
  background: rgba(255, 255, 255, 0.8);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid #e8ede9;
}
.lp-trust-item .trust-icon {
  font-size: 14px;
}

.lp-cta {
  background: linear-gradient(135deg, #0a8f3c 0%, #067029 100%);
  color: #fff;
  border: none;
  padding: 16px 40px;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 16px rgba(10, 143, 60, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.lp-cta::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}
.lp-cta:hover { 
  transform: translateY(-2px); 
  box-shadow: 0 8px 24px rgba(10, 143, 60, 0.4); 
}
.lp-cta:active { transform: translateY(0); }
.lp-cta .cta-icon {
  font-size: 20px;
  transition: transform 0.25s ease;
}
.lp-cta:hover .cta-icon {
  transform: translateX(3px);
}

.lp-hero-scroll {
  position: absolute;
  bottom: 32px;
  text-align: center;
  z-index: 1;
}
.lp-scroll-hint { font-size: 12px; color: #999; }
.lp-scroll-arrow {
  display: block;
  margin-top: 8px;
  font-size: 18px;
  color: #0a8f3c;
  animation: bounce 2s infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

/* Features — Modern Card Grid */
.lp-features {
  padding: 80px 24px;
  background: #fff;
}
.lp-features-inner { max-width: 640px; margin: 0 auto; }
.lp-section-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin: 0 0 12px;
  color: #1a1a1a;
}
.lp-section-subtitle {
  font-size: 15px;
  color: #666;
  text-align: center;
  margin: 0 0 48px;
}
.lp-feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.lp-feature {
  padding: 24px 20px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #e8ede9;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.lp-feature::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #0a8f3c, #2cb357);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.lp-feature:hover { 
  border-color: rgba(10, 143, 60, 0.3); 
  box-shadow: 0 8px 24px rgba(10, 143, 60, 0.08);
  transform: translateY(-2px);
}
.lp-feature:hover::before { opacity: 1; }
.lp-feature-icon { 
  font-size: 28px; 
  margin-bottom: 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 143, 60, 0.06);
  border-radius: 12px;
}
.lp-feature h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px;
  color: #1a1a1a;
}
.lp-feature p {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin: 0;
}

/* CTA Section — Modern */
.lp-cta-section {
  text-align: center;
  padding: 80px 24px 100px;
  background: linear-gradient(180deg, #fff 0%, #f0faf4 100%);
}
.lp-cta-section h2 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 12px;
  color: #1a1a1a;
}
.lp-cta-section p {
  font-size: 15px;
  color: #666;
  margin: 0 0 28px;
}
.lp-cta-bottom { 
  font-size: 16px; 
  padding: 14px 36px;
  background: linear-gradient(135deg, #0a8f3c 0%, #067029 100%);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(10, 143, 60, 0.3);
}

/* Login Overlay — Modern Glassmorphism */
.lp-login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 24px;
}
.lp-login-card {
  background: #fff;
  border: 1px solid rgba(10, 143, 60, 0.1);
  border-radius: 24px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(10, 143, 60, 0.06);
  position: relative;
  transform: translateY(20px);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.landing-page.login-mode .lp-login-card {
  transform: translateY(0);
}
.lp-login-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.15s ease;
}
.lp-login-close:hover { 
  color: #333; 
  background: rgba(0, 0, 0, 0.05);
}
.lp-login-footer {
  text-align: center;
  font-size: 11px;
  color: #999;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

/* Scroll Reveal Animation */
.fade-up {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.fade-up.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== End Landing Page ===== */

/* Login Form — Modern Inputs */
#login-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

#login-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: left;
  margin-bottom: -4px;
}

#login-username,
#login-password {
  font-size: 15px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  transition: all 0.2s ease;
  font-family: inherit;
}

#login-username:focus,
#login-password:focus {
  outline: none;
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.12);
  background: var(--surface);
}

#login-username::placeholder,
#login-password::placeholder {
  color: var(--text-muted);
}

/* Password input with toggle */
.password-input-wrap {
  position: relative;
}
.password-input-wrap input {
  padding-right: 48px;
}
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  border-radius: 6px;
  transition: all 0.15s ease;
}
.password-toggle:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

/* Remember me checkbox */
.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.login-remember input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--baac-green);
  cursor: pointer;
}

/* Loading state for login button */
.btn-primary.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}
.btn-primary.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}
@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

/* Error message styling */
.login-error {
  color: var(--error);
  font-size: 13px;
  min-height: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.login-error:empty {
  display: none;
}
.login-error::before {
  content: '⚠️';
  font-size: 14px;
}

/* PIN Fallback */
.login-divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin: var(--sp-5) 0 var(--sp-3);
  color: var(--text-muted);
  font-size: 12px;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-link {
  background: none;
  border: none;
  color: var(--baac-green);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-link:hover {
  background: var(--baac-green-muted);
}

#pin-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

#pin-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: left;
}

#pin-input {
  font-size: 28px;
  text-align: center;
  letter-spacing: 14px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  transition: all 0.2s ease;
}

#pin-input:focus {
  outline: none;
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.12);
  background: var(--surface);
}

/* ===== Buttons (shared) ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--baac-green);
  color: white;
  border: none;
  padding: 12px var(--sp-5);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  min-height: 48px;
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: var(--baac-green-dark);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--surface);
  color: var(--baac-green);
  border: 1.5px solid var(--baac-green);
  padding: 10px var(--sp-4);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  min-height: 44px;
}

.btn-secondary:hover {
  background: var(--baac-green-muted);
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-large {
  width: 100%;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  background: var(--danger);
  color: white;
  border: none;
  padding: 12px var(--sp-5);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  min-height: 48px;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.btn-close:hover {
  background: var(--surface-sunken);
  color: var(--text);
}

/* ===== App Layout (Map-as-canvas) ===== */
.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface);
}

/* ===== App Header (Overlay) ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: 48px;
}

.app-header.app-header-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.65) 0%, rgba(0, 0, 0, 0.3) 50%, transparent 100%);
  padding: calc(env(safe-area-inset-top, 0px) + 14px) var(--sp-3) var(--sp-3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  isolation: isolate;
}

.app-header-center {
  display: none;
  align-items: center;
  justify-content: center;
  flex: 1;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 500;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-shrink: 0;
}

.logo-icon {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.logo-text {
  font-weight: 700;
  font-size: 14px;
  color: white;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.app-user {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  flex-shrink: 0;
}

/* User avatar */
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--baac-green) 0%, var(--baac-green-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}

.user-avatar:hover {
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(1.05);
}

.avatar-initial {
  font-size: 14px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
}

/* Sync badge */
.sync-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.sync-badge:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sync-badge.syncing {
  animation: syncPulse 1.5s ease-in-out infinite;
}

/* ป้าย sync ลอย (z 9999) เคยทับปุ่มใน modal — ซ่อนตอนมี modal เปิด */
body:has(.modal:not(.hidden)) #sync-badge { display: none !important; }

@keyframes syncPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sync-icon {
  font-size: 16px;
}

#user-name {
  display: none;
  white-space: nowrap;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* More menu */
.header-more-menu {
  position: relative;
  flex-shrink: 0;
}

.more-menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
  min-width: 200px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.more-menu-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.more-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: #1a1c18;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
  font-family: inherit;
  text-align: left;
}

.more-menu-item:hover {
  background: #f5f5f5;
}

.more-menu-item .icon {
  width: 18px;
  height: 18px;
  color: #666;
}

.more-menu-divider {
  height: 1px;
  background: #e8e8e8;
  margin: 4px 0;
}

.more-menu-info {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.more-menu-danger {
  color: #d32f2f;
}

.more-menu-danger:hover {
  background: #fff5f5;
}

.more-menu-danger .icon {
  color: #d32f2f;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: white;
  width: var(--touch-min);
  height: var(--touch-min);
  min-width: var(--touch-min);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-icon:active {
  transform: scale(0.92);
}

/* Version label — แสดงเวอร์ชันปัจจุบันข้างปุ่มรีเฟรช */
.version-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 2px 8px;
  margin: 0 4px;
  white-space: nowrap;
  line-height: 1.5;
  align-self: center;
}
.version-label.has-update {
  background: rgba(201, 162, 39, 0.7);
  border-color: #c9a227;
  animation: btnPulse 2s ease-in-out infinite;
}
/* ป้ายเวอร์ชันในเมนู (พื้นสว่าง) — ตัวหนังสือเข้มอ่านชัด */
.more-menu-info .version-label {
  color: #1f2937;
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.more-menu-info .version-label.has-update {
  color: #fff;
}

/* Refresh button animations */
.btn-icon.spinning {
  animation: btnSpin 0.8s linear;
}

@keyframes btnSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#refresh-btn.has-update {
  animation: btnPulse 2s ease-in-out infinite;
}

@keyframes btnPulse {
  0%, 100% { background: rgba(255, 255, 255, 0.12); }
  50% { background: rgba(201, 162, 39, 0.6); }
}

/* ===== Full-screen Map ===== */
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

/* ===== FAB Buttons ===== */
.map-fab {
  position: fixed;
  bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  right: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  z-index: 1100;            /* เหนือ bottom-sheet (z 999) */
  pointer-events: none;
  transition: bottom 0.25s ease;
}

/* Q2 FIX: FAB ยกขึ้นตามความสูงของ sheet — ไม่ซ่อนแล้ว */
body:has(.bottom-sheet.sheet-peek) .map-fab   { bottom: calc(180px + env(safe-area-inset-bottom, 0px)); }
body:has(.bottom-sheet.sheet-half) .map-fab   { bottom: calc(52vh + env(safe-area-inset-bottom, 0px)); }
body:has(.bottom-sheet.sheet-full) .map-fab   { bottom: calc(88vh + env(safe-area-inset-bottom, 0px)); }

/* เปิด modal อยู่ → ซ่อนปุ่มลอย (เดิมปุ่ม + ลอยทับฉากหลังที่มืดอยู่) */
body:has(.modal:not(.hidden)) .map-fab { display: none; }

.map-fab .fab {
  pointer-events: auto;
}

/* B: ปุ่มซูม −/+ (แทน Leaflet topleft ที่โดนแผงตัวกรองบัง) */
.zoom-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
}
.fab-zoom {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #fff;
  color: #2c3a2c;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow-md);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab-zoom:active {
  background: #eef4ee;
}

.fab {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fab:active {
  transform: scale(0.92);
}

.fab-primary {
  background: var(--baac-green);
  color: white;
}

.fab-primary:hover {
  background: var(--baac-green-dark);
  box-shadow: var(--shadow-xl);
}

.fab-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-light);
}

.fab-secondary:hover {
  background: var(--bg);
}

/* ===== Bottom Sheet — Modern with haptic feedback ===== */
.bottom-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  max-height: 85dvh;
  --sheet-h: 85dvh;
  --sheet-peek-y: calc(var(--sheet-h) - 140px);
  --sheet-half-y: calc(var(--sheet-h) - 50dvh);
  --sheet-collapsed-y: calc(var(--sheet-h) - 52px);
  height: var(--sheet-h);
  transform: translateY(var(--sheet-peek-y));
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  display: flex;
  flex-direction: column;
}

/* Sheet state indicator */
.bottom-sheet::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 8px;
  opacity: 0.5;
  transition: opacity 0.2s ease;
  z-index: 3;
}

.bottom-sheet.sheet-full::before {
  opacity: 0;
}

@media (orientation: landscape) and (max-height: 520px) {
  .bottom-sheet {
    --sheet-h: 62dvh;
    --sheet-peek-y: calc(var(--sheet-h) - 120px);
    --sheet-half-y: calc(var(--sheet-h) - 50dvh);
    --sheet-collapsed-y: calc(var(--sheet-h) - 44px);
  }
}

@media (orientation: landscape) and (max-height: 400px) {
  .bottom-sheet {
    --sheet-h: 55dvh;
    --sheet-peek-y: calc(var(--sheet-h) - 100px);
  }
}

.bottom-sheet.sheet-peek { transform: translateY(var(--sheet-peek-y)); }
.bottom-sheet.sheet-half { transform: translateY(var(--sheet-half-y)); }
.bottom-sheet.sheet-full { transform: translateY(0); }
.bottom-sheet.sheet-collapsed { transform: translateY(var(--sheet-collapsed-y)); }

/* แผงเต็มจอ = กำลังทำงานในแผง → ซ่อนการ์ดตัวกรองแผนที่ ไม่ให้ถูกตัดค้างเป็นเศษที่ขอบบน */
body:has(.bottom-sheet.sheet-full) #map-debt-filter { display: none; }

/* Sheet Handle — improved touch target */
.sheet-handle {
  flex-shrink: 0;
  z-index: 2;
  background: var(--surface);
  padding: var(--sp-3) 0 var(--sp-2);
  display: flex;
  justify-content: center;
  cursor: grab;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  touch-action: none;
  min-height: 48px;
  position: relative;
}

.sheet-handle:active {
  cursor: grabbing;
}

.sheet-handle-bar {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border);
  transition: background 0.2s ease;
}

/* ปุ่มยุบแผงล่าง — มุมขวาของที่จับ (เป้าจิ้ม 44px ตามเกณฑ์ผู้ใช้วัย 50+) */
.sheet-close {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  z-index: 4;
  touch-action: manipulation;
}
.sheet-close:active { background: var(--md-primary-container, #e9f6ee); color: var(--md-primary, #0a8f3c); }

.sheet-handle:hover .sheet-handle-bar {
  background: var(--text-muted);
}

/* Sheet Tabs */
.sheet-tabs {
  flex-shrink: 0;
  display: flex;
  z-index: 2;
  background: var(--surface);
  padding: 0 var(--sp-2);
  gap: 0;
  border-bottom: 1px solid var(--border-light);
  /* จอเล็ก: เลื่อนแนวนอนได้ แทนบีบให้แน่น/ตัด */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.sheet-tabs::-webkit-scrollbar { display: none; }

.sheet-tab {
  flex: 0 0 auto;              /* ขนาดตามเนื้อหา — ไม่บีบ ไม่ตัด */
  background: none;
  border: none;
  padding: var(--sp-3) var(--sp-3);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
}

.sheet-tab:hover {
  color: var(--text-secondary);
}

.sheet-tab.active {
  color: var(--baac-green);
  border-bottom-color: var(--baac-green);
  font-weight: 600;
}

/* Sheet Content */
.sheet-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  padding-bottom: calc(env(safe-area-inset-bottom, 28px) + 60px);
}

.sheet-content {
  display: none;
  padding: var(--sp-4);
}

.sheet-content.active {
  display: block;
}

/* ===== Today's Visits (Route Pane) ===== */
.today-visits {
  min-height: 100px;
}

.visit-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.visit-card:hover {
  border-color: var(--border);
}

.visit-card:active {
  background: var(--surface-sunken);
}

.visit-card .visit-order {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--baac-green);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

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

.visit-card .visit-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.visit-card .visit-branch {
  font-size: 12px;
  color: var(--text-muted);
}

.visit-card .visit-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.visit-card .visit-distance {
  font-size: 12px;
  color: var(--text-muted);
}

.visit-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

.visit-badge.badge-current {
  background: #dbeafe;
  color: #1d4ed8;
}

.visit-badge.badge-overdue {
  background: #fef2f2;
  color: #dc2626;
}

/* Visits Group */
.visits-group {
  margin-bottom: var(--sp-3);
}

.visits-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--baac-green-dark);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: var(--sp-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Leaflet CircleMarker + Route Number Overlays ===== */
/* circleMarker has NO CSS — rendered directly on Canvas/SVG.
   Only the route-number pill (max 10) needs styling. */
.marker-route-num {
  background: var(--baac-green-deeper);
  color: white;
  font-size: 11px;
  font-weight: 800;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  border: 2px solid white;
}
/* โหมดโฟกัสเส้นทาง (27 ต.ค.69): ป้ายเลขลำดับใหญ่เด่น — ไม่ให้เลขกลุ่มพิกัดบัง */
.marker-route-num.focus {
  min-width: 32px;
  height: 32px;
  border-radius: 16px;
  font-size: 16px;
  border: 3px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
  pointer-events: none;
}

/* ===== Marker Cluster (zoomed-out grouping) — styled numeric badges ===== */
.marker-cluster-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  border: 3px solid #fff;
  cursor: pointer;
}
.marker-cluster-icon.mc-green  { background: rgba(22,163,74,0.92); }  /* 2-9 */
.marker-cluster-icon.mc-orange { background: rgba(217,119,6,0.92); }  /* 10-49 */
.marker-cluster-icon.mc-red    { background: rgba(220,38,38,0.92); }  /* 50+ */
/* hide markercluster default background ring so our icon shows cleanly */
.leaflet-marker-icon.marker-cluster {
  background: transparent !important;
}


/* ===== Customers Toolbar (filters + sort) ===== */
.customers-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  margin-bottom: var(--sp-2);
}

.customers-filters {
  display: flex;
  gap: var(--sp-1);
  flex-wrap: wrap;
  flex: 1;
}

.customers-sort {
  flex-shrink: 0;
  margin-left: auto;   /* ชิดขวาเสมอ (ปุ่มกรองถูกตัดออกแล้ว ไม่มีอะไรดัน) */
}

.sort-select {
  font-size: 16px;
  padding: 6px 10px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
}

.sort-select:focus {
  outline: none;
  border-color: var(--baac-green);
}

/* ===== Customers List ===== */
.customers-header {
  padding: var(--sp-4) 0 var(--sp-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.customers-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.customers-stats {
  background: var(--baac-green-muted);
  color: var(--baac-green-dark);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
}

.customers-search {
  padding: 0 0 var(--sp-3);
}

.customers-search input {
  width: 100%;
  padding: 10px var(--sp-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px;
  background: var(--bg);
  font-family: inherit;
  transition: all 0.2s ease;
}

.customers-search input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.08);
}

.customers-filters {
  display: flex;
  gap: var(--sp-2);
  padding: 0 0 var(--sp-3);
  overflow-x: auto;
}

.filter {
  background: var(--surface);
  border: 1.5px solid var(--border);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  color: var(--text-secondary);
  transition: all 0.15s ease;
  min-height: 36px;
}

.filter:hover {
  border-color: var(--baac-green);
  color: var(--baac-green);
}

.filter.active {
  background: var(--baac-green);
  color: white;
  border-color: var(--baac-green);
}

.customers-list {
  padding: 0 0 80px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.customer-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  transition: all 0.15s ease;
}

.customer-card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

.customer-card:active {
  background: var(--bg);
}

.customer-card.visited {
  opacity: 0.6;
}

.customer-avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--baac-gold-muted);
  color: var(--baac-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  font-weight: 700;
}

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

.customer-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-address {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-cif {
  font-size: 13px;
  color: var(--baac-green);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-weight: 600;
  margin-top: 2px;
}

.customer-actions {
  display: flex;
  gap: var(--sp-1);
  flex-shrink: 0;
}

.btn-small {
  background: var(--bg);
  border: 1px solid var(--border);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-small:hover {
  background: var(--surface-sunken);
}

.btn-small.btn-route-active {
  background: var(--baac-green);
  color: white;
  border-color: var(--baac-green);
}

.customer-no-match {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Route Tab ===== */
.route-header {
  padding: var(--sp-4) 0 var(--sp-2);
}

.route-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-1);
  letter-spacing: -0.2px;
}

.route-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.route-search-box {
  margin-bottom: var(--sp-3);
}

.route-search-box input {
  width: 100%;
  padding: 10px var(--sp-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px;
  background: var(--bg);
  font-family: inherit;
  transition: all 0.2s ease;
}

.route-search-box input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.08);
}

.route-selected {
  margin-bottom: var(--sp-3);
}

.route-selected-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
}

.route-selected-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.route-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.route-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--baac-green-muted);
  border: 1px solid rgba(10, 143, 60, 0.2);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--baac-green-dark);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 14px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: all 0.15s ease;
}

.chip-remove:hover {
  background: rgba(220, 38, 38, 0.1);
}

/* Route Options */
.route-start,
.route-end,
.route-vehicle,
.road-classification {
  margin-bottom: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.route-start label,
.route-end label,
.route-vehicle label,
.road-classification label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}

#route-start-mode,
#route-end-mode,
#route-vehicle,
#road-classification {
  width: 100%;
  padding: 10px var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s ease;
}

#route-start-mode:focus,
#route-end-mode:focus,
#route-vehicle:focus,
#road-classification:focus {
  outline: none;
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.08);
}

.custom-start {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.custom-start input {
  padding: var(--sp-2) var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
}

/* Route Actions */
.route-actions-row {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.route-actions-row .btn-primary,
.route-actions-row .btn-secondary {
  flex: 1;
}

/* ปุ่มคำนวณเส้นทาง 2 ทาง — การ์ดเต็มความกว้าง อ่านง่าย แตะง่าย (ผู้ใช้สูงวัย) */
.route-actions-col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.route-action-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  min-height: 64px;
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.route-action-card .ra-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.route-action-card .ra-desc {
  font-size: 14px;
  line-height: 1.35;
  color: var(--text-muted);
}

.route-action-card.primary {
  background: var(--baac-green);
  border-color: var(--baac-green);
  color: #fff;
}

.route-action-card.primary .ra-desc {
  color: rgba(255, 255, 255, 0.85);
}

.route-action-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.route-action-card:active:not(:disabled) {
  transform: scale(0.99);
}

/* หมายเหตุใต้หัวข้อสรุปเส้นทาง (โชว์เมื่อระบบจัดลำดับให้) */
.result-order-note {
  margin: 6px 0 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.14);
  font-size: 14px;
  line-height: 1.4;
}

/* Route Result */
.route-result {
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-card {
  background: var(--baac-green-deeper);
  color: white;
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-4);
}

.result-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--sp-3);
  opacity: 0.9;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-3);
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.stat-label {
  display: block;
  font-size: 11px;
  opacity: 0.75;
  margin-top: 2px;
  font-weight: 500;
}

.result-fuel {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 13px;
  opacity: 0.9;
}

.result-vehicle-info {
  font-size: 12px;
  opacity: 0.7;
  margin-top: var(--sp-1);
}

.route-order {
  padding-left: var(--sp-5);
  margin-bottom: var(--sp-4);
}

.route-order li {
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.route-order li:last-child {
  border-bottom: none;
}

.route-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding-bottom: var(--sp-4);
}

/* ===== Quick Status Buttons (Visit Modal) ===== */
.quick-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.quick-status-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 2px solid var(--border-light);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  min-height: 64px;
}

.quick-status-btn:hover {
  border-color: var(--baac-green);
  background: var(--baac-green-muted);
}

.quick-status-btn.active {
  border-color: var(--baac-green);
  background: var(--baac-green-muted);
  box-shadow: 0 0 0 1px var(--baac-green);
}

.qs-icon {
  font-size: 20px;
}

.qs-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}

.quick-status-visited.active {
  border-color: #16a34a;
  background: #f0fdf4;
  box-shadow: 0 0 0 1px #16a34a;
}

.quick-status-interested.active {
  border-color: #16a34a;
  background: #f0fdf4;
  box-shadow: 0 0 0 1px #16a34a;
}

.quick-status-noanswer.active,
.quick-status-nothome.active {
  border-color: #d32f2f;
  background: #fff5f5;
  box-shadow: 0 0 0 1px #d32f2f;
}

.quick-status-reschedule.active {
  border-color: #1976d2;
  background: #eff6ff;
  box-shadow: 0 0 0 1px #1976d2;
}

.quick-status-notinterested.active {
  border-color: #9e9e9e;
  background: #f5f5f5;
  box-shadow: 0 0 0 1px #9e9e9e;
}

.qs-desc {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.3;
}

.quick-status-grid.grid-2col {
  grid-template-columns: repeat(2, 1fr);
}

.quick-status-grid.grid-3col {
  grid-template-columns: repeat(3, 1fr);
}

.quick-status-waitincome.active {
  border-color: #f59e0b;
  background: #fffbeb;
  box-shadow: 0 0 0 1px #f59e0b;
}

/* ===== Visit modal sections (card guide) ===== */
.visit-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px 4px;
}

.visit-section {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-bottom: 0;
}

.visit-step-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.visit-step-head label {
  margin-bottom: 0;
  font-size: 14px;
  color: var(--text);
}

.step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--baac-green);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.step-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0 0;
  font-weight: 400;
}

.qs-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 4px 2px 6px;
}

.qs-group-title + .quick-status-grid {
  margin-bottom: 10px;
}

.qs-group-title + .quick-status-grid:last-child {
  margin-bottom: 0;
}

#visit-log-modal .modal-header h3 {
  font-size: 15px;
  overflow-wrap: anywhere;
}

#visit-log-form .form-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding: 12px 20px 16px;
}

.gps-status-table {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: stretch;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.gps-status-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  border-radius: 6px;
}

.gps-status-table .gps-display {
  margin: 0;
  border: none;
  background: transparent;
  padding: 4px;
}

.btn-gps {
  background: var(--baac-green);
  border-color: var(--baac-green);
  color: #fff;
  font-weight: 700;
  width: 100%;
}

/* ===== Visit Tab ===== */
.visit-header {
  padding: var(--sp-4) 0 var(--sp-2);
}

.visit-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.visit-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.visit-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.visit-stat {
  text-align: center;
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border-light);
}

.visit-stat-num {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.visit-stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

.visit-stat-pending .visit-stat-num { color: var(--pending); }
.visit-stat-visited .visit-stat-num { color: var(--visited); }
.visit-stat-skipped .visit-stat-num { color: var(--skipped); }

.visit-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* ===== Visit guide + row cards (tap to record) ===== */
.visit-guide {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--baac-green-muted);
  border: 1px solid rgba(10, 143, 60, 0.2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--baac-green-dark);
}

/* ห้ามตัดครึ่งคำบนจอแคบ: ให้พับทีละขั้น ไม่พับกลางขั้น */
.visit-guide-step {
  white-space: nowrap;
}

.visit-guide-step b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--baac-green);
  color: #fff;
  font-size: 11px;
  margin-right: 2px;
}

.visit-guide-btn {
  background: var(--baac-green);
  color: #fff;
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 12px;
}

.visit-guide-arrow {
  color: var(--baac-green-dark);
  opacity: 0.5;
}

.visit-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.visit-item:active {
  transform: scale(0.99);
  border-color: var(--baac-green);
}

.visit-item.visited {
  border-color: rgba(22, 163, 74, 0.4);
  background: #f0fdf4;
}

.visit-item.skipped {
  border-color: rgba(211, 47, 47, 0.25);
}

.visit-order {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--baac-green);
  color: #fff;
}

.visit-debt {
  font-size: 11px;
  font-weight: 700;
  background: #fef3c7;
  color: #92400e;
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}

.visit-status {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--surface-sunken);
}

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

.visit-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visit-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.visit-go-btn {
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-full);
  background: var(--baac-green);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
}

.visit-item.visited .visit-go-btn,
.visit-item.skipped .visit-go-btn {
  background: var(--surface-sunken);
  color: var(--text-secondary);
}

/* ===== Add-customer modal (step sections + GPS row + photo) ===== */
#add-customer-form .db-search-container {
  margin-bottom: 0;
}

#add-customer-form .form-row-2 {
  margin-bottom: 12px;
}

#add-customer-form .form-row-2:last-child {
  margin-bottom: 0;
}

#add-customer-modal .modal-header h3 {
  font-size: 15px;
  overflow-wrap: anywhere;
}

#add-customer-form .form-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding: 12px 20px 16px;
}

#add-customer-form .form-actions .btn-secondary {
  flex: 1;
}

.gps-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gps-btn-row .btn-secondary {
  width: 100%;
  font-size: 13px;
  padding: 10px 6px;
}

.photo-details {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.photo-details summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  gap: 6px;
  align-items: center;
}

.photo-details summary::-webkit-details-marker {
  display: none;
}

.photo-details summary::before {
  content: '▶';
  font-size: 10px;
  color: var(--text-muted);
}

.photo-details[open] summary::before {
  content: '▼';
}

.photo-details .photo-upload {
  padding: 0 12px 12px;
}

.photo-details .photo-preview {
  aspect-ratio: auto;
  min-height: 96px;
}

/* ===== Empty States ===== */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.empty-state strong {
  color: var(--baac-green);
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  /* 1250 = เหนือ map-debt-filter (700) + promise-alert (1200) — เดิม 200 ทำให้การ์ดตัวกรองแผนที่ทับหัว modal
     (แผงจัดการระบบ/ตั้ง PIN ถูกบังตอนอยู่แท็บแผนที่) · ยังต่ำกว่าแผงปักหมุด (10000) และ toast (99999) */
  z-index: 1250;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: overlayIn 0.2s ease;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

/* Forms inside modal-card that are NOT wrapped in .modal-body should scroll */
.modal-card > form {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes modalSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-card-wide {
  max-width: 640px;
}

.modal-card-narrow {
  max-width: 400px;
}

/* แท็บใน modal จัดการระบบ: โชว์เฉพาะแผงที่เลือก (เดิมไม่มีกฎนี้ ทุกแผงกองโชว์ซ้อนกัน) */
.admin-tab-pane { display: none; }
.admin-tab-pane.active { display: block; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-5) var(--sp-3);
  border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.modal-header-danger {
  background: #fef2f2;
  border-bottom-color: #fecaca;
}

.modal-header-danger h3 {
  color: var(--danger);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
}

.modal-footer {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border-light);
  background: var(--bg);
}

.modal-footer .btn-secondary,
.modal-footer .btn-danger {
  flex: 1;
}

/* ===== Form Elements ===== */
.form-row {
  margin-bottom: var(--sp-4);
}

.form-row:last-child {
  margin-bottom: 0;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--sp-1);
}

.form-row input,
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 10px var(--sp-3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: all 0.15s ease;
}

.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.08);
}

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

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

.form-actions {
  display: flex;
  gap: var(--sp-2);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border-light);
  margin-top: var(--sp-4);
}

.form-actions .btn-primary {
  flex: 1;
}

/* DB Search */
.db-search-container {
  background: var(--baac-green-muted);
  border: 1px solid rgba(10, 143, 60, 0.15);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.db-search-container label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--baac-green-dark);
  margin-bottom: var(--sp-2);
}

.db-search-row input {
  width: 100%;
  padding: 10px var(--sp-3);
  border: 1.5px solid rgba(10, 143, 60, 0.2);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
}

.db-search-row input:focus {
  outline: none;
  border-color: var(--baac-green);
  box-shadow: 0 0 0 3px rgba(10, 143, 60, 0.1);
}

.db-search-results {
  margin-top: var(--sp-2);
  display: none;
}
.db-search-results.active {
  display: block;
}

.db-filled-info {
  margin-top: var(--sp-2);
  font-size: 12px;
  color: var(--baac-green-dark);
  display: none;
}
.db-filled-info.active {
  display: block;
}

/* Mini Map */
.mini-map-container {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

#mini-map {
  width: 100%;
  height: 200px;
}

.mini-map-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
  color: white;
  text-align: center;
  padding: var(--sp-6) var(--sp-3) var(--sp-2);
  font-size: 12px;
  font-weight: 500;
}

/* Photo Upload */
.photo-upload {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.photo-preview {
  width: 100%;
  aspect-ratio: 4/3;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  overflow: hidden;
  background: var(--bg);
}

.photo-preview:hover {
  border-color: var(--baac-green);
  background: var(--baac-green-muted);
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.photo-actions {
  display: flex;
  gap: var(--sp-2);
}

.photo-actions .btn-secondary {
  flex: 1;
}

.photo-size-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* GPS Capture */
.gps-capture {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.gps-display {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.gps-empty {
  color: var(--text-muted);
  font-style: italic;
}

.gps-captured {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.gps-coord {
  color: var(--baac-green-dark);
  font-weight: 600;
}

.gps-accuracy {
  color: var(--text-muted);
  font-size: 11px;
  background: var(--surface-sunken);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
  margin-left: var(--sp-1);
}

/* ===== Report Chart ===== */
.report-chart {
  margin-bottom: 24px;
}

.report-chart h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.chart-container {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border-light);
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 120px;
  padding-top: 20px;
}

.bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  position: relative;
}

.bar-fill {
  width: 100%;
  max-width: 40px;
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
  min-height: 4px;
  margin-top: auto;
}

.bar-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50px;
  text-align: center;
}

.bar-value {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  position: absolute;
  top: 0;
}

/* ===== Report Modal ===== */
.report-controls {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
}

.report-controls .form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: var(--sp-3);
  align-items: end;
}

.report-range-label-wrap {
  display: flex;
  flex-direction: column;
}

.report-range-label {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px var(--sp-3);
  font-size: 13px;
  color: var(--baac-green-dark);
  font-weight: 600;
  min-height: 42px;
  display: flex;
  align-items: center;
}

.report-allowance-note {
  background: var(--baac-gold-muted);
  border: 1px solid var(--baac-gold-light);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 12px;
  color: #78350f;
  margin-top: var(--sp-2);
  line-height: 1.5;
}

.report-preview {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  max-height: 60vh;
}

.report-summary h3,
.report-days h3 {
  margin: 0 0 var(--sp-3) 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.summary-item {
  background: var(--baac-green-muted);
  border: 1px solid rgba(10, 143, 60, 0.15);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  text-align: center;
}

.summary-item.highlight {
  background: var(--baac-gold-muted);
  border-color: var(--baac-gold-light);
}

.summary-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--baac-green-dark);
  line-height: 1.2;
}

.summary-item.highlight .summary-num {
  color: #92400e;
}

.summary-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}

.report-fuel-cost {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  color: var(--text-secondary);
}

.report-day {
  border-left: 3px solid var(--border);
  padding: var(--sp-2) 0 var(--sp-2) var(--sp-3);
  margin: var(--sp-3) 0;
}

.report-day.day-qualifies {
  border-left-color: var(--risk-good);
}

.report-day-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.report-day-header strong {
  font-size: 14px;
  color: var(--text);
}

.day-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.badge-yes,
.badge-no,
.badge-warn {
  padding: 2px var(--sp-2);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.badge-yes { background: var(--risk-good); color: white; }
.badge-no { background: var(--skipped); color: white; }
.badge-warn { background: var(--risk-warning); color: white; }

.report-day-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: var(--sp-2);
}

.report-day-table th {
  background: var(--baac-green);
  color: white;
  padding: var(--sp-2) var(--sp-3);
  text-align: left;
  font-weight: 600;
}

.report-day-table td {
  border: 1px solid var(--border-light);
  padding: var(--sp-2) var(--sp-3);
  vertical-align: top;
}

.report-day-table tr:nth-child(even) td {
  background: var(--bg);
}

.td-name {
  font-weight: 600;
  color: var(--text);
}

.td-sub {
  color: var(--text-muted);
  font-size: 11px;
}

.export-buttons {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border-light);
  background: var(--bg);
  justify-content: flex-end;
}

.export-buttons .btn-secondary {
  flex: 1;
  max-width: 180px;
}

/* ===== Confirm Delete Modal ===== */
.confirm-del-body {
  text-align: center;
  padding: var(--sp-5);
}

.confirm-del-photo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin: 0 auto var(--sp-3);
  overflow: hidden;
  background: var(--bg);
}

.confirm-del-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.confirm-del-question {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}

.confirm-del-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.confirm-del-details {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--sp-3);
}

.confirm-del-warning {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  font-size: 12px;
  color: #991b1b;
  line-height: 1.5;
}

/* ===== Help Modal ===== */
.help-content {
  padding: var(--sp-5);
}

.help-intro,
.help-quickstart {
  margin-bottom: var(--sp-5);
}

.help-intro h4,
.help-quickstart h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.help-intro p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.help-steps {
  padding-left: var(--sp-5);
}

.help-steps li {
  padding: var(--sp-2) 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.help-steps li b {
  color: var(--text);
}

.help-steps small {
  display: block;
  margin-top: var(--sp-1);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== Help modal body (restored 17 ก.ย.69 — เคยหลุดหาย เหลือแค่ intro/quickstart) ===== */
.help-content section {
  margin-bottom: 24px;
}
.help-content section h4 {
  font-size: 16px;
  color: var(--baac-green-dark);
  margin: 0 0 12px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--baac-gold);
  display: inline-block;
}
.help-content p, .help-content li {
  font-size: 14px;
  line-height: 1.6;
  color: #333;
}
.help-content section small {
  display: block;
  color: #666;
  font-size: 12px;
  margin-top: 4px;
  font-style: italic;
}

/* Marker color dots — สีตรงกับหมุดจริงบนแผนที่ (customers.js _riskColors) */
.marker-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 1px #999;
  vertical-align: middle;
  margin-right: 6px;
}
.marker-dot.good { background: var(--risk-good); }
.marker-dot.warning { background: #d97706; }
.marker-dot.bad { background: #dc2626; }
.marker-dot.unclassified { background: #6d28d9; }

/* Status table — อันไหนนับเบี้ยเลี้ยง (แถว "ไม่นับ" ใช้ class .no ตรงๆ ไม่พึ่งลำดับแถว) */
.status-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
}
.status-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #fafafa;
  border-radius: 6px;
  font-size: 13px;
}
.status-row b.counts {
  color: var(--baac-green-dark);
  font-size: 12px;
  white-space: nowrap;
}
.status-row b.counts.no {
  color: #999;
}

/* Allowance box */
.allowance-box {
  background: linear-gradient(135deg, #f0f8f0 0%, #e8f5e9 100%);
  border-left: 4px solid var(--baac-green);
  padding: 12px 16px;
  border-radius: 8px;
}
.allowance-box ul {
  margin: 4px 0;
  padding-left: 20px;
}

/* Help list */
.help-list, .help-tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.help-list li, .help-tips-list li {
  padding: 6px 0;
  border-bottom: 1px dashed #eee;
}
.help-tips-list li {
  padding: 8px 0;
}
.help-list li:last-child, .help-tips-list li:last-child {
  border-bottom: none;
}

/* Help footer */
.help-footer {
  text-align: center;
  padding-top: 16px;
  border-top: 1px solid #eee;
  margin-top: 8px;
}

/* มือถือจอแคบ: ตารางสถานะคอลัมน์แรกย่อลง กันล้นจอ */
@media (max-width: 480px) {
  .status-row {
    grid-template-columns: 104px 1fr auto;
    font-size: 12px;
    padding: 6px 8px;
  }
  .help-content section h4 {
    font-size: 15px;
  }
}

/* ===== Route Search Results ===== */
.route-search-results {
  max-height: 200px;
  overflow-y: auto;
  margin-top: var(--sp-2);
}

.route-search-result {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.route-search-result:hover {
  background: var(--bg);
}

.route-search-result .result-name {
  font-weight: 600;
  font-size: 14px;
}

.route-search-result .result-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Responsive (Mobile) ===== */
@media (max-width: 480px) {
  .app-header .btn-icon {
    /* Keep 44px touch target — don't shrink below Apple/Android minimum */
    width: var(--touch-min);
    height: var(--touch-min);
    min-width: var(--touch-min);
  }
  /* แสดงชื่อผู้ใช้บนมือถือ (เดิมซ่อนไว้) — ย่อให้พอดีจอ */
  #user-name {
    display: inline;
    font-size: 10px;
    max-width: 38px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* เก็บพื้นที่: ไม่เว้นช่องระหว่างปุ่ม + ขอบจอแคบ */
  .app-user {
    gap: 1px;
  }
  .app-header {
    padding-left: 8px;
    padding-right: 4px;
  }
  /* แท็บแผงล่างบนมือถือ: ย่อลงให้ครบ 5 ตัวพอดีจอ 360px (ยังเลื่อนแนวนอนได้ถ้าจอเล็กมาก) */
  .sheet-tab {
    padding: var(--sp-3) 6px;
    font-size: 12px;
  }
  /* ไอคอนแท็บเล็กลงนิด + ไม่ต้องเว้นขวา (flex gap เว้นให้แล้ว) กันแถบแท็บล้นจอ */
  .sheet-tab .icon {
    width: 15px;
    height: 15px;
    margin-right: 0;
  }
  /* ซ่อนชื่อเต็ม เหลือแค่ไอคอน — ประหยัดพื้นที่ header */
  .logo-text {
    display: none;
  }
  .app-logo {
    gap: 0;
  }
  /* เลขเวอร์ชันบนมือถือ: ย่อสั้นไม่เกะกะ (โชว์อย่างเดียว) */
  .version-label {
    font-size: 8px;
    padding: 2px 4px;
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* ลดช่องว่างระหว่างปุ่ม + ขอบจอ ให้พอดี 390px */
  .app-user {
    gap: 1px;
  }
  .app-header {
    padding-left: 10px;
    padding-right: 6px;
  }
  /* เลื่อนกล่องตัวกรองลงพ้น header — ตั้งที่ท้ายไฟล์ (หลัง base rule) ให้ได้ผล */
}

@media (min-width: 768px) {
  .modal {
    align-items: center;
    padding: var(--sp-5);
  }

  .modal-card {
    border-radius: var(--radius-xl);
    max-height: 85dvh;
    animation: modalScaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes modalScaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
  }

  /* แท็บเล็ต/เดสก์ท็อป: แผงทำงานเต็มความกว้าง (ไม่ใช่การ์ดลอยมุมขวาแบบเดิม)
     — เดิม max-width 420px + right/bottom offset ทำให้บนแท็บเล็ตเห็นแค่กล่องเล็ก ๆ
       ที่มุมขวาล่าง อ่านและกดยาก · ตอนนี้กว้างเต็มจอ (จำกัด 1080px แล้วจัดกลาง) */
  .bottom-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    max-width: 1080px;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
    max-height: 90dvh;
    --sheet-h: 90dvh;
  }

  /* แท็บทั้ง 5 อยู่ในแถวเดียว ไม่ต้องเลื่อนแนวนอนซ่อนแท็บสุดท้าย */
  .sheet-tabs {
    justify-content: center;
    padding: 0 var(--sp-4);
  }

  .sheet-tab {
    font-size: 15px;
    padding: var(--sp-3) var(--sp-5);
    min-height: 52px;
  }

  .sheet-tab .icon {
    width: 18px;
    height: 18px;
  }

  .sheet-content {
    width: 100%;
    max-width: 880px;
    margin-left: auto;
    margin-right: auto;
    padding: var(--sp-5);
    font-size: 16px;   /* 50+ อ่านบนแท็บเล็ตระยะแขน — ใหญ่ขึ้นจาก 15px */
  }

  .sheet-handle {
    min-height: 52px;
  }

  .sheet-handle-bar {
    width: 56px;
    height: 6px;
  }

  /* แผงเต็มจอ = ชั้นหน้าสุดของหน้า — ยกเหนือการ์ดตัวกรองแผนที่ (z 700) แต่ยังใต้ FAB (1100) */
  .bottom-sheet.sheet-full {
    z-index: 750;
  }

  /* modal ต้องอยู่เหนือแผงที่ยกขึ้นมา 750 (เดิม 200 → เปิดฟอร์มเพิ่มลูกค้าแล้วโดนแผงบัง) */
  .modal {
    z-index: 900;
  }

  /* ปุ่มลอย: ซ่อนเฉพาะปุ่มแผนที่ (ตำแหน่ง/ซูม) — เก็บปุ่ม ＋ เพิ่มลูกค้าไว้มุมขวาล่างของแผง
     right ต้องอิงขอบขวาของแผง (ไม่ใช่ขอบจอ) ไม่งั้นจอ >1080px ปุ่มจะล้ำออกนอกแผง */
  body:has(.bottom-sheet.sheet-full) .map-fab {
    bottom: calc(var(--safe-bottom) + 24px);
    right: max(var(--sp-4), calc((100vw - 1080px) / 2 + var(--sp-5)));
  }

  body:has(.bottom-sheet.sheet-full) .map-fab .fab-secondary,
  body:has(.bottom-sheet.sheet-full) .map-fab .zoom-stack {
    display: none;
  }

  /* แผงเกือบเต็มจอ: ปุ่มควบคุมบนแผนที่ถูกตัดครึ่งที่ขอบบน — ซ่อนไปเลย (เก็บ attribution ไว้) */
  body:has(.bottom-sheet.sheet-full) .leaflet-top {
    display: none;
  }


  .app-header {
    padding: var(--sp-3) var(--sp-4);
  }

  .app-header-center {
    display: flex;
  }

  #user-name {
    display: inline;
  }

  .btn-icon {
    width: var(--touch-min);
    height: var(--touch-min);
    min-width: var(--touch-min);
  }

  .logo-icon {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .logo-text {
    font-size: 15px;
  }
}

/* ===== Print ===== */
@media print {
  .app-header,
  .map-fab,
  .bottom-sheet {
    display: none !important;
  }

  #map {
    position: relative;
    height: 300px;
  }
}

/* ===== Leaflet Overrides ===== */
.leaflet-top {
  top: 60px !important;
}

.leaflet-control-zoom a {
  width: 36px;
  height: 36px;
  line-height: 36px;
  font-size: 18px;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-family: inherit;
}

/* การ์ดป๊อบอัพ: ความสูงไม่เกินกรอบแผนที่ — เลื่อนดูในได้ (กันปุ่มท้ายการ์ดตกขอบบนมือถือ)
   --card-max-h ถูกตั้งจาก JS ตอน popupopen (customers.js) = ความสูงจริงของแผนที่ */
.leaflet-popup-content-wrapper {
  max-height: var(--card-max-h, 70vh);
  overflow: hidden;
}

.leaflet-popup-content {
  max-height: calc(var(--card-max-h, 70vh) - 26px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* หัวการ์ด + ปุ่มปิด ✕ (มือถือ: นิ้วแตะง่าย 44px) */
.popup-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.popup-close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -8px -10px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}

.popup-close:active {
  background: var(--surface-sunken);
}

.popup-name {
  font-weight: 700;
  font-size: 17px;
  color: var(--baac-green-dark);
  margin-bottom: 4px;
}

.popup-addr {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.popup-actions {
  display: flex;
  gap: 8px;
}

.popup-actions button {
  padding: 10px 14px;
  min-height: 48px;
  font-size: 15px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
}

/* Toast แจ้งเตือน — ตัวใหญ่พออ่านบนมือถือภาคสนาม */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  max-width: 92vw;
  padding: 14px 20px;
  font-size: 16px;
  border-radius: 12px;
  background: #222;
  color: #fff;
  z-index: 12000;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.popup-nav {
  background: var(--baac-green);
  color: white;
}

.popup-edit {
  background: var(--bg);
  color: var(--text);
}

.popup-del {
  background: var(--bg);
  color: var(--danger);
}

/* ===== Debt summary + contracts (ข้อมูลหนี้ Customer Indicator) ===== */
.popup-debt {
  margin: 6px 0 8px;
}
.debt-summary {
  border-left: 4px solid var(--baac-green);
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.debt-summary.debt-urgent {
  background: #fdf0f0;
}
.debt-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 2px 0;
}
.debt-label {
  color: var(--text-secondary);
}
.debt-val {
  font-weight: 700;
  text-align: right;
}
.debt-contracts {
  margin-top: 2px;
  max-height: 365px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}
.debt-contract {
  border: 1px solid #e2e6e2;
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.debt-contract-urgent {
  border-color: #f0b4b4;
  background: #fff9f9;
}
.debt-contract .dc-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-weight: 700;
}
.debt-contract .dc-no {
  color: var(--text);
}
.debt-contract .dc-line {
  font-size: 11px;
  color: var(--text);
  padding: 1px 0;
}
.debt-contract .dc-line .red-debt {
  color: #b30000;
}
.debt-more {
  width: 100%;
  background: var(--baac-green-muted);
  border: 1px solid var(--baac-green-light);
  color: var(--baac-green-dark);
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
}
.debt-more:hover {
  background: #d7edd9;
}
/* ===== 🔍 ขยายตัวอักษรการ์ดหนี้ (ปุ่มในการ์ด) ===== */
.debt-zoom-bar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 6px;
}
.debt-zoom-btn {
  background: var(--baac-green-muted);
  border: 1px solid var(--baac-green-light);
  color: var(--baac-green-dark);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
.debt-zoom-btn:hover { background: #d7edd9; }
body.debt-zoom .debt-zoom-btn { font-size: 15px; padding: 7px 12px; }
/* โหมดขยาย: ตัวอักษรในการ์ดหนี้ใหญ่ขึ้น (popup แผนที่ + การ์ดในหน้าจัดการ) */
body.debt-zoom .debt-summary { padding: 12px; }
body.debt-zoom .debt-row { font-size: 17px; padding: 4px 0; }
body.debt-zoom .debt-contract { font-size: 17px; padding: 10px; }
body.debt-zoom .debt-contract .dc-head { font-size: 17px; margin-bottom: 6px; }
body.debt-zoom .debt-contract .dc-line { font-size: 16px; padding: 3px 0; }
body.debt-zoom .debt-more { font-size: 15px; padding: 10px; }
body.debt-zoom .debt-nodata { font-size: 15px; }
body.debt-zoom .debt-contracts { max-height: max(365px, 60vh); }
body.debt-zoom .debt-card-head .dc-name { font-size: 21px; }
body.debt-zoom .debt-card-head .dc-cif { font-size: 16px; }
/* การ์ดบนแผนที่: ชื่อ/ที่อยู่/ปุ่ม ใหญ่ขึ้นด้วยเพื่อให้อ่านง่าย */
body.debt-zoom .popup-name { font-size: 21px; }
body.debt-zoom .popup-addr { font-size: 16px !important; }
body.debt-zoom .popup-actions button { font-size: 15px; padding: 8px 10px; }
.debt-nodata {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0;
}
.meta-badge.red-debt {
  background: #b30000;
  color: #fff;
}
.meta-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.meta-badge.gray { background: #eef1ef; color: #4a554a; }
.meta-badge.blue { background: #e8f0fa; color: #1e4e79; }
.meta-badge.red { background: #fdecea; color: #b30000; }
.meta-badge.yellow { background: #fdf6e3; color: #92610a; }
.meta-badge.green { background: #e8f5ec; color: #067029; }

/* ===== Mini debt line in customer list ===== */
.customer-debt {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  border-left: 3px solid var(--baac-green);
  padding-left: 8px;
  margin-top: 6px;
  background: var(--surface-sunken);
  border-radius: 4px;
  padding: 4px 8px;
}
.customer-debt.debt-urgent {
  background: #fdf0f0;
}
/* สถานะกำลังโหลดข้อมูลหนี้ */
.customer-debt.debt-loading {
  color: var(--text-muted);
  font-style: italic;
  animation: debtPulse 1.6s ease-in-out infinite;
}
@keyframes debtPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ===== Map debt filter bar (floating over map) ===== */
.map-debt-filter {
  position: absolute;
  top: 10px;
  left: 10px;
  right: auto;
  z-index: 700;
  background: rgba(255,255,255,0.97);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* C: เผื่อฝั่งขวา ~80px ให้ปุ่มระบบไม่โดนเยื้อง */
  max-width: calc(100vw - 90px);
}
.mdf-row {
  display: grid;
  grid-template-columns: 1fr 1fr;   /* A: 2 คอลัมน์เท่ากันทุกแถว */
  gap: 6px;
  align-items: center;
}

.mdf-select {
  width: 100%;
  min-width: 0;
  padding: 7px 26px 7px 9px;
  border: 1.5px solid #d4dad4;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.3;
  font-family: inherit;
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23667' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 9px center;
  -webkit-appearance: none;
  appearance: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #243024;
}
.mdf-select:focus {
  outline: none;
  border-color: var(--baac-green, #0a8f3c);
  box-shadow: 0 0 0 3px rgba(10,143,60,.12);
}
.mdf-reset {
  width: 100%;
  height: 38px;
  border: 1.5px solid #f3d4d2;
  border-radius: 8px;
  background: #fdf3f2;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  align-self: center;
}
.mdf-reset:hover { background: #fdecea; }
/* ปุ่มโกลเด้นรูท v2 (28 ต.ค.69 — ทองเรียบพรีเมียม เต็มแถว ตัวขาว) */
.mdf-plan-row { margin-top: 2px; align-items: center; }
.mdf-label {
  font-size: 13.5px;
  font-weight: 700;
  color: #3c463c;
  padding-left: 4px;
}
.mdf-plan {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #e3ac20 0%, #c6930a 55%, #a87808 100%);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  padding: 0 16px;
  letter-spacing: .2px;
  text-shadow: 0 1px 2px rgba(90,60,0,.45);
  box-shadow: 0 3px 12px rgba(184,134,11,.45), inset 0 1px 0 rgba(255,255,255,.35);
}
.mdf-plan:hover { background: linear-gradient(180deg, #d6a11c 0%, #b8860b 55%, #9c6f07 100%); }
.mdf-plan:active { transform: scale(.99); }
/* ประกายวิ่งตอนแตะ (10/10 — รู้สึกเหมือนเหรียญทอง) */
.mdf-plan { position: relative; overflow: hidden; }
.mdf-plan::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 46px; left: -70px;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,.5), transparent);
  transform: skewX(-20deg);
}
.mdf-plan:hover::after, .mdf-plan:active::after { left: 130%; transition: left .6s ease; }

/* ===== GPS gauge ใต้ช่องค้นหา (โชว์ตลอดแม้ตอนพับ) ===== */
.mdf-gps-gauge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 0;
  font-size: 12px;
  color: #3c463c;
}
.mdf-gps-text { white-space: nowrap; font-weight: 600; }
.mdf-gps-bar {
  flex: 1;
  height: 6px;
  border-radius: 4px;
  background: #e5e9e5;
  overflow: hidden;
  min-width: 40px;
}
.mdf-gps-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: #0a8f3c;
  transition: width 0.25s ease;
}

/* ===== Debt Summary tab (สรุปภาพรวมหนี้) ===== */
.debt-summary-header {
  padding: 4px 0 10px;
  border-bottom: 1px solid #eef1ef;
  margin-bottom: 12px;
}
.debt-summary-header h2 {
  font-size: 18px;
  color: var(--baac-green-dark);
  margin-bottom: 2px;
}
.debt-summary-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.debt-overview-cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.dov-card {
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.dov-green { background: #e8f5ec; }
.dov-blue { background: #e8f0fa; }
.dov-amber { background: #fdf6e3; }
.dov-num { display: block; font-size: 15px; font-weight: 700; color: var(--text); line-height: 1.2; }
.dov-label { display: block; font-size: 10px; color: var(--text-secondary); margin-top: 2px; }
.debt-block {
  background: var(--surface);
  border: 1px solid #e2e6e2;
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}
.debt-block h3 {
  font-size: 13px;
  color: var(--baac-green-dark);
  margin-bottom: 10px;
}
.debt-block-body { display: flex; flex-direction: column; gap: 6px; }
.ds-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 2px 0;
}
.ds-label { color: var(--text); }
.ds-val { font-weight: 600; }
.ds-note { font-size: 12px; color: var(--text-muted); padding: 6px 0; }
.ds-row.ds-total {
  background: var(--baac-green-muted);
  border: 1px solid var(--baac-green-light);
  border-radius: 6px;
  padding: 8px 10px;
  font-weight: 700;
  margin-bottom: 6px;
}
.ds-total .ds-label { color: var(--baac-green-dark); }
.ds-total .ds-val { color: var(--baac-green-dark); font-size: 15px; }
.ds-bar {
  height: 8px;
  background: #eef1ef;
  border-radius: 4px;
  overflow: hidden;
  margin: 2px 0 6px;
}
.ds-bar-fill { height: 100%; border-radius: 4px; }

/* Debt drill-down clickable rows */
.ds-clickable {
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.ds-clickable:hover {
  background: rgba(10, 143, 60, 0.06);
}

.ds-clickable:active {
  background: rgba(10, 143, 60, 0.12);
}

/* ===== Layer Toggle (roadmap ↔ satellite) — Modern ===== */
.layer-toggle {
  display: flex !important;
  flex-direction: row;
  background: white;
  border-radius: 10px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 3px;
  border: none !important;
}

.layer-toggle .layer-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: #666;
}

.layer-toggle .layer-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.layer-toggle .layer-btn.active {
  background: var(--baac-green);
  color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.layer-toggle-mini .layer-btn {
  width: 28px;
  height: 28px;
  font-size: 14px;
}

/* ===== Fullscreen Toggle ===== */
.fs-toggle {
  background: white;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-md);
  margin-top: 6px !important;
  border: none !important;
}

.fs-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: background 0.15s;
}

.fs-btn:hover {
  background: #f0f0f0;
}

.fs-btn.active {
  background: var(--baac-green);
  color: white;
}

/* ===== Fullscreen (real + fake fallback) ===== */
#map:fullscreen,
#map:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  background: #e8f0e8;
}

#map:fullscreen .leaflet-container,
#map:-webkit-full-screen .leaflet-container {
  height: 100vh !important;
  width: 100vw !important;
}

#map.map-fs-fake {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 99999;
  background: #e8f0e8;
}

#map.map-fs-fake .leaflet-container {
  height: 100vh !important;
  height: 100dvh !important;
  width: 100vw !important;
}

body:has(#map.map-fs-fake) .map-fab {
  display: none;
}

/* ===== End Point Pin ===== */
.end-marker {
  background: transparent;
  border: none;
}

.end-pin {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* ===== GPS Location Marker (Google-Maps style) ===== */
.gps-dot {
  width: 22px;
  height: 22px;
  position: relative;
}

.gps-dot-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  background: #4285F4;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

/* Pulsing accuracy halo around the dot */
.gps-dot::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translate(-50%, -50%);
  background: #4285F4;
  border-radius: 50%;
  opacity: 0.5;
  animation: gpsPulse 2s ease-out infinite;
  z-index: 1;
}

@keyframes gpsPulse {
  0%   { transform: translate(-50%, -50%) scale(1);   opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(3);   opacity: 0;   }
}

/* Heading arrow — visible only on mobile w/ compass */
.gps-arrow-wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  transform: translate(-50%, -50%);
  transform-origin: center;
  display: none;
  z-index: 3;
}

.gps-dot.has-heading .gps-arrow-wrap {
  display: block;
}

.gps-arrow {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid #4285F4;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

/* ===== FAB Tracking State (GPS active) ===== */
.fab-secondary.tracking,
.fab.tracking {
  background: #4285F4 !important;
  color: #ffffff !important;
  border-color: #4285F4 !important;
  animation: fabTrackingPulse 2s ease-in-out infinite;
}

@keyframes fabTrackingPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(66, 133, 244, 0.5); }
  50%      { box-shadow: 0 0 0 10px rgba(66, 133, 244, 0); }
}

/* ===== Mobile Scroll Fix (sheet content) ===== */
.sheet-scroll {
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Mobile: เลื่อนกล่องตัวกรองหนี้ ลงพ้น header (หลัง base rule — ชนะ cascade) ===== */
/* Mobile ≤480px (Android+iOS): grid 2 คอลัมน์ — dropdown กว้างพอ อ่านข้อความครบ */
@media (max-width: 480px) {
  .map-debt-filter {
    top: 74px;
    left: 10px;
    /* C: เผื่อขวา ~80px — ไม่เยื้องปุ่มระบบด้านขวา */
    max-width: calc(100vw - 90px);
    padding: 8px;
  }
  .mdf-select {
    font-size: 13px;
    padding: 9px 28px 9px 10px;
  }
}

/* Very small phones (≤360px): ยังคง 2-col แต่ font คงที่ — text ellipsis เฉพาะ option ยาว */

/* จอเล็กมาก (≤330px): ซ่อนเลขเวอร์ชัน ให้ปุ่ม + ชื่อผู้ใช้พอดีตลอด */
@media (max-width: 330px) {
  .version-label {
    display: none;
  }
  #user-name {
    max-width: 30px;
    font-size: 9px;
  }
}

/* ===== Mobile-First Polish (Phase 6) ===== */

/* Touch feedback — no highlight flash anywhere (iOS polish) */
* {
  -webkit-tap-highlight-color: transparent;
}

.fab,
.sheet-tab,
.filter,
.route-chip {
  position: relative;
}

.btn-primary:active,
.btn-secondary:active,
.btn-danger:active,
.fab:active,
.sheet-tab:active,
.filter:active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

/* Touch target size — minimum 44px */
button,
input[type="submit"],
input[type="button"],
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-icon,
.fab,
.sheet-tab,
.filter {
  min-height: 44px;
  min-width: 44px;
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(env(safe-area-inset-top) + 8px);
  }
  
  .bottom-sheet {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .modal-card {
    margin-bottom: env(safe-area-inset-bottom);
  }
}

/* Responsive improvements */
@media (max-width: 390px) {
  /* Smaller hero title on very small screens */
  .lp-title {
    font-size: 40px;
  }
  .lp-title-accent {
    font-size: 44px;
  }
  
  /* Smaller feature cards */
  .lp-feature-grid {
    gap: 12px;
  }
  .lp-feature {
    padding: 16px 14px;
  }
  .lp-feature-icon {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  .lp-feature h3 {
    font-size: 14px;
  }
  .lp-feature p {
    font-size: 12px;
  }
  
  /* Smaller login card */
  .lp-login-card {
    padding: 28px 20px;
    border-radius: 20px;
  }
  
  /* Smaller CTA button */
  .lp-cta {
    padding: 14px 32px;
    font-size: 15px;
  }
}

@media (min-width: 391px) and (max-width: 768px) {
  /* Medium phones */
  .lp-title {
    font-size: 48px;
  }
  .lp-title-accent {
    font-size: 52px;
  }
}

@media (min-width: 769px) {
  /* Tablets and desktop */
  .lp-feature-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  
  .lp-login-card {
    max-width: 440px;
  }
}

/* Landscape mode improvements */
@media (orientation: landscape) and (max-height: 500px) {
  .lp-hero {
    min-height: auto;
    padding: 40px 24px;
  }
  
  .lp-hero-scroll {
    display: none;
  }
  
  .lp-logo {
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
  }
  
  .lp-title {
    font-size: 36px;
  }
  .lp-title-accent {
    font-size: 40px;
  }
  
  .lp-subtitle {
    font-size: 15px;
    margin-bottom: 24px;
  }
}

/* Pull-to-refresh indicator */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: var(--baac-green);
  color: white;
  padding: 8px 16px;
  border-radius: 0 0 12px 12px;
  font-size: 13px;
  font-weight: 600;
  z-index: 99999;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ptr-indicator.visible {
  transform: translateX(-50%) translateY(0);
}

/* Offline indicator */
.offline-indicator {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #f59e0b;
  color: #1a1a1a;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 99999;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.offline-indicator::before {
  content: '📡';
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Better focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--baac-green);
  outline-offset: 2px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1c18;
    --surface: #2f312a;
    --surface-raised: #383a32;
    --surface-sunken: #141512;
    --text: #f1f1e9;
    --text-secondary: #c4c8bb;
    --text-muted: #8a8e82;
    --border: #44483d;
    --border-light: #383a32;
  }

  .landing-page { background: #1a1c18; color: #f1f1e9; }
  .lp-hero { background: linear-gradient(135deg, #1a2418 0%, #1e2e1a 30%, #1a1c18 70%, #1a2018 100%); }
  .lp-badge { background: rgba(10, 143, 60, 0.15); border-color: rgba(10, 143, 60, 0.25); }
  .lp-subtitle { color: #aaa; }
  .lp-feature { background: #2f312a; border-color: #44483d; }
  .lp-feature h3 { color: #f1f1e9; }
  .lp-feature p { color: #aaa; }
  .lp-cta-section { background: linear-gradient(180deg, #1a1c18 0%, #1a2418 100%); }
  .lp-cta-section h2 { color: #f1f1e9; }
  .lp-cta-section p { color: #aaa; }

  .lp-login-overlay { background: rgba(26, 28, 24, 0.95); }
  .lp-login-card { background: #2f312a; border-color: rgba(10, 143, 60, 0.2); }
  .lp-login-close { color: #888; }
  .lp-login-close:hover { color: #ccc; background: rgba(255,255,255,0.05); }

  #login-username, #login-password, #pin-input {
    background: #383a32;
    border-color: #44483d;
    color: #f1f1e9;
  }
  #login-username:focus, #login-password:focus, #pin-input:focus {
    border-color: var(--baac-green);
    background: #2f312a;
  }

  .login-remember { color: #c4c8bb; }
  .login-error { color: #ff6b6b; }

  .app-header.app-header-overlay {
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.5) 50%, transparent 100%);
  }

  .more-menu-dropdown { background: #2f312a; border: 1px solid #44483d; }
  .more-menu-item { color: #f1f1e9; }
  .more-menu-item:hover { background: #383a32; }
  .more-menu-item .icon { color: #aaa; }
  .more-menu-divider { background: #44483d; }
  .more-menu-danger { color: #ff6b6b; }
  .more-menu-danger:hover { background: #3a2020; }

  .bottom-sheet { background: #2f312a; }
  .sheet-handle { background: #2f312a; }
  .sheet-handle-bar { background: #555; }
  .sheet-tab { color: #888; }
  .sheet-tab.active { color: var(--baac-green); border-bottom-color: var(--baac-green); }

  .modal-card { background: #2f312a; border-color: #44483d; }
  .modal-header h2, .modal-header h3 { color: #f1f1e9; }

  /* popup แผนที่ (Leaflet) — ตัวการตัวอักษรกลืนบนมือถือ */
  .leaflet-popup-content-wrapper { background: #2f312a; color: #f1f1e9; box-shadow: 0 12px 40px rgba(0,0,0,0.5); }
  .leaflet-popup-tip { background: #2f312a; }
  .leaflet-popup-content { color: #f1f1e9; }
  .leaflet-container a { color: #6ee7a0; }
  .popup-name { color: #6ee7a0; }
  .popup-debt .debt-label { color: #c4c8bb; }
  .popup-debt .debt-val { color: #f1f1e9; }
  .popup-addr { color: #8a8e82; }

  /* การ์ดสัญญาใน popup แผนที่ */
  .debt-summary { background: #242b24; }
  .debt-summary .debt-val { color: #f1f1e9; }
  .debt-summary.debt-urgent { background: #3a2424; }
  /* การ์ดลูกค้า: แถบหนี้ overdue เดิมเป็นชมพูอ่อน+ตัวอักษรสว่าง = อ่านไม่ออกในโหมดมืด */
  .customer-debt.debt-urgent { background: #3a2424; color: #f1f1e9; }
  .debt-contract { border-color: #44483d; }
  .debt-contract .dc-no { color: #f1f1e9; }
  .debt-contract .dc-line { color: #d5d9cc; }
  .debt-contract-urgent { border-color: #7a4a4a; background: #332222; }
  .meta-badge.gray { background: #3a3c34; color: #c4c8bb; }

  .btn-secondary { background: #2f312a; border-color: var(--baac-green); }

  .customer-card { background: #2f312a; border-color: #44483d; }
  .customer-name { color: #f1f1e9; }

  .quick-status-btn { background: #2f312a; border-color: #44483d; }
  .quick-status-btn:hover { border-color: var(--baac-green); background: #383a32; }

  .sort-select { background: #2f312a; border-color: #44483d; color: #f1f1e9; }

  .report-summary { background: #2f312a; }
  .summary-item { background: #383a32; border-color: #44483d; }
  .report-day { background: #2f312a; border-color: #44483d; }

  .debt-block { background: #2f312a; border-color: #44483d; }
  .dov-card { background: #383a32; border-color: #44483d; }

  .chart-container { background: #2f312a; border-color: #44483d; }

  .admin-user-card { background: #2f312a; border-color: #44483d; }

  .toast { background: #383a32; color: #f1f1e9; }

  .offline-indicator { background: #b45309; color: #fff; }
}

/* ===== Pin Options Panel (ปักหมุดลูกค้าเดิม) ===== */
.pin-options-panel {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 400px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  z-index: 10000;
  overflow: hidden;
  animation: pinSlideUp 0.2s ease-out;
}
@keyframes pinSlideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
.pin-options-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f0fdf4;
  font-size: 14px;
  font-weight: 600;
  color: #166534;
  border-bottom: 1px solid #bbf7d0;
}
.pin-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
  padding: 0 4px;
}
.pin-options-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
}
.pin-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.pin-btn:active { transform: scale(0.97); }
.pin-btn-existing { border-color: #3b82f6; color: #1d4ed8; }
.pin-btn-existing:hover { background: #eff6ff; }
.pin-btn-new { border-color: #10b981; color: #047857; }
.pin-btn-new:hover { background: #ecfdf5; }
.pin-btn-street { border-color: #f59e0b; color: #b45309; text-decoration: none; }
.pin-btn-street:hover { background: #fffbeb; }

/* Search inside pin panel */
.pin-search-input-wrap {
  padding: 10px 16px;
}
.pin-search-input-wrap input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #d1d5db;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
}
.pin-search-input-wrap input:focus {
  border-color: #3b82f6;
}
.pin-search-results {
  max-height: 260px;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.pin-search-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.1s;
}
.pin-search-item:hover { background: #f3f4f6; }
.pin-search-item:active { background: #e5e7eb; }
.pin-search-name {
  font-size: 14px;
  font-weight: 600;
  color: #111;
}
.pin-search-meta {
  font-size: 12px;
  color: #6b7280;
  margin-top: 2px;
}
.pin-search-hint {
  padding: 16px;
  text-align: center;
  color: #9ca3af;
  font-size: 14px;
}

/* ===== Keyboard guard (iOS/Android): ยก panel/modal พ้นแป้นพิมพ์ =====
   JS: Utils.initKeyboardGuard() ตั้ง --kb-h + class keyboard-open บน <html>
   ใช้ 100vh (layout viewport ไม่หด) ลบ --kb-h — กัน dvh หดเองแล้วซ้อนทบ */
html.keyboard-open .pin-options-panel {
  bottom: calc(var(--kb-h, 0px) + 12px);
  max-height: calc(100vh - var(--kb-h, 0px) - 24px);
  overflow-y: auto;
}
html.keyboard-open .pin-search-results {
  max-height: 180px; /* ลดจาก 260px ให้ช่องพิมพ์+ผลลัพธ์เห็นพร้อมกันใน panel ที่สั้นลง */
  -webkit-overflow-scrolling: touch;
}
html.keyboard-open .modal-card {
  max-height: calc(100vh - var(--kb-h, 0px) - 12px);
}
/* ช่องพิมพ์เองก็เลื่อนให้เห็นเสมอ (กันผลลัพธ์ยาวดัน input หลุด) */
html.keyboard-open .pin-search-input-wrap {
  flex-shrink: 0;
}

/* ===== Custom confirm dialog (แทน window.confirm — iOS Safari บล็อก) ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 20000; /* เหนือ panel ปักหมุด (10000) และ modal (200) */
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: overlayIn 0.15s ease;
}
.confirm-card {
  background: #fff;
  border-radius: 16px;
  width: min(92vw, 360px);
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  animation: modalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.confirm-title {
  font-size: 17px;
  font-weight: 700;
  color: #111;
  margin-bottom: 8px;
}
.confirm-msg {
  font-size: 14px;
  color: #374151;
  line-height: 1.55;
  margin-bottom: 18px;
}
.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.confirm-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
}
.confirm-btn:active { transform: scale(0.96); }
.confirm-btn.cancel {
  background: #f3f4f6;
  color: #374151;
}
.confirm-btn.ok {
  background: #16a34a;
  color: #fff;
}
.confirm-btn.ok.danger {
  background: #dc2626;
}
html.keyboard-open .confirm-card {
  /* ถ้า keyboard ค้างเปิดอยู่ ยก dialog ขึ้นพ้นเหมือน panel */
  max-height: calc(100vh - var(--kb-h, 0px) - 24px);
  overflow-y: auto;
}
@media (prefers-color-scheme: dark) {
  .confirm-card { background: #1e1e2e; }
  .confirm-title { color: #e5e5e5; }
  .confirm-msg { color: #b0b0c0; }
  .confirm-btn.cancel { background: #2a2a3e; color: #c0c0d0; }
  .confirm-btn.ok { background: #16a34a; color: #fff; }
  .confirm-btn.ok.danger { background: #dc2626; color: #fff; }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .map-debt-filter { background: rgba(36,38,31,0.97); border-color: #44483d; }
  .map-debt-filter .mdf-select {
    background-color: #2f312a;
    border-color: #44483d;
    color: #f1f1e9;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23aab2aa' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
  }
  .map-debt-filter .mdf-reset { background: #3a2320; border-color: #5c3430; color: #ff8a80; }
  .map-debt-filter .mdf-reset { background: #2f312a; border-color: #44483d; color: #ff6b6b; }
  .map-debt-filter .mdf-reset:hover { background: #3a2424; }
  .pin-options-panel { background: #1e1e2e; }
  .pin-options-header { background: #1a2e1a; color: #86efac; border-bottom-color: #2d4a2d; }
  .pin-btn { background: #2a2a3e; border-color: #3a3a5a; }
  .pin-btn-existing { border-color: #60a5fa; color: #93c5fd; }
  .pin-btn-existing:hover { background: #1e3a5f; }
  .pin-btn-new { border-color: #34d399; color: #6ee7b7; }
  .pin-btn-new:hover { background: #1a3a2a; }
  .pin-btn-street { border-color: #fbbf24; color: #fcd34d; }
  .pin-btn-street:hover { background: #3a2f12; }
  .pin-search-input-wrap input { background: #2a2a3e; border-color: #3a3a5a; color: #e5e5e5; }
  .pin-search-item:hover { background: #2a2a3e; }
  .pin-search-name { color: #e5e5e5; }
  .pin-search-meta { color: #9ca3af; }
}

/* ===== Search row inside map-debt-filter (unified panel) ===== */
.mdf-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 2px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}
.mdf-search-icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.mdf-search-row input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  padding: 6px 0;
  color: var(--text);
  min-width: 0;
}
.mdf-search-row input::placeholder { color: var(--text-muted); }
.mdf-search-clear {
  background: none;
  border: none;
  font-size: 15px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  flex-shrink: 0;
  line-height: 1;
}
.mdf-search-clear:hover { color: var(--text); }
/* Collapse toggle (▼/▲) — always visible in search row */
.mdf-toggle {
  background: #eef4ee;
  border: 1px solid #d4dad4;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1;
  color: #243024;
  cursor: pointer;
  padding: 6px 8px;
  flex-shrink: 0;
  font-family: inherit;
  min-width: 32px;
  min-height: 32px;
}
.mdf-toggle:hover { background: #e2ece2; }
.mdf-toggle.has-active {
  background: #0a8f3c;
  border-color: #0a8f3c;
  color: #fff;
}
/* Collapsed state (default): show only search row + results — hide filter rows */
.map-debt-filter.mdf-collapsed .mdf-row { display: none; }
.map-debt-filter.mdf-collapsed .mdf-search-row { border-bottom: none; margin-bottom: 0; }

/* Results dropdown (inside filter panel) */
.msb-results {
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.msb-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}
.msb-result-item:last-child { border-bottom: none; }
.msb-result-item:hover, .msb-result-item:focus { background: var(--md-surface-container-low); }
.msb-result-item:active { background: var(--md-surface-container); }
.msb-result-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.msb-result-info { flex: 1; min-width: 0; }
.msb-result-name {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msb-result-meta { font-size: 11px; color: var(--text-muted); }
.msb-no-results {
  padding: 14px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  .mdf-search-row { border-bottom-color: rgba(255,255,255,0.08); }
  .mdf-search-row input { color: #f1f1e9; }
  .mdf-search-row input::placeholder { color: #aab2aa; }
  .mdf-search-clear { color: #aab2aa; }
  .mdf-search-clear:hover { color: #f1f1e9; }
  .mdf-search-icon { color: #aab2aa; }
  .msb-results { border-bottom-color: rgba(255,255,255,0.08); }
  .msb-result-item { border-bottom-color: rgba(255,255,255,0.06); }
  .msb-result-item:hover { background: rgba(255,255,255,0.06); }
  .msb-result-name { color: #f1f1e9; }
  .msb-result-meta { color: #aab2aa; }
  .msb-no-results { color: #aab2aa; }
  .mdf-gps-gauge { color: #c9d2c9; }
  .mdf-gps-bar { background: rgba(255,255,255,0.12); }
}

/* ===== Staff grid: แตะชื่อ + PIN (แผน B วังท่าช้าง) ===== */
.staff-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);   /* 2 คอลัมน์เท่ากัน — ปุ่มสาขา/ชื่อเรียงตรงกัน (17 ต.ค.69) */
  gap: 8px;
  margin: 8px 0 12px;
  max-height: 180px;
  overflow-y: auto;
}
.staff-grid > p { grid-column: 1 / -1; margin: 0 0 4px; }   /* ข้อความ "เลือกสาขาก่อน" เต็มแถว ไม่แย่งช่องปุ่ม */
.staff-grid .staff-back { grid-column: 1 / -1; }            /* ปุ่มเปลี่ยนสาขาเต็มแถว */
.staff-btn {
  padding: 12px 8px;
  font-size: 15px;
  border: 2px solid #b6e2c5;
  border-radius: 10px;
  background: #f0f9f4;
  color: #0a5c28;
  cursor: pointer;
  text-align: center;
  min-height: 52px;
}
.staff-btn:active { transform: scale(0.97); }
.staff-btn.staff-selected {
  border-color: #0a8f3c;
  background: #0a8f3c;
  color: #fff;
  font-weight: 700;
}
/* ปุ่มเล็กในการ์ดรายชื่อแอดมิน (ใช้กับปุ่มลบเดิมด้วย) */
.btn-icon-sm, .btn-danger-sm {
  padding: 6px 10px;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  margin-left: 4px;
}
.btn-danger-sm { border-color: #fecaca; }

/* ===== B (17 ต.ค.69): โหมดตัวใหญ่สำหรับหน้างาน — เปิดจาก ⋯ → 🔍 ตัวใหญ่ (จำค่าในเครื่อง) ===== */
body.field-big .customer-name { font-size: 19px; }
body.field-big .customer-address { font-size: 16px; }
body.field-big .customer-cif { font-size: 15px; }
body.field-big .btn-small { width: 48px; height: 48px; font-size: 18px; }
body.field-big .sheet-tab { font-size: 17px; min-height: 52px; }
body.field-big .mdf-select { font-size: 16px; min-height: 48px; }
body.field-big #customer-search, body.field-big #map-search, body.field-big #route-search { font-size: 17px; min-height: 48px; }
body.field-big .fab { width: 56px; height: 56px; }
body.field-big .route-action-card { font-size: 17px; }
/* ===== แจ้งเตือนนัดติดตาม (redesign 15 พ.ย.69) — อยู่ในโฟลว์ใต้หัวเว็บ ไม่ทับเนื้อหา ===== */
#promise-alert {
  position: fixed;
  top: var(--pa-top, calc(env(safe-area-inset-top, 0px) + 104px));
  left: 12px;
  right: 12px;
  z-index: 1200;                 /* เหนือปุ่มลอย (1100) — เดิม 800 ทำให้ปุ่มทับ */
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #FFE7E1 0%, #FFF4D8 100%);
  border: 1px solid #F2C4B4;
  border-left: 4px solid #D93A2B;
  color: #450D05;
  font-size: 16px;               /* วัย 50+ อ่านชัด (เดิม 13.5px) */
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  animation: promiseAlertIn .3s cubic-bezier(.2, .8, .2, 1);
}
#promise-alert.hidden { display: none !important; }
@media (min-width: 768px) {
  #promise-alert { left: 50%; right: auto; transform: translateX(-50%); width: 460px; }
}
#promise-alert .pa-ico { font-size: 20px; flex: none; }
#promise-alert .pa-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#promise-alert .pa-text b { font-size: 15px; font-weight: 700; }
#promise-alert .pa-text span { font-size: 13px; opacity: .9; white-space: nowrap; }
#promise-alert .pa-btn {
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 10px;
  background: #0A8F3C; color: #fff; font-size: 15px; font-weight: 700;
  white-space: nowrap; flex: none; cursor: pointer;
}
#promise-alert .pa-btn:active { background: #076b2d; }
#promise-alert .pa-close {
  width: 44px; height: 44px; flex: none; border: 1px solid rgba(0, 0, 0, .18); border-radius: 50%;
  background: rgba(0, 0, 0, .10); color: #450D05; font-size: 20px; font-weight: 700; line-height: 1; cursor: pointer;
}
#promise-alert .pa-close:active { background: rgba(0, 0, 0, .14); }
#promise-alert button:focus-visible { outline: 3px solid #0A8F3C; outline-offset: 2px; }
/* ดันแผงตัวกรองบนแผนที่ลง เมื่อมีแถบแจ้งเตือน (ไม่ให้ทับกัน) */
body.alert-open .map-debt-filter { top: calc(74px + var(--pa-space, 0px)) !important; }
@media (min-width: 768px) {
  body.alert-open .map-debt-filter { top: calc(10px + var(--pa-space, 0px)) !important; }
}
@keyframes promiseAlertIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-color-scheme: dark) {
  #promise-alert {
    background: linear-gradient(135deg, rgba(217,58,43,.22) 0%, rgba(120,90,20,.28) 100%);
    border-color: rgba(255,255,255,.18); color: #FFF3EE;
  }
  #promise-alert .pa-close { background: rgba(255,255,255,.14); color: #FFF3EE; }
}
@media (max-width: 380px) {
  #promise-alert { padding: 9px 10px; gap: 8px; }
  #promise-alert .pa-text b { font-size: 13px; white-space: nowrap; line-height: 1.3; }
  #promise-alert .pa-text span { font-size: 12px; }
  #promise-alert .pa-btn { padding: 0 10px; font-size: 14px; }
}

/* ===== ปฏิทินงาน — Google Calendar style (M3 tokens, scoped #sheet-calendar) 31 ต.ค.69 ===== */
#sheet-calendar .cal-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
#sheet-calendar .cal-chip { display: inline-flex; align-items: center; gap: 4px; padding: 7px 14px; border-radius: 999px; background: var(--md-surface-variant); color: var(--md-on-surface-variant); font-size: 14px; font-weight: 500; }
#sheet-calendar .cal-chip-due { background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); }
#sheet-calendar .cal-chip-over { background: var(--md-error-container); color: var(--md-on-error-container); }
#sheet-calendar .cal-chip-paid { background: var(--md-primary-container); color: var(--md-on-primary-container); }

#sheet-calendar .cal-nav { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; }
#sheet-calendar .cal-nav-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: var(--md-on-surface-variant); font-size: 22px; line-height: 1; cursor: pointer; flex: none; }
#sheet-calendar .cal-nav-btn:hover { background: var(--md-surface-variant); }
#sheet-calendar .cal-title { font-size: 20px; font-weight: 600; letter-spacing: .2px; color: var(--md-on-surface); min-width: 150px; text-align: center; }
#sheet-calendar .cal-today-btn { margin-left: 8px; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--md-outline); background: transparent; color: var(--md-primary); font-size: 14px; font-weight: 600; cursor: pointer; }
#sheet-calendar .cal-today-btn:hover { background: var(--md-primary-container); border-color: transparent; color: var(--md-on-primary-container); }

#sheet-calendar .cal-week { display: grid; grid-template-columns: repeat(7, 1fr); margin-top: 8px; padding: 0 2px; color: var(--md-on-surface-variant); font-size: 14px; font-weight: 600; text-align: center; }
#sheet-calendar .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 2px; }
#sheet-calendar .cal-cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; aspect-ratio: 1 / 1; min-height: 46px; padding: 0 0 8px; border: 1px solid transparent; border-radius: 14px; background: transparent; color: var(--md-on-surface); font: inherit; font-size: 15px; cursor: pointer; transition: background .18s ease, border-color .18s ease, transform .18s ease; -webkit-tap-highlight-color: transparent; }
#sheet-calendar .cal-cell:hover { background: var(--md-surface-variant); transform: translateY(-1px); }
#sheet-calendar .cal-cell:active { transform: scale(.94); }
#sheet-calendar .cal-empty { pointer-events: none; background: transparent; }
#sheet-calendar .cal-selected { background: var(--md-surface-container); border-color: var(--md-outline-variant); }
#sheet-calendar .cal-today .cal-daynum { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: linear-gradient(135deg, var(--md-primary) 0%, #2fbf60 100%); color: var(--md-on-primary); font-weight: 700; box-shadow: 0 2px 10px rgba(10,143,60,.35); }
#sheet-calendar .cal-dot { position: absolute; bottom: 6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
#sheet-calendar .cal-dot-due { background: var(--md-error); color: var(--md-on-error); }
#sheet-calendar .cal-dot-wait { background: var(--md-tertiary); color: var(--md-on-tertiary); }
#sheet-calendar .cal-dot-paid { background: var(--md-primary-container); color: var(--md-on-primary-container); }

#sheet-calendar .cal-section-title { font-size: 16px; font-weight: 700; color: var(--md-on-surface); margin: 20px 0 6px; }
#sheet-calendar .cal-entry { background: var(--md-surface-container-low); border: 1px solid var(--md-outline-variant); border-left: 4px solid var(--md-outline); border-radius: 16px; padding: 13px 15px; margin: 10px 0; box-shadow: 0 1px 2px rgba(60, 64, 67, .10); transition: box-shadow .2s ease, transform .2s ease; }
#sheet-calendar .cal-entry:hover { box-shadow: 0 4px 14px rgba(60, 64, 67, .16); transform: translateY(-1px); }
#sheet-calendar .cal-entry-due, #sheet-calendar .cal-entry-overdue { border-left-color: var(--md-error); }
#sheet-calendar .cal-entry-upcoming { border-left-color: var(--md-tertiary); }
#sheet-calendar .cal-entry-paid { border-left-color: var(--md-primary); }
#sheet-calendar .cal-entry-name { font-size: 16px; font-weight: 600; color: var(--md-on-surface); }
#sheet-calendar .cal-cif { font-size: 14px; font-weight: 400; color: var(--md-on-surface-variant); }
#sheet-calendar .cal-entry-meta { font-size: 14px; color: var(--md-on-surface-variant); margin-top: 3px; }
#sheet-calendar .cal-entry-note { font-size: 14px; color: var(--md-on-surface-variant); margin-top: 7px; padding: 8px 10px; background: var(--md-surface-variant); border-radius: 10px; }
#sheet-calendar .cal-hist { font-size: 14px; color: var(--md-on-surface-variant); margin-top: 5px; }
#sheet-calendar .cal-entry-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
#sheet-calendar .cal-btn { padding: 9px 16px; border-radius: 999px; border: 1px solid var(--md-outline-variant); background: transparent; color: var(--md-primary); font-size: 14px; font-weight: 600; cursor: pointer; }
#sheet-calendar .cal-btn:hover { background: var(--md-primary-container); border-color: transparent; color: var(--md-on-primary-container); }
#sheet-calendar .cal-btn-paid { background: linear-gradient(135deg, var(--md-primary) 0%, #2fbf60 100%); border-color: transparent; color: var(--md-on-primary); box-shadow: 0 2px 8px rgba(10,143,60,.28); }
#sheet-calendar .cal-btn-paid:hover { background: var(--md-primary); color: var(--md-on-primary); opacity: .92; }
#sheet-calendar .cal-resched { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 11px; padding-top: 11px; border-top: 1px dashed var(--md-outline-variant); font-size: 14px; color: var(--md-on-surface-variant); }
#sheet-calendar .cal-resched input[type="date"] { padding: 9px 12px; border-radius: 12px; border: 1px solid var(--md-outline); background: var(--md-surface); color: var(--md-on-surface); font-size: 14px; }
#sheet-calendar .cal-desc { font-size: 14px; color: var(--md-on-surface-variant); }
@media (max-width: 480px) {
  #sheet-calendar .cal-title { font-size: 18px; min-width: 120px; }
  #sheet-calendar .cal-cell { border-radius: 10px; }
}

/* ===== สรุปหนี้สำหรับแผน (route debt summary) ===== */
.route-debt-summary { margin: 12px 0; }
.route-debt-summary.hidden { display: none !important; }
.rds-card { background: var(--md-surface-container-low); border: 1px solid var(--md-outline-variant); border-radius: 16px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.rds-title { font-size: 16px; font-weight: 700; color: var(--md-on-surface); margin: 0 0 10px; }
.rds-overview { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.rds-stat { background: var(--md-surface-container); border-radius: 12px; padding: 10px 12px; text-align: center; }
.rds-num { display: block; font-size: 18px; font-weight: 700; color: var(--md-primary); line-height: 1.2; }
.rds-label { display: block; font-size: 12px; color: var(--md-on-surface-variant); margin-top: 2px; }
.rds-block { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--md-outline-variant); }
.rds-block-title { font-size: 14px; font-weight: 600; color: var(--md-on-surface); margin-bottom: 6px; }
.rds-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 14px; gap: 8px; }
.rds-row .rds-label { color: var(--md-on-surface-variant); flex: 1; }
.rds-row .rds-val { font-weight: 600; color: var(--md-on-surface); text-align: right; white-space: nowrap; }
.rds-warn .rds-label, .rds-warn .rds-val { color: var(--md-error); }
.rds-ok .rds-label, .rds-ok .rds-val { color: var(--md-primary); }
.rds-perf { background: var(--md-primary-container); border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.rds-perf .rds-block-title { color: var(--md-on-primary-container); }
.rds-perf .rds-row .rds-label { color: var(--md-on-primary-container); }
.rds-perf .rds-row .rds-val { color: var(--md-on-primary-container); font-weight: 700; }
.rds-note { font-size: 14px; color: var(--md-on-surface-variant); padding: 8px; text-align: center; }
@media (prefers-color-scheme: dark) {
  .rds-card { background: var(--md-surface-container-low); }
  .rds-stat { background: var(--md-surface-container); }
  .rds-perf { background: var(--md-primary-container); }
}
@media (max-width: 480px) {
  .rds-overview { grid-template-columns: 1fr; }
  .rds-num { font-size: 16px; }
}

/* ===== UX ง่ายสุด: หน้าแรกงานวันนี้ + คิวเก็บพิกัด + ปุ่มลัด (31 ต.ค.69) ===== */
.today-header h2 { font-size: 20px; margin: 0 0 2px; }
.today-desc { color: var(--md-on-surface-variant, #5b5b52); font-size: 14px; margin: 0 0 10px; }
.pane-divider { border: 0; border-top: 1px solid var(--md-outline-variant, #e0e0e0); margin: 14px 0; }
#gps-collect { margin-bottom: 12px; }
.gps-collect-card { background: var(--md-surface-container-low, #f6f6f0); border: 1px solid var(--md-outline-variant, #e0e0e0); border-radius: 12px; padding: 12px; }
.gps-collect-card h3 { font-size: 16px; margin: 0 0 4px; }
.gps-collect-desc { font-size: 14px; margin: 0 0 8px; }
.gps-progress { height: 10px; border-radius: 999px; background: var(--md-surface-container-high, #e8e8e0); overflow: hidden; margin-bottom: 10px; }
.gps-progress-fill { height: 100%; background: var(--md-primary); border-radius: 999px; transition: width .3s; }
.gps-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--md-outline-variant, #e8e8e0); }
.gps-row-info { flex: 1; min-width: 0; }
.gps-row-name { font-weight: 700; font-size: 15px; }
.gps-row-addr { font-size: 13px; color: var(--md-on-surface-variant, #5b5b52); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gps-row-btn { min-height: 48px; padding: 10px 14px; font-size: 15px; white-space: nowrap; }
.gps-more { font-size: 13px; text-align: center; margin: 6px 0 0; }
.promise-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.promise-chips-label { font-size: 14px; font-weight: 700; }
.chip-btn { min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--md-primary); background: transparent; color: var(--md-primary); font-size: 14px; font-weight: 700; cursor: pointer; }
.chip-btn:active { background: var(--md-primary); color: var(--md-on-primary); }
details.qs-more { margin-top: 10px; }
details.qs-more > summary { min-height: 48px; display: flex; align-items: center; font-size: 15px; font-weight: 700; cursor: pointer; color: var(--md-primary); }
details.qs-more .quick-status-grid { margin-top: 8px; }
details.adv-settings { margin-top: 8px; border: 1px solid var(--md-outline-variant, #e0e0e0); border-radius: 12px; padding: 0 12px 12px; }
details.adv-settings > summary { min-height: 52px; display: flex; align-items: center; font-size: 15px; font-weight: 700; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
  .gps-progress-fill { transition: none; }
}

/* ===== หน้าแรก: ตามหนี้ตามประเภท (การ์ดสไตล์ปฏิทิน) ===== */
.chase-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.today-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.today-filters .mdf-select { width: 100%; min-height: 44px; }
.chase-count { font-size: 13px; font-weight: 700; margin: 4px 0 8px; }

/* ===== Today tab — การ์ด/ปุ่ม/หัวข้อ สไตล์เดียวกับปฏิทิน (31 ต.ค.69) ===== */
#sheet-today .cal-section-title { font-size: 16px; font-weight: 700; color: var(--md-on-surface); margin: 20px 0 8px; }
#sheet-today .cal-entry {
  background: #fff;
  border: 1px solid var(--md-outline-variant, #e6ebe4);
  border-left: 4px solid var(--md-outline, #c9d3c9);
  border-radius: 16px;
  padding: 13px 15px;
  margin: 10px 0;
  box-shadow: 0 1px 3px rgba(60, 64, 67, .08);
  transition: box-shadow .2s ease, transform .2s ease;
}
#sheet-today .cal-entry:hover { box-shadow: 0 4px 14px rgba(60, 64, 67, .14); transform: translateY(-1px); }
#sheet-today .cal-entry-due, #sheet-today .cal-entry-overdue { border-left-color: var(--md-error, #b3261e); }
#sheet-today .cal-entry-upcoming { border-left-color: var(--md-tertiary, #7d5700); }
#sheet-today .cal-entry-paid { border-left-color: var(--md-primary, #0a8f3c); }
#sheet-today .cal-entry-name { font-size: 16px; font-weight: 600; color: var(--md-on-surface); }
#sheet-today .cal-cif { font-size: 14px; font-weight: 400; color: var(--md-on-surface-variant, #5b5b52); }
#sheet-today .cal-entry-meta { font-size: 14px; color: var(--md-on-surface-variant, #5b5b52); margin-top: 3px; }
#sheet-today .cal-entry-note { font-size: 14px; color: var(--md-on-surface-variant, #5b5b52); margin-top: 7px; padding: 8px 10px; background: #f4f7f2; border-radius: 10px; }
#sheet-today .cal-entry-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
#sheet-today .cal-btn { padding: 9px 16px; border-radius: 999px; border: 1px solid var(--md-outline-variant, #e0e0e0); background: #fff; color: var(--md-primary, #0a8f3c); font-size: 14px; font-weight: 600; cursor: pointer; }
#sheet-today .cal-btn:hover { background: var(--md-primary-container, #d7f5e0); border-color: transparent; color: var(--md-on-primary-container, #00391a); }
#sheet-today .cal-btn-paid { background: linear-gradient(135deg, var(--md-primary, #0a8f3c) 0%, #2fbf60 100%); border-color: transparent; color: #fff; box-shadow: 0 2px 8px rgba(10,143,60,.28); }
#sheet-today .cal-btn-paid:hover { background: var(--md-primary, #0a8f3c); color: #fff; opacity: .92; }

/* ตัวกรองละเอียด — การ์ดพับได้ ขาวสะอาด ไม่เป็นกล่องเทา */
.today-filter-card {
  background: #fff;
  border: 1px solid var(--md-outline-variant, #e0e0e0);
  border-radius: 14px;
  padding: 10px 12px 12px;
  margin: 8px 0 12px;
  box-shadow: 0 1px 3px rgba(60, 64, 67, .07);
}
.today-filter-card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font-size: 14px;
  font-weight: 700;
  color: var(--md-on-surface, #1f1f1f);
}
.today-filter-card > summary::-webkit-details-marker { display: none; }
.today-filter-card > summary::after {
  content: '▾';
  margin-left: auto;
  transition: transform .2s ease;
  color: var(--md-on-surface-variant, #5b5b52);
}
.today-filter-card[open] > summary::after { transform: rotate(180deg); }
.today-filter-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--md-primary, #0a8f3c);
  background: #e8f5ec;
  border-radius: 999px;
  padding: 2px 9px;
}
.today-filter-card .today-filters { margin-top: 10px; }
.today-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 0; }
.today-filters .mdf-select { width: 100%; min-height: 42px; font-size: 13px; border-radius: 10px; background-color: #fbfdf9; }
.today-filters .mdf-select:focus { border-color: var(--baac-green, #0a8f3c); box-shadow: 0 0 0 3px rgba(10,143,60,.12); }

/* กล่องคิวเก็บพิกัด — ขาว + ขอบเขียวอ่อน ไม่เป็นกล่องเทา */
.gps-collect-card { background: #fff; border: 1px solid #dcebdd; border-radius: 14px; padding: 12px; box-shadow: 0 1px 3px rgba(60, 64, 67, .06); }
.gps-collect-card h3 { color: var(--md-on-surface, #1f1f1f); }
.gps-progress { background: #eaf2ea; }

/* คิวเก็บพิกัด: ชื่อลูกค้าเด่น ปุ่มกะทัดรัด ไม่เป็นแถบยาวเต็มจอ */
#gps-collect .gps-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
}
#gps-collect .gps-row-info { min-width: 0; }
#gps-collect .gps-row-name { font-size: 14px; line-height: 1.35; }
#gps-collect .gps-row-addr { font-size: 12.5px; }
#gps-collect .gps-row-btn {
  width: auto;
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

/* ===== คิวเก็บพิกัด (Today) — รายละเอียดการ์ด + ปุ่ม Golden Route ===== */
.gps-row-cif { font-size: 12px; font-weight: 500; color: #7a857a; }
.gps-row-meta { font-size: 12.5px; color: #6b756b; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gps-row-ok { font-size: 13px; font-weight: 700; color: #0a8f3c; white-space: nowrap; }
.gps-count { font-size: 13px; font-weight: 700; color: #0a8f3c; background: #e8f5ec; border-radius: 999px; padding: 2px 9px; margin-left: 6px; vertical-align: middle; }
.gps-search { grid-column: 1 / -1; background-image: none; padding-right: 9px; }
.today-golden-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 9px 16px;
  margin: 4px 0 14px;
  border-radius: 999px;
  border: 1px solid #d4b25a;
  background: linear-gradient(135deg, #fff7dd, #ffe9a8);
  color: #6b4e00;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(180, 140, 30, .16);
  width: auto;
}
.today-golden-btn:active { transform: translateY(1px); }
#btn-auto-plan.flash { animation: goldenFlash 1.8s ease; }
@keyframes goldenFlash {
  0%, 100% { box-shadow: none; }
  30%, 60% { box-shadow: 0 0 0 4px rgba(255, 193, 7, .55); }
}

/* ที่อยู่ในคิวเก็บพิกัด — ให้ขึ้นบรรทัดใหม่ได้ ไม่ตัดจังหวัดทิ้ง */
#gps-collect .gps-row-addr,
#gps-collect .gps-row-meta {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.35;
}

/* แบ่งหน้าคิวเก็บพิกัด — หน้าละ 10 ราย */
.gps-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e6ebe4;
}
.gps-page-btn {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #cfe0d2;
  background: #fff;
  color: #0a8f3c;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.gps-page-btn:disabled { opacity: .4; cursor: default; }
.gps-pager-info { flex: 1; text-align: center; font-size: 12px; line-height: 1.35; color: #5b6b5b; }

/* เปิดการ์ดลูกหนี้บนแผนที่ → ซ่อนปุ่มควบคุมชั่วคราว กันปุ่มทับข้อมูล */
body.card-open .leaflet-control,body.card-open .map-fab{opacity:0!important;pointer-events:none!important;transition:opacity .15s}

/* ===== สรุปแผนสั้น บนสุดของแท็บวางแผน (15 พ.ย.69) ===== */
.plan-quick{position:sticky;top:6px;z-index:6;margin:10px 12px 2px;padding:10px 12px 11px;border-radius:14px;
  background:linear-gradient(135deg,#0f5132 0%,#166534 100%);color:#fff;
  box-shadow:0 6px 16px rgba(15,81,50,.22)}
.plan-quick.hidden{display:none}
.pq-top{display:flex;justify-content:space-between;align-items:baseline;font-size:14px}
.pq-top b{font-weight:600;letter-spacing:.2px}
.pq-top span{font-size:13px;opacity:.9}
.pq-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;margin-top:9px}
.pq-cell{display:flex;flex-direction:column;align-items:center;line-height:1.15}
.pq-num{font-size:18px;font-weight:700;color:#fde68a;font-variant-numeric:tabular-nums}
.pq-num.warn{color:#fecaca}
.pq-lbl{font-size:13px;opacity:.88;margin-top:3px}
@media(max-width:380px){.pq-num{font-size:16px}.pq-lbl{font-size:12px}}

/* มือถือ: แผงครึ่งจอ → ปุ่มซูมทับการ์ดสรุปแผน ให้ซ่อนปุ่มซูม (ยังใช้ pinch ได้) */
@media (max-width: 767px) {
  /* แผงยกขึ้น (half/full) → ซ่อนปุ่มลอยบนแผนที่ทั้งหมด กันทับการ์ดสรุป/แท็บ */
  body:has(.bottom-sheet.sheet-half) .map-fab,
  body:has(.bottom-sheet.sheet-full) .map-fab { display: none; }
}

/* ปุ่ม "รายละเอียดหนี้" ในสรุปแผน + เอฟเฟกต์ตอนเลื่อนมาโชว์ */
.pq-link{background:rgba(255,255,255,.16);border:1px solid rgba(255,255,255,.35);color:#fff;
  font-size:12.5px;padding:3px 9px;border-radius:999px;margin-left:auto;margin-right:8px;line-height:1.4}
.pq-link:active{background:rgba(255,255,255,.28)}
.plan-quick.flash{animation:pqFlash 1.4s ease-out}
@keyframes pqFlash{0%{box-shadow:0 0 0 0 rgba(253,230,138,.9)}70%{box-shadow:0 0 0 14px rgba(253,230,138,0)}100%{box-shadow:0 6px 16px rgba(15,81,50,.22)}}

/* จอเล็กมาก (iPhone SE 320px): 5 แท็บย่อชื่อแล้วให้พอดีจอโดยไม่ต้องเลื่อนแนวนอน */
@media (max-width: 360px) {
  .sheet-tabs { padding: 0 4px; }
  .sheet-tab { padding-left: 4px; padding-right: 4px; gap: 3px; }
}

/* จอเล็กมาก: ย่อระยะห่าง/จำนวนบรรทัดของแถบ — สี การ์ด ปุ่ม ฟอนต์เหมือนเดิมทุกอย่าง */
@media (max-width: 360px) {
  .app-header.app-header-overlay { padding-top: 8px; padding-bottom: 6px; }
  #promise-alert { padding: 7px 8px; gap: 5px; }
  #promise-alert .pa-text { flex-direction: column; align-items: flex-start; gap: 1px; }
  #promise-alert .pa-text b { white-space: nowrap; line-height: 1.3; }
  #promise-alert .pa-text span { display: block; white-space: nowrap; }
  #promise-alert .pa-btn { min-height: 44px; padding: 0 10px; }
  #promise-alert .pa-close { width: 44px; height: 44px; }
  .map-debt-filter { padding: 6px; gap: 4px; }
  .mdf-search-row { padding: 2px 2px 0; margin-bottom: 2px; }
  .mdf-search-row input { padding: 5px 0; font-size: 14px; }
  .mdf-plan { min-height: 44px; padding: 0 4px; }
  .mdf-gps-gauge { padding: 0 2px; }
}
