/* ===== APP LAYOUT ===== */
.app-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(14, 17, 23, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  text-decoration: none;
  flex-shrink: 0;
}
.app-nav-brand:hover { color: var(--accent); }

.app-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}
.app-nav-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--fg-2);
  transition: all 0.15s;
  white-space: nowrap;
}
.app-nav-links a:hover { color: var(--fg); background: var(--bg-3); }
.app-nav-links a.active { color: var(--accent); background: var(--accent-dim); }
.app-nav-links a svg { width: 15px; height: 15px; }

/* Hamburger button — hidden on desktop */
.app-hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  color: var(--fg-2);
  transition: all 0.15s;
}
.app-hamburger:hover { color: var(--fg); border-color: var(--fg-3); }
.app-hamburger svg { display: block; }

/* Mobile nav overlay */
.app-nav-links-mobile {
  display: none;
  position: fixed;
  inset: 60px 0 0 0;
  background: rgba(14,17,23,0.97);
  backdrop-filter: blur(16px);
  z-index: 99;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 20px 20px;
  overflow-y: auto;
}
.app-nav-links-mobile.open { display: flex; }
.app-nav-links-mobile a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--fg-2);
  transition: all 0.15s;
  border: 1px solid transparent;
}
.app-nav-links-mobile a:hover { color: var(--fg); background: var(--bg-3); }
.app-nav-links-mobile a.active { color: var(--accent); background: var(--accent-dim); border-color: rgba(0,229,195,0.2); }
.app-nav-links-mobile a svg { width: 18px; height: 18px; }

.app-main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 20px;
}

/* ===== CARDS / PANELS ===== */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg);
}
.panel-subtitle {
  font-size: 0.8rem;
  color: var(--fg-2);
  margin-top: 2px;
}

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--fg-2);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--fg);
  font-family: var(--font-body);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input::placeholder { color: var(--fg-3); }
