/* Базові змінні теми та фірмової кольорової палітри Tiplr */
:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-soft: #fcfcfb;
  --panel-muted: #f4f5f7;
  --text: #1f2937;
  --text-soft: #667085;
  --text-muted: #98a2b3;
  --brand-navy: #171a6a;
  --brand-pink: #ea2f8b;
  --brand-pink-soft: #fff5fa;
  --border: rgba(15, 23, 42, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
  --radius-xl: 28px;
  --radius-lg: 24px;
  --container: 1280px;
  --ready: #1d6b52;
  --loading: #6b7280;
  --error: #8b2e24;
  --user-bubble-bg: #eef2f7;
  --user-bubble-text: #171a6a;
  --assistant-bubble-bg: #ffffff;
  --assistant-bubble-border: rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(237, 51, 133, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(23, 26, 106, 0.08), transparent 30%),
    #f7f7f5;
  color: var(--text);
}
img { display: block; max-width: 100%; height: auto; }
button, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: none; }

.page {
  min-height: 100vh;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
}
.container { width: min(calc(100% - 48px), var(--container)); margin: 0 auto; }
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 24px;
  flex: 1;
  align-items: start;
}
.panel {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-xl);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.05);
}
.sidebar {
  grid-column: 1;
  grid-row: 1;
  min-height: 720px;
  padding: 28px;
  display: flex;
  flex-direction: column;
}
.sidebar-logo-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 18px;
}
.sidebar-logo { width: 128px; height: auto; object-fit: contain; }
.sidebar-claim {
  margin: 12px 0 0;
  color: var(--brand-pink);
  font-size: 1.08rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-align: center;
}
.sidebar-intro {
  margin: 0 auto;
  max-width: 31ch;
  color: var(--text-soft);
  font-size: 0.91rem;
  line-height: 1.5;
  text-align: center;
}

