/* ── Mobile-First Overrides ──
   Loaded on all user-facing pages.
   Desktop is untouched — all rules are inside @media queries.
   Breakpoints: 480px (phone), 768px (tablet)
*/

/* Prevent horizontal overflow globally */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
}

/* ── Sidebar: shared styles (desktop + mobile drawer) ── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9998;
}
.drawer-overlay.open { display: block; }

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100%;
  background: #1a1a2e;
  z-index: 9999;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.drawer-header {
  background: #4E2A84;
  padding: 18px 16px 14px;
  position: relative;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.drawer-header h2 {
  color: #fff;
  font-family: 'Montserrat', sans-serif;
  font-size: 15px;
  font-weight: 800;
}
.drawer-close {
  position: absolute;
  top: 14px;
  right: 12px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.drawer-links {
  padding: 8px 0;
}
.drawer-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  color: #ccc;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  transition: background 0.1s;
}
.drawer-link:hover,
.drawer-link:active {
  background: rgba(255,255,255,0.05);
}
.drawer-link.active {
  color: #D4A373;
  background: rgba(212,163,115,0.08);
  border-left: 3px solid #D4A373;
  padding-left: 15px;
}
.drawer-link svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}
.drawer-link.gold { color: #D4A373; }
.drawer-link.logout-link { color: #e57373; }
.drawer-link.logout-link:hover { background: rgba(229,115,115,0.1); }

.drawer-divider {
  height: 1px;
  background: #2a2a4a;
  margin: 8px 16px;
}

.drawer-lang-toggle {
  display: block;
  margin: 8px 18px 16px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}

/* ── Desktop: sidebar always visible ── */
@media (min-width: 769px) {
  .drawer-toggle { display: none; }
  .drawer-close { display: none; }

  /* Hide inline topbar nav — sidebar replaces it */
  .topbar-nav { display: none !important; }

  /* Shift topbar and content to the right of sidebar */
  .topbar { margin-left: 220px; }
  .page, .container, .main-content, .page-content { margin-left: 220px; }

  /* Trial banner needs to clear the sidebar too */
  .trial-banner { margin-left: 220px; }
}

/* ── Tablet: narrower sidebar ── */
@media (min-width: 601px) and (max-width: 768px) {
  .drawer-toggle { display: none; }
  .drawer-close { display: none; }
  .topbar-nav { display: none !important; }

  .side-drawer { width: 200px; }
  .topbar { margin-left: 200px; }
  .page, .container, .main-content, .page-content { margin-left: 200px; }
  .trial-banner { margin-left: 200px; }
}

/* ── Mobile: hamburger drawer ── */
@media (max-width: 600px) {
  .side-drawer {
    left: -280px;
    width: 270px;
    transition: left 0.25s ease;
  }
  .side-drawer.open { left: 0; }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .topbar-left {
    width: 100%;
    justify-content: space-between;
    display: flex;
    align-items: center;
  }

  .topbar h1 { font-size: 16px; }
  .topbar-user { font-size: 12px; }

  /* Hide the inline nav on mobile — drawer replaces it */
  .topbar-nav { display: none !important; }

  /* Drawer toggle button */
  .drawer-toggle {
    display: flex;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
  }

  .new-chat-btn {
    padding: 10px 6px;
    min-height: 40px;
    font-size: 12px;
  }
}

/* ── Streak widget: fit in topbar ── */
@media (max-width: 600px) {
  .streak-widget {
    padding: 2px 6px;
    margin-right: 4px;
    font-size: 13px;
  }

  .streak-count {
    font-size: 12px;
  }

  .streak-flame {
    font-size: 15px;
  }
}

/* ── Streak popup: fit on phone screens ── */
@media (max-width: 480px) {
  .streak-popup {
    width: 94%;
    max-width: none;
    padding: 20px 16px;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 12px;
  }

  .streak-popup h3 {
    font-size: 32px;
  }

  .streak-popup .streak-label {
    font-size: 16px;
  }

  .streak-calendar {
    max-width: 240px;
    gap: 2px;
  }

  .streak-popup-close {
    top: 8px;
    right: 10px;
    font-size: 24px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .streak-freeze-btn {
    padding: 12px 20px;
    min-height: 44px;
    font-size: 14px;
  }

  .streak-toast {
    width: 90%;
    left: 5%;
    transform: translateX(0) translateY(-60px);
    text-align: center;
    font-size: 14px;
    padding: 12px 16px;
  }

  .streak-toast.show {
    transform: translateX(0) translateY(0);
  }
}

/* ── AI Chat: prevent overflow, better mobile layout ── */
@media (max-width: 600px) {
  .chat-container {
    padding: 0 8px;
  }

  .msg-bubble {
    max-width: 92%;
    padding: 10px 14px;
    font-size: 14px;
  }

  .message {
    gap: 8px;
  }

  .msg-avatar {
    width: 28px;
    height: 28px;
    font-size: 10px;
    flex-shrink: 0;
  }

  .input-row textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px;
    max-height: 80px;
  }

  .input-row button {
    padding: 10px 14px;
    min-height: 44px;
    font-size: 14px;
  }

  .input-area {
    padding: 10px 0 16px;
  }

  .input-footer {
    font-size: 11px;
  }

  .analyze-btn {
    padding: 14px 24px;
    font-size: 15px;
  }

  .quick-chips {
    max-width: 100%;
  }

  .quick-chip {
    font-size: 12px;
    padding: 8px 12px;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
  }

  .welcome-title {
    font-size: 20px;
  }

  .welcome-sub {
    font-size: 13px;
    padding: 0 8px;
  }
}

/* ── AI Support: single column prompts on phone ── */
@media (max-width: 520px) {
  .prompt-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Dashboard: responsive form fields ── */
@media (max-width: 600px) {
  .container {
    padding: 16px 10px 40px;
  }

  .card {
    padding: 16px 12px;
  }

  .form-field.narrow input {
    width: 100%;
  }

  .stream-fields .sf {
    min-width: 0;
    flex: 1 1 100%;
  }

  .form-row {
    flex-direction: column;
    gap: 8px;
  }
}

/* ── Profile: full-width tier inputs ── */
@media (max-width: 600px) {
  .form-group {
    min-width: 0;
    flex: 1 1 100%;
  }

  .tier-name input,
  .tier-price input {
    width: 100% !important;
  }
}

/* ── Journey: bigger checkboxes, safe toast ── */
@media (max-width: 600px) {
  .milestone-check {
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .stage-header {
    padding: 14px 12px;
  }

  .celebrate-toast {
    top: max(24px, env(safe-area-inset-top, 24px));
    left: 5%;
    right: 5%;
    transform: none;
    text-align: center;
  }
}

/* ── Schedule: summary cards stack on phone ── */
@media (max-width: 480px) {
  .summary-row {
    grid-template-columns: 1fr;
  }

  .slot-editor {
    width: 94vw;
    max-width: none;
  }

  .cal-scroll {
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Start page: bigger action buttons ── */
@media (max-width: 600px) {
  .btn-action {
    padding: 12px 20px;
    font-size: 14px;
    min-height: 44px;
  }
}

/* ── Global: minimum touch targets ── */
@media (max-width: 768px) {
  button, .btn, [role="button"] {
    min-height: 36px;
  }
}

/* ── Safe area: notched phones ── */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .input-area {
      padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
  }
}