.form-textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font-display);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; }
.btn-accent {
  background: var(--accent);
  color: #0a0e14;
}
.btn-accent:hover { background: #00ffdd; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,229,195,0.25); }
.btn-ghost {
  background: transparent;
  color: var(--fg-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--fg); border-color: var(--fg-3); background: var(--bg-3); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-danger { background: #ff4d4d; color: white; }
.btn-danger:hover { background: #ff6b6b; transform: translateY(-1px); }

/* ===== LINE ITEMS TABLE ===== */
.line-items { width: 100%; border-collapse: collapse; }
.line-items th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  border-bottom: 1px solid var(--border);
}
.line-items th:last-child, .line-items th:nth-child(n+2) { text-align: right; }
.line-items td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--fg);
  vertical-align: middle;
}
.line-items td:nth-child(n+2) { text-align: right; }
.line-items tr:last-child td { border-bottom: none; }
.line-items input {
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 0.88rem;
  width: 100%;
  padding: 4px 0;
}
.line-items input:focus { outline: none; }
.line-items input[type="number"] { text-align: right; }
.line-items .remove-btn {
  background: none;
  border: none;
  color: var(--fg-3);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
}
.line-items .remove-btn:hover { color: #ff4d4d; background: rgba(255,77,77,0.1); }
.line-items tfoot td {
  border-top: 1px solid var(--border);
  padding: 14px 12px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg);
}

/* ===== MAP AREA ===== */
.map-container {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.map-toolbar .tool-label {
  font-size: 0.78rem;
  color: var(--fg-3);
  font-weight: 500;
  margin-right: 4px;
}
.map-toolbar .tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.15s;
}
.map-toolbar .tool-btn:hover { color: var(--fg); border-color: var(--fg-3); }
.map-toolbar .tool-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.map-toolbar .tool-btn svg { width: 14px; height: 14px; }
.map-area {
  width: 100%;
  height: 480px;
  position: relative;
  cursor: crosshair;
}
#map-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ===== CALLOUT / ALERTS ===== */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 16px;
}
.callout-info { background: var(--accent-dim); border: 1px solid rgba(0,229,195,0.2); color: var(--fg-2); }
.callout-success { background: rgba(40,202,65,0.12); border: 1px solid rgba(40,202,65,0.2); color: #28ca41; }
.callout-error { background: rgba(255,77,77,0.12); border: 1px solid rgba(255,77,77,0.2); color: #ff6b6b; }
.callout svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

/* ===== PROFILE CARD ===== */
.profile-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-3);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.profile-card:hover { border-color: var(--accent); }
.profile-avatar {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-info { flex: 1; min-width: 0; }
.profile-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-contact {
  font-size: 0.78rem;
  color: var(--fg-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-badge {
  font-size: 0.72rem;
  color: var(--fg-3);
  padding: 4px 10px;
  background: var(--bg-2);
  border-radius: 100px;
  border: 1px solid var(--border);
}

/* ===== QUOTE CARDS ===== */
.quotes-list { display: flex; flex-direction: column; gap: 12px; }
.quote-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.quote-card:hover { border-color: var(--accent); background: var(--bg-2); }
.quote-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.quote-card-icon svg { width: 20px; height: 20px; color: var(--accent); }
.quote-card-info { flex: 1; min-width: 0; }
.quote-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quote-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--fg-3);
}
.quote-card-amount {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  margin-left: auto;
  white-space: nowrap;
}
.quote-card-delete {
  margin-left: 8px;
  background: none;
  border: none;
  color: var(--fg-3);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.quote-card-delete:hover { color: #ff4d4d; background: rgba(255,77,77,0.1); }

/* ===== SESSION INDICATOR ===== */
.session-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--fg-3);
}
.session-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #28ca41;
  box-shadow: 0 0 6px #28ca41;
  animation: pulse 2s ease-in-out infinite;
}
.session-dot.saving { background: #ffbd2e; box-shadow: 0 0 6px #ffbd2e; }

/* ===== STICKY FOOTER BAR ===== */
.sticky-bar {
  position: sticky;
  bottom: 0;
  background: rgba(14,17,23,0.9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 50;
}
.sticky-bar-left { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; color: var(--fg-2); }
.sticky-bar-right { display: flex; align-items: center; gap: 10px; }

/* ===== GRID LAYOUTS ===== */
.app-grid-2 {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}
.app-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ===== RESPONSIVE ===== */
/* Line items table — horizontal scroll on all screen sizes */
.line-items-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

@media (max-width: 900px) {
  .app-grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .app-grid-3 { grid-template-columns: 1fr; }
  .app-main { padding: 24px 16px; }
  .map-toolbar { gap: 6px; }
  .map-toolbar .tool-label { display: none; }
  .quote-card { padding: 14px 16px; }
  .save-upgrade-card { flex-direction: column; }
  /* Table column widths — shrink the unit/total cols on tablet */
  .line-items th:nth-child(n+2),
  .line-items td:nth-child(n+2) { width: 80px; min-width: 70px; }
  .line-items th:nth-child(3),
  .line-items td:nth-child(3) { width: 100px; min-width: 85px; }
  .line-items th:last-child,
  .line-items td:last-child { width: 36px; min-width: 36px; }
}

@media (max-width: 600px) {
  .app-hamburger { display: flex; }
  .app-nav-links { display: none; }
  .app-nav { padding: 0 16px; }
  .app-main { padding: 20px 12px; }
  .map-area { height: 280px; }
  .map-toolbar { padding: 8px 12px; }
  .map-toolbar .tool-btn { padding: 4px 8px; font-size: 0.75rem; }
  .map-toolbar .tool-btn svg { display: none; }
  /* Hide layer toggle row on narrow mobile — already wraps but can still overflow */
  .map-layer-row { display: none; }
  .address-search-row { display: none; /* hide address search on small screens */ }
  .panel { padding: 20px 16px; }
  .panel-title { font-size: 0.9rem; }
  .btn { padding: 9px 16px; font-size: 0.85rem; }
  .form-input, .form-select { font-size: 16px; /* prevent iOS zoom on focus */ }
  .line-items { font-size: 0.82rem; }
  .line-items input { font-size: 0.82rem; }
  .quote-card-amount { font-size: 0.9rem; }
  .profile-card { padding: 12px 14px; }
  .profile-avatar { width: 40px; height: 40px; font-size: 1rem; }
  .sticky-bar { padding: 12px 16px; flex-direction: column; gap: 10px; }
  .sticky-bar-left, .sticky-bar-right { width: 100%; justify-content: center; }
  /* quotes page header */
  .quotes-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  /* profile page buttons */
  .profile-actions { flex-direction: column; }
  .profile-actions .btn { width: 100%; justify-content: center; }
  /* Line items — tighter at mobile */
  .line-items { font-size: 0.78rem; }
  .line-items th, .line-items td { padding: 8px 8px; }
  .line-items th:nth-child(n+2),
  .line-items td:nth-child(n+2) { width: 70px; min-width: 60px; }
  .line-items th:nth-child(3),
  .line-items td:nth-child(3) { width: 85px; min-width: 70px; }
  .line-items th:first-child { width: auto; min-width: 80px; }
  .line-items td:first-child { width: auto; min-width: 80px; }
  .line-items th:last-child,
  .line-items td:last-child { width: 30px; min-width: 30px; }
  /* Quick add buttons — smaller on mobile */
  .quick-add-row { gap: 6px; }
  .quick-add-row .btn { padding: 5px 10px; font-size: 0.75rem; }
}

@media (max-width: 480px) {
  .map-area { height: 220px; }
  .btn-accent { font-size: 0.88rem; padding: 10px 18px; }
  .tier-card { padding: 28px 24px; }
  /* Strip map toolbar to essential tools on 480px */
  .map-toolbar .tool-btn:not(:first-child):not(:last-child) { display: none; }
  /* Quote summary panel — collapse to single column */
  .quote-summary-row { flex-direction: column; gap: 8px; }
}

@media (max-width: 600px) {
  .app-hamburger { display: flex; }
  .app-nav-links { display: none; }
  .app-nav { padding: 0 16px; }
  .app-main { padding: 20px 12px; }
  .map-area { height: 280px; }
  .map-toolbar { padding: 8px 12px; }
  .map-toolbar .tool-btn { padding: 4px 8px; font-size: 0.75rem; }
  .map-toolbar .tool-btn svg { display: none; }
  .address-search-row { display: none; /* hide address search on small screens */ }
  .panel { padding: 20px 16px; }
  .panel-title { font-size: 0.9rem; }
  .btn { padding: 9px 16px; font-size: 0.85rem; }
  .form-input, .form-select { font-size: 16px; /* prevent iOS zoom on focus */ }
  .line-items { font-size: 0.82rem; }
  .quote-card-amount { font-size: 0.9rem; }
  .profile-card { padding: 12px 14px; }
  .profile-avatar { width: 40px; height: 40px; font-size: 1rem; }
  .sticky-bar { padding: 12px 16px; flex-direction: column; gap: 10px; }
  .sticky-bar-left, .sticky-bar-right { width: 100%; justify-content: center; }
  /* quotes page header */
  .quotes-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  /* profile page buttons */
  .profile-actions { flex-direction: column; }
  .profile-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
  .map-area { height: 220px; }
  .btn-accent { font-size: 0.88rem; padding: 10px 18px; }
  .tier-card { padding: 28px 24px; }
  .map-layer-row { display: none; }
}

/* ===== SAVE UPGRADE CARD ===== */
.save-upgrade-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  background: linear-gradient(135deg, rgba(0,229,195,0.07), rgba(0,229,195,0.02));
  border: 1px solid rgba(0,229,195,0.25);
  border-radius: 12px;
}
.save-upgrade-icon {
  width: 44px;
  height: 44px;
  background: var(--accent-dim);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.save-upgrade-body { flex: 1; }
.save-upgrade-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  margin-bottom: 4px;
}
.save-upgrade-desc {
  font-size: 0.82rem;
  color: var(--fg-2);
  line-height: 1.5;
}
.save-upgrade-cta { flex-shrink: 0; }

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

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--fg-3);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: 0.4; }
.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-2);
  margin-bottom: 8px;
}
.empty-state p { font-size: 0.85rem; }