/* ==========================================================================
   Seahawk Yacht Charters — Leads Mini App
   Theme: adapts to Telegram's theme params / colour scheme, with a
   restrained nautical accent (deep navy + sea-glass teal) layered on top.
   ========================================================================== */

:root {
  /* --- Telegram theme vars, with sane light-mode fallbacks for when the
     page is opened outside Telegram (dev/preview) --- */
  --tg-bg: var(--tg-theme-bg-color, #f6f5f1);
  --tg-text: var(--tg-theme-text-color, #101b26);
  --tg-hint: var(--tg-theme-hint-color, #7c8791);
  --tg-link: var(--tg-theme-link-color, #1c8f82);
  --tg-button: var(--tg-theme-button-color, #0c2438);
  --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #eceae3);
  --tg-section-bg: var(--tg-theme-section-bg-color, #ffffff);
  --tg-section-header: var(--tg-theme-section-header-text-color, #6b7680);
  --tg-destructive: var(--tg-theme-destructive-text-color, #d64545);

  /* --- Seahawk nautical accent palette --- */
  --sea-navy: #0c2438;
  --sea-navy-deep: #071523;
  --sea-teal: #1c9c8c;
  --sea-teal-soft: rgba(28, 156, 140, 0.14);
  --sea-amber: #c98a34;
  --sea-amber-soft: rgba(201, 138, 52, 0.16);
  --sea-green: #3d9660;
  --sea-green-soft: rgba(61, 150, 96, 0.16);
  --sea-muted: #8a8f97;
  --sea-muted-soft: rgba(138, 143, 151, 0.16);
  --sea-off-white: #f6f5f1;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgba(7, 21, 35, 0.04), 0 6px 16px rgba(7, 21, 35, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Mobile-first: this is a phone-shaped app. On wider screens (desktop
     preview, tablets) it stays a centered phone-width column rather than
     stretching full-bleed. */
  --app-max-width: 560px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* we draw our own :active feedback instead */
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  /* letterboxing either side of the centered column on wide viewports */
  background: var(--sea-navy-deep);
}

body {
  max-width: var(--app-max-width);
  margin: 0 auto;
  font-family: var(--font);
  background: var(--tg-bg);
  color: var(--tg-text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  overflow-x: hidden; /* guard against any stray wide element causing horizontal scroll */
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* Momentum scrolling on older iOS WebViews (modern ones do this natively,
   this is a harmless no-op there). */
html, body, .chip-row {
  -webkit-overflow-scrolling: touch;
}

/* -------------------------------------------------------------------- */
/* Config warning (dev aid — only shows if config.js is unedited)        */
/* -------------------------------------------------------------------- */

.config-warning {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--sea-amber-soft);
  color: var(--sea-amber);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

/* -------------------------------------------------------------------- */
/* Preview banner (dev aid — only shows with ?preview=1)                  */
/* -------------------------------------------------------------------- */

.preview-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--sea-teal-soft);
  color: var(--sea-teal);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

.preview-banner-close {
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1;
  opacity: 0.75;
}

.preview-banner-close:active { opacity: 1; }

/* -------------------------------------------------------------------- */
/* Fallback (opened outside Telegram)                                    */
/* -------------------------------------------------------------------- */

.fallback-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: linear-gradient(180deg, var(--sea-navy) 0%, var(--sea-navy-deep) 100%);
}

.fallback-card {
  max-width: 360px;
  text-align: center;
  color: #f2f5f6;
}

.fallback-card .brand-mark--lg {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  color: var(--sea-teal);
}

.fallback-card h1 {
  font-size: 22px;
  margin: 0 0 10px;
  font-weight: 700;
}

.fallback-card p {
  font-size: 15px;
  line-height: 1.5;
  color: rgba(242, 245, 246, 0.75);
  margin: 0;
}

/* -------------------------------------------------------------------- */
/* App shell                                                              */
/* -------------------------------------------------------------------- */

.app-root {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 20px;
  background: linear-gradient(135deg, var(--sea-navy) 0%, var(--sea-navy-deep) 100%);
  color: #f2f5f6;
  flex-shrink: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  color: var(--sea-teal);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-mark svg { width: 100%; height: 100%; }

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: rgba(242, 245, 246, 0.65);
}

.view {
  flex: 1;
  min-height: 0;
  padding: 16px 16px 32px;
}

/* -------------------------------------------------------------------- */
/* Search + filters                                                       */
/* -------------------------------------------------------------------- */

.search-row {
  position: relative;
  margin-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--tg-hint);
  font-size: 16px;
  pointer-events: none;
}

#search-input {
  width: 100%;
  border: none;
  outline: none;
  background: var(--tg-section-bg);
  border-radius: var(--radius-md);
  padding: 12px 14px 12px 36px;
  font-size: 16px; /* iOS: <16px inputs trigger an auto-zoom on focus */
  min-height: 44px;
  box-shadow: var(--shadow-card);
  -webkit-appearance: none;
}

#search-input::placeholder { color: var(--tg-hint); }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  margin: 0 -2px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  min-height: 44px; /* thumb-friendly touch target */
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

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

.chip.is-active {
  background: var(--sea-navy);
  color: #f2f5f6;
}

.list-summary {
  font-size: 12.5px;
  color: var(--tg-hint);
  padding: 0 4px 10px;
}

/* -------------------------------------------------------------------- */
/* Lead list                                                              */
/* -------------------------------------------------------------------- */

.lead-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lead-row {
  min-height: 64px; /* touch target + must match .skeleton-card height exactly (no layout shift) */
  background: var(--tg-section-bg);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

.lead-row:active { transform: scale(0.985); opacity: 0.9; }

.lead-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lead-name {
  font-size: 16px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--tg-hint);
}

.lead-row-meta .dot::before {
  content: "·";
  margin-right: 8px;
}

.lead-row-status-col {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.pill {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.lead-row-amount {
  font-size: 12px;
  font-weight: 700;
  color: var(--sea-green);
  white-space: nowrap;
}

.load-more {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  padding: 12px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 14.5px;
  font-weight: 600;
}

.load-more:active { opacity: 0.8; }

/* -------------------------------------------------------------------- */
/* Empty state                                                           */
/* -------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--tg-hint);
}

.empty-state .anchor-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 14px;
  color: var(--tg-hint);
  opacity: 0.6;
}

.empty-state .anchor-icon svg { width: 100%; height: 100%; }

.empty-state p {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.5;
}

/* -------------------------------------------------------------------- */
/* Skeletons                                                              */
/* -------------------------------------------------------------------- */

.skeleton-card {
  height: 64px; /* matches .lead-row's min-height exactly — avoids layout shift on load */
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--tg-secondary-bg) 25%, var(--tg-section-bg) 37%, var(--tg-secondary-bg) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  margin-bottom: 10px;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--tg-secondary-bg) 25%, var(--tg-section-bg) 37%, var(--tg-secondary-bg) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* -------------------------------------------------------------------- */
/* Detail view                                                            */
/* -------------------------------------------------------------------- */

#detail-content {
  /* clears the fixed compose bar at the bottom — it's taller now (a real
     multi-line textarea, growing further, plus an optional note-prompt
     banner), so this is a generous fixed estimate rather than a precise
     measurement — simple and safe for a no-build vanilla app. */
  padding-bottom: 280px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
}

.back-link {
  flex-shrink: 0;
  border: none;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  width: 44px; /* thumb-friendly touch target */
  height: 44px;
  border-radius: 50%;
  font-size: 19px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-link:active { opacity: 0.7; }

.detail-title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.detail-title p {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--tg-hint);
}

.contact-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.contact-link {
  flex: 1;
  min-width: 0; /* let a long phone/email wrap instead of forcing the row wider than the viewport */
  min-height: 48px; /* thumb-friendly touch target */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  text-decoration: none;
  background: var(--tg-section-bg);
  color: var(--sea-teal);
  border-radius: var(--radius-md);
  padding: 13px 10px;
  font-size: 13.5px;
  font-weight: 650;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow-card);
}

.contact-link:active { opacity: 0.75; }

.section-block {
  margin-bottom: 22px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tg-section-header);
  margin: 0 0 10px 2px;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-chip {
  min-height: 48px; /* large, thumb-friendly buttons — not tiny tags */
  display: inline-flex;
  align-items: center;
  border: none;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 700;
  transition: transform 0.1s ease, filter 0.1s ease;
}

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

.status-chip.is-current { box-shadow: inset 0 0 0 2px currentColor; }

.status-meta {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--tg-hint);
}

.sold-amount-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: none;
  background: var(--sea-green-soft);
  color: var(--sea-green);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 700;
  text-align: left;
}

.sold-amount-row:active { opacity: 0.8; }

.sold-amount-row--empty {
  background: var(--tg-section-bg);
  color: var(--tg-hint);
  box-shadow: var(--shadow-card);
}

.sold-amount-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.sold-amount-text { flex: 1; }

.sold-amount-edit-hint {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 650;
  opacity: 0.75;
  text-decoration: underline;
}

.field-list {
  background: var(--tg-section-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Stacked, not side-by-side: question labels are often long ("Our charters
   start at $1,000/hour, does that work for your budget?") and a shared-row
   label+value layout leaves no room for the answer and can push content
   past the viewport width. Question on its own full-width line, answer
   below it — both wrap cleanly and never overflow horizontally. */
.field-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px;
  border-bottom: 1px solid var(--tg-secondary-bg);
}

.field-row:last-child { border-bottom: none; }

.field-label {
  color: var(--tg-hint);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.field-value {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.note-card {
  background: var(--tg-section-bg);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
}

.note-meta {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--tg-hint);
  margin-bottom: 4px;
}

.note-text {
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.notes-empty {
  font-size: 13.5px;
  color: var(--tg-hint);
  padding: 10px 2px;
}

/* Sticky bottom compose bar: primary actions live in the thumb zone, not
   buried at the end of a long scroll. Fixed (not sticky) so it stays
   pinned to the viewport regardless of how tall the notes list gets, and
   centered to match the app's phone-width column on wider screens. This is
   in addition to the Telegram MainButton wiring in app.js — belt and
   braces, since MainButton isn't guaranteed to be equally discoverable in
   every client. */
.compose-row {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--app-max-width);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--tg-bg);
  border-top: 1px solid var(--tg-secondary-bg);
  box-shadow: 0 -2px 12px rgba(7, 21, 35, 0.06);
}

.compose-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#note-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--tg-section-bg);
  box-shadow: var(--shadow-card);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 16px; /* iOS: <16px inputs trigger an auto-zoom on focus */
  line-height: 1.4;
  min-height: 88px; /* ~3-4 visible rows, a real compose area rather than a one-liner */
  max-height: 168px; /* ~6 rows — keep in sync with the JS auto-grow cap in renderDetail() */
}

#note-input::placeholder { color: var(--tg-hint); }

.send-btn {
  flex-shrink: 0;
  border: none;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border-radius: var(--radius-md);
  padding: 0 18px;
  height: 44px;
  font-size: 14px;
  font-weight: 650;
}

.send-btn:disabled { opacity: 0.45; }
.send-btn:active:not(:disabled) { opacity: 0.85; }

/* -------------------------------------------------------------------- */
/* Toast                                                                  */
/* -------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: calc(100% - 32px);
  max-width: calc(var(--app-max-width) - 32px);
  z-index: 100;
  background: var(--sea-navy-deep);
  color: #f2f5f6;
  border-radius: var(--radius-md);
  padding: 13px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(7, 21, 35, 0.28);
  font-size: 13.5px;
  animation: toast-in 0.18s ease;
}

/* detail view has its own fixed bottom compose bar — lift the toast clear
   of it so a failure toast (e.g. a bad status change) never overlaps it */
body.detail-active .toast {
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.toast-msg { flex: 1; line-height: 1.4; }

.toast-retry {
  flex-shrink: 0;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: none;
  background: var(--sea-teal);
  color: #06231f;
  font-weight: 700;
  font-size: 12.5px;
  padding: 7px 14px;
  border-radius: 999px;
}

.toast-close {
  flex-shrink: 0;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: rgba(242, 245, 246, 0.6);
  font-size: 16px;
  line-height: 1;
}

/* -------------------------------------------------------------------- */
/* Amount sheet (bottom sheet — "how much was it sold for?")             */
/* -------------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(7, 21, 35, 0.45);
}

.sheet-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-width);
  z-index: 200;
  background: var(--tg-section-bg);
  border-radius: 20px 20px 0 0;
  padding: 22px 20px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(7, 21, 35, 0.3);
  animation: sheet-in 0.2s ease;
}

@keyframes sheet-in {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}

.sheet-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.amount-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.amount-prefix {
  font-size: 20px;
  font-weight: 700;
  color: var(--tg-hint);
}

#amount-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 20px; /* also comfortably clears the iOS 16px auto-zoom threshold */
  font-weight: 700;
  min-height: 44px;
}

#amount-input::placeholder { color: var(--tg-hint); font-weight: 700; }

/* Multi-line textarea variant used by the note-prompt sheet — same sheet
   chrome as the amount input above, sized like the sticky composer's
   textarea (3-4 rows, growing further, never below the iOS auto-zoom
   threshold). */
.sheet-textarea {
  display: block;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 16px;
  line-height: 1.4;
  min-height: 88px;
  max-height: 168px;
  margin-bottom: 16px;
}

.sheet-textarea::placeholder { color: var(--tg-hint); }

.sheet-actions {
  display: flex;
  gap: 10px;
}

.sheet-btn {
  flex: 1;
  min-height: 50px; /* generous, thumb-friendly — this is a primary flow action */
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
}

.sheet-btn-secondary {
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
}

.sheet-btn-primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

.sheet-btn:active:not(:disabled) { opacity: 0.85; }
.sheet-btn:disabled { opacity: 0.45; }

/* -------------------------------------------------------------------- */
/* Contact sheet (bottom sheet — Call/Email with a Copy fallback)        */
/* -------------------------------------------------------------------- */

.action-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-row {
  min-height: 50px; /* thumb-friendly touch target — a primary flow action */
  border: none;
  border-radius: var(--radius-md);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 15px;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding: 10px 14px;
}

.action-row:active { opacity: 0.85; }

.action-row--cancel {
  background: transparent;
  color: var(--tg-hint);
  font-weight: 600;
}

/* -------------------------------------------------------------------- */
/* Small screens                                                          */
/* -------------------------------------------------------------------- */

@media (max-width: 340px) {
  .contact-row { flex-direction: column; }
}