.feature-card,
.prompt-card-light { margin-top: 24px; border-radius: var(--radius-lg); padding: 20px; background: #f8fafc; border: 1px solid var(--border); }
.card-label { margin: 0 0 12px; font-size: 0.95rem; font-weight: 700; color: var(--brand-navy); }
.feature-list,
.example-list-light { margin: 0; padding: 0; list-style: none; }
.feature-list li,
.example-list-light li { font-size: 0.95rem; line-height: 1.65; }
.feature-list li + li,
.example-list-light li + li { margin-top: 8px; }
.feature-list li { color: var(--text-soft); padding-left: 18px; position: relative; }
.feature-list li::before { content: "•"; position: absolute; left: 0; top: 0; color: var(--brand-pink); font-weight: 700; }
.example-list-light li { color: var(--text-soft); cursor: pointer; transition: color 0.15s ease, transform 0.15s ease; padding: 2px 0; }
.example-list-light li:hover { color: var(--brand-pink); transform: translateX(3px); }

.chat-shell {
  grid-column: 2;
  grid-row: 1;
  height: calc(100vh - 96px);
  min-height: 640px;
  display: flex;
  flex-direction: column;
  padding: 24px;
  position: sticky;
  top: 24px;
  overflow: hidden;
}
.chat-panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex: 0 0 auto; }
.chat-heading { margin: 0; font-size: 0.82rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.chat-subheading { margin: 8px 0 0; max-width: 52ch; font-size: 0.98rem; line-height: 1.6; color: var(--text-soft); }
.new-chat-button {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 13px;
  background: #ffffff;
  color: var(--brand-navy);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.new-chat-button:hover {
  border-color: var(--brand-pink);
  color: var(--brand-pink);
  background: var(--brand-pink-soft);
}
.new-chat-button:focus-visible {
  outline: 2px solid var(--brand-pink);
  outline-offset: 2px;
}
.new-chat-button:disabled {
  opacity: 0.45;
  cursor: default;
}
.status-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 86px; padding: 8px 14px; border-radius: 999px; background: rgba(15, 23, 42, 0.06); color: var(--loading); font-size: 0.82rem; font-weight: 700; transition: all 0.2s ease; }
.status-pill[data-mode="ready"] { background: rgba(29, 107, 82, 0.1); color: var(--ready); }
.status-pill[data-mode="error"] { background: rgba(139, 46, 36, 0.1); color: var(--error); }

.chat-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 26px;
  overflow: hidden;
  background: var(--panel-soft);
  border: 1px solid var(--border);
}
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.chat-message { display: flex; gap: 12px; max-width: 86%; animation: messageFadeIn 0.25s ease-out; }
@keyframes messageFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.chat-message.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-message.assistant { align-self: flex-start; }
.message-avatar { width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--panel); border: 1px solid var(--border); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04); overflow: hidden; }
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }
.message-avatar.user-avatar {
  border-radius: 50%;
  background: #eef2f7;
  color: var(--brand-navy);
  font-weight: 800;
  font-size: 0.72rem;
}
.message-bubble { padding: 14px 18px; border-radius: 20px; line-height: 1.6; font-size: 0.98rem; word-break: break-word; }
.chat-message.user .message-bubble {
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
  border: 1px solid rgba(23, 26, 106, .06);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .025);
}
.chat-message.assistant .message-bubble { background: var(--assistant-bubble-bg); color: var(--text); border: 1px solid var(--assistant-bubble-border); border-bottom-left-radius: 4px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03); }
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 { margin: 16px 0 8px; font-weight: 700; color: var(--brand-navy); line-height: 1.3; }
.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child { margin-top: 0; }
.message-bubble h2 { font-size: 1.2rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.message-bubble h3 { font-size: 1.05rem; }
.message-bubble p { margin: 8px 0; }
.message-bubble p:first-child { margin-top: 0; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul,
.message-bubble ol { margin: 8px 0; padding-left: 20px; }
.message-bubble li { margin-bottom: 4px; }
.message-bubble strong { font-weight: 600; color: var(--brand-navy); }
.message-bubble a { color: var(--brand-pink); text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.message-bubble a:hover { color: #c91f73; }

.typing-indicator { display: inline-flex; align-items: center; gap: 5px; padding: 12px 16px; }
.typing-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-pink); opacity: 0.4; animation: typingPulse 1.3s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingPulse { 0%, 100% { opacity: 0.3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }

.travel-phase-controls {
  margin: 12px auto 0;
  padding: 4px;
  display: inline-flex;
  gap: 2px;
  align-items: center;
  align-self: center;
  max-width: calc(100% - 28px);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
}
.travel-phase-button {
  white-space: nowrap;
  padding: 7px 13px;
  border-radius: 999px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.travel-phase-button:hover:not(.is-active) {
  background: var(--brand-pink-soft);
  color: var(--brand-pink);
}
.travel-phase-button.is-active {
  background: var(--brand-navy);
  color: #ffffff;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.18);
}
.travel-phase-button:focus-visible {
  outline: 2px solid var(--brand-pink);
  outline-offset: 2px;
}

.chat-input-bar {
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
}
.chat-input-bar textarea { flex: 1; resize: none; min-height: 44px; max-height: 140px; padding: 10px 16px; border-radius: 16px; border: 1px solid var(--border); background: #ffffff; color: var(--text); font-family: inherit; font-size: 0.96rem; line-height: 1.45; outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.chat-input-bar textarea:focus { border-color: var(--brand-pink); box-shadow: 0 0 0 3px rgba(234, 47, 139, 0.12); }
.chat-send-btn { height: 44px; padding: 0 22px; border-radius: 16px; border: none; background: var(--brand-pink); color: #ffffff; font-family: inherit; font-size: 0.94rem; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.2s ease, opacity 0.2s ease, transform 0.1s ease; }
.chat-send-btn:hover:not(:disabled) { background: var(--brand-navy); }
.chat-send-btn:active:not(:disabled) { transform: scale(0.98); }
.chat-send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.chat-state { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 32px; text-align: center; background: linear-gradient(180deg, rgba(252, 252, 251, 0.96) 0%, rgba(252, 252, 251, 0.92) 100%); }
.chat-state[hidden] { display: none !important; }
.chat-state-inner { max-width: 580px; }
.empty-copy,
#chat-state-message { margin: 0 auto; font-size: 1rem; line-height: 1.7; color: var(--text-soft); }
.retry-button { margin-top: 18px; border: 0; border-radius: 999px; padding: 12px 20px; background: var(--brand-pink); color: #ffffff; font-family: inherit; font-weight: 700; cursor: pointer; transition: background 0.2s ease; }
.retry-button:hover { background: var(--brand-navy); }

.page-footer { text-align: center; font-size: 12px; letter-spacing: 0.02em; line-height: 1.4; color: var(--text-muted); padding: 16px 0 8px; }

/* The Guide is the primary entry point. Workspace navigation is secondary
   on smaller screens but remains one tap away. */
/* On desktop branding remains in the sidebar. Smaller viewports show a
   compact original Tiplr wordmark beside the active Guide/Trip heading. */
.chat-header-identity { min-width: 0; }
.mobile-header-logo,
.mobile-workspace-nav,
.mobile-guide-return { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .chat-shell { grid-column: 1; grid-row: 1; }
  .sidebar { grid-column: 1; grid-row: 2; }
  .mobile-header-logo {
    display: block;
    flex: 0 0 auto;
    width: 152px;
    max-width: 52vw;
    height: auto;
    max-height: 50px;
    object-fit: contain;
  }
  /* Keep branding/actions in one row; the dynamic Guide/Trip subtitle
     belongs on its own readable row, not squeezed beside the wordmark. */
  .chat-panel-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    row-gap: 8px;
    align-items: center;
  }
  .chat-header-identity { display: contents; }
  .mobile-header-logo { grid-column: 1; grid-row: 1; }
  .chat-header-copy { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .chat-panel-header > .new-chat-button {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }
  /* The horizontal Tiplr wordmark is sufficient in Guide mode.
     Keep the active Trip name visible to avoid losing workspace context. */
  .chat-heading:not(.is-trip) { display: none; }
  .chat-subheading {
    display: block;
    margin: 0;
    max-width: none;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-soft);
  }
  .chat-heading.is-trip {
    display: block;
    color: var(--brand-navy);
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
  }
  .chat-heading.is-trip + .chat-subheading { display: block; }
  /* Hide only the duplicate oversized logo; preserve the editorial
     positioning statement in the personal workspace. */
  .sidebar-logo-wrap { display: none; }
  .sidebar-intro {
    display: block;
    max-width: none;
    margin: 3px 0 18px;
    color: var(--text-soft);
    font-size: 0.88rem;
    line-height: 1.55;
    text-align: left;
  }
  .mobile-workspace-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: -4px 0 13px;
  }
  .mobile-workspace-nav a,
  .mobile-guide-return {
    color: var(--brand-navy);
    font-size: 0.78rem;
    font-weight: 750;
    line-height: 1.3;
    text-decoration: none;
    border-radius: 999px;
    padding: 9px 12px;
    background: #fff;
    border: 1px solid var(--border);
  }
  .mobile-workspace-nav a:focus-visible,
  .mobile-guide-return:focus-visible {
    outline: 2px solid var(--brand-pink);
    outline-offset: 2px;
  }
  .mobile-guide-return {
    display: inline-flex;
    align-self: flex-start;
    margin-bottom: 12px;
  }
  #workspace-heading,
  #saved-tips-title,
  #trips-title { scroll-margin-top: 20px; }
  .sidebar,
  .chat-shell { min-height: auto; }
  .sidebar-intro { max-width: none; }
  .chat-shell {
    height: calc(100vh - 40px);
    min-height: 560px;
    position: relative;
    top: auto;
  }
  .chat-stage { min-height: 0; }
}

@media (max-width: 720px) {
  .container { width: min(calc(100% - 24px), var(--container)); }
  .page { padding: 12px 0; }
  .chat-shell,
  .sidebar { padding: 18px; }
  .chat-panel-header {
    column-gap: 10px;
    row-gap: 8px;
    margin-bottom: 11px;
  }
  .mobile-header-logo { width: 136px; }
  .chat-heading {
    color: var(--brand-navy);
    text-transform: none;
    font-size: 1.05rem;
    line-height: 1.25;
    letter-spacing: 0;
    font-weight: 800;
  }
  /* Restore the short explanatory text, but keep it below the logo. */
  .chat-subheading {
    display: block;
    font-size: 0.78rem;
    line-height: 1.45;
  }
  .chat-heading.is-trip + .chat-subheading {
    display: block;
    margin-top: 3px;
    font-size: 0.74rem;
    line-height: 1.3;
  }
  .new-chat-button {
    min-height: 36px;
    padding: 8px 11px;
    white-space: nowrap;
    font-size: 0.74rem;
  }
  .mobile-workspace-nav { margin: 0 0 12px; }
  .chat-shell { height: calc(100vh - 24px); min-height: 520px; padding: 14px; }
  .sidebar { padding: 16px; }
  /* Assistant voice first: position its identity above the response, not in
     a narrow side column. The user's outgoing messages keep their layout. */
  .chat-message { max-width: 96%; }
  .chat-message.assistant {
    width: 100%;
    max-width: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
  }
  .chat-message.assistant .message-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }
  .chat-message.assistant .message-bubble {
    width: 100%;
    min-width: 0;
    border-bottom-left-radius: 20px;
    box-sizing: border-box;
  }
  .chat-message.assistant .message-bubble.typing-indicator {
    width: auto;
  }
  .sidebar .suitcase-card-copy,
  .sidebar .trip-guide-note,
  .sidebar .suitcase-empty,
  .sidebar .account-label {
    color: var(--text-soft);
    font-size: 0.81rem;
    line-height: 1.5;
  }
  .sidebar .account-title { font-size: 0.88rem; }
  .page-footer { padding: 10px 0 16px; }
}

.tip-save-button { color: var(--brand-navy); font-weight: 600; padding: 2px 0; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.tip-save-button:hover { color: var(--brand-pink); }
.tip-save-button:focus-visible { outline: 2px solid var(--brand-pink); outline-offset: 3px; border-radius: 3px; }
.tip-save-button[aria-busy="true"] { cursor: progress; opacity: 0.65; }
.tip-save-feedback { margin-left: 0.5em; font-size: 0.85em; color: var(--brand-navy); }

@media (max-width: 720px) {
  /* iOS browsers zoom the whole page when a focused text field is below
     16px. Keep editable fields at 16px on phones so the layout stays put. */
  .chat-input-bar textarea,
  #auth-email,
  #trip-name {
    font-size: 16px;
  }
}

/* Disable double-tap-to-zoom on taps (quick repeated taps on Save, + or Send
   zoomed the page on iPhone). Pinch-to-zoom stays available. */
html,
button,
a,
.tip-card,
.chat-input-bar {
  touch-action: manipulation;
}
