/* Just One Thought - mobile & small-screen polish (loaded LAST, phones/tablets only).
   Desktop (>900px) is not affected by anything in this file. */

/* ---- Safety nets (all small screens) ------------------------------------------------------------------------- */
@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { overflow-x: clip; }
  img, video, canvas, iframe { max-width: 100%; }
  table { max-width: 100%; }
  .table-scroll, .compare-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* 16px inputs stop iOS/Android WebViews zooming the page when a field is focused. */
  input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]), select, textarea { font-size: 16px !important; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; flex: 0 0 auto; }
  /* Comfortable touch targets. */
  .button, .btn, .text-button, .icon-button, button.slide-btn, .pagination button,
  .app-nav a, .sidebar-bottom > a, .mast-more summary, .mast-more .nav-panel a, .auth-back, .auth-links a,
  .commerce-header nav a, .dashboard-tabs a, .foot-col a, .explore-card, .radio-card, .payment-options label, .format-option { min-height: 44px; }
  .text-button, .icon-button { display: inline-flex; align-items: center; justify-content: center; padding-left: 8px; padding-right: 8px; }
  .icon-button { min-width: 44px; }
  .button, .btn { white-space: normal; text-align: center; }
  a, button, summary, label { -webkit-tap-highlight-color: rgba(192, 57, 143, .15); }
  dialog::backdrop { background: rgba(17, 38, 17, .55); }
}

/* ---- Floating WhatsApp button: smaller, never hides content --------------------------------------------------- */
@media (max-width: 700px) {
  .whatsapp-float { width: 48px; height: 48px; padding: 0 !important; justify-content: center; left: auto !important; right: 14px; bottom: 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
  .whatsapp-float span { display: none !important; }
  .whatsapp-float svg { width: 26px; height: 26px; }
  body { padding-bottom: 72px; }          /* room so the button never covers the last line of any page */
  body.marketing { padding-bottom: 0; }
  body.marketing .foot { padding-bottom: 72px; }
}

/* ---- Public marketing pages ---------------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .mast-inner { gap: 10px; }
  .mast-more summary { padding: 10px 16px; font-size: 12px; }
  .mast-more .nav-panel { max-height: calc(100vh - 90px); max-height: calc(100dvh - 90px); overflow-y: auto; }
  .mast-more .nav-panel a { font-size: 15px; display: flex; align-items: center; }
  .mast-brand .brand-logo { height: 46px; width: auto; }
}
@media (max-width: 560px) {
  /* The "Get started" pill pushed the header 64px past the screen edge; it is in the Menu panel instead. */
  .mast-cta { display: none; }
  .mast-more { margin-left: auto; }
  .wrap { padding-left: 20px; padding-right: 20px; }
  .display { word-break: normal; overflow-wrap: break-word; hyphens: auto; }
  .kicker, .crumbs { font-size: 12px; letter-spacing: .12em; }
  .lede { font-size: 16px; line-height: 1.6; }
  .btn { padding: 14px 20px; font-size: 14px; }
  .foot-grid { grid-template-columns: 1fr 1fr; row-gap: 28px; }
  .foot-brand { grid-column: 1 / -1; }
  .foot-col a { display: flex; align-items: center; font-size: 15px; }
  .foot-bottom { flex-direction: column; align-items: flex-start; gap: 12px; }
  .foot-bottom nav { display: flex; flex-wrap: wrap; gap: 4px 18px; }
  .foot-bottom nav a { display: inline-flex; align-items: center; min-height: 44px; }
  .explore-grid, .contact-grid { grid-template-columns: 1fr; }
  table.compare { font-size: 13px; }
  .compare-wrap { position: relative; }
  .compare-wrap::after { content: 'Swipe to compare \2192'; display: block; text-align: right; font-size: 12px; color: #6b7a6b; padding: 8px 14px; border-top: 1px solid #f3dcea; }
}
@media (max-width: 380px) {
  .wrap { padding-left: 16px; padding-right: 16px; }
  .foot-grid { grid-template-columns: 1fr; }
}

/* ---- Sign in / sign up / PIN ---------------------------------------------------------------------------------- */
@media (max-width: 620px) {
  .auth-story { min-height: 0; padding: 20px 22px 14px; }
  .auth-story h1 br { display: inline !important; }   /* was display:none, which glued words together ("tohave") */
  .auth-story h1 { font-size: 26px; line-height: 1.2; }
  .auth-form-area { padding: 18px 18px 36px; }
  .auth-card { padding: 24px 20px; width: 100%; max-width: 100%; }
  .auth-back { display: inline-flex; align-items: center; font-size: 13px; }
  .auth-links { font-size: 14px; }
  .auth-links a { display: inline-flex; align-items: center; }
  .pin-input { font-size: 22px !important; letter-spacing: .4em; text-align: center; }
  .button.full { min-height: 50px; font-size: 14px; }
}

/* ---- Journal app (signed-in) ---------------------------------------------------------------------------------- */
@media (max-width: 620px) {
  .app-topbar { height: auto; min-height: 60px; padding: 8px 12px; gap: 8px; position: sticky; top: 0; z-index: 20; background: var(--paper, #fffafd); }
  .breadcrumb { font-size: 13px; min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .breadcrumb span { margin: 0 6px; }
  .topbar-right { gap: 8px; flex: 0 0 auto; }
  .topbar-right .connection-status { display: none; }
  .topbar-right .button { font-size: 13px; padding: 10px 14px; min-height: 44px; }
  .mobile-menu { font-size: 22px; min-width: 44px; min-height: 44px; }
  .app-content { padding: 20px 16px 28px; }
  .app-footer { padding: 16px; flex-direction: column; gap: 6px; font-size: 12px; text-align: center; }
  .page-heading { flex-direction: column; gap: 14px; }
  .page-heading h1 { font-size: 32px; line-height: 1.15; }
  .page-heading p:not(.eyebrow) { font-size: 15px; line-height: 1.55; }
  .page-heading > .button { align-self: stretch; }
  .eyebrow { font-size: 11px; letter-spacing: .14em; }
  .fine { font-size: 13px !important; line-height: 1.55; }
  .muted { font-size: 14px; }
  /* streak badge: was 5px text */
  .streak-badge { flex-direction: row; text-align: left; gap: 10px; padding: 10px 14px; min-width: 0; align-self: flex-start; }
  .streak-badge strong { font-size: 15px; }
  .streak-badge small { font-size: 12px; }
  /* daily prompt + mood check-in */
  .daily-prompt { padding: 24px 20px; }
  .daily-prompt h2 { font-size: 24px; line-height: 1.25; }
  .prompt-art { display: none; }
  .daily-prompt .button { min-height: 46px; }
  .mood-checkin { padding: 18px 14px; }
  .mood-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; width: 100%; }
  .mood-options button { min-width: 0; min-height: 64px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
  .mood-options button span { font-size: 24px; }
  .mood-options button small { font-size: 11px; line-height: 1.15; text-align: center; }
  /* entries, filters, calendar */
  .entry-card { min-height: 0; padding: 20px; }
  .entry-card .mood-pill { font-size: 12px; }
  .filter-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; }
  .filter-bar label { font-size: 12px; min-width: 0; }
  .filter-bar .button { grid-column: 1 / -1; height: auto; min-height: 44px; font-size: 14px; }
  .filter-bar .text-button { grid-column: 1 / -1; }
  .search-box input { min-height: 46px; }
  .pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .pagination .button { min-height: 44px; font-size: 13px; }
  .calendar-panel { padding: 12px; }
  .calendar-weekdays span { font-size: 11px; }
  .calendar-grid { gap: 3px; }
  .calendar-grid button, .calendar-empty { min-height: 44px; font-size: 13px; }
  .stats-grid { grid-template-columns: 1fr; gap: 10px; }
  .insights-grid { grid-template-columns: 1fr; }
  .notebooks-grid { grid-template-columns: 1fr; }
  .panel { padding: 20px 16px; }
  .account-grid { gap: 14px; }
  .plan-actions { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
  .plan-actions .button, .plan-actions .text-button { width: 100%; }
  .form-stack label { font-size: 14px; }
  .form-stack input, .form-stack select, .form-stack textarea { min-height: 46px; }
  .form-stack .button { width: 100%; min-height: 48px; font-size: 14px; }
  .readonly-banner { font-size: 13px; padding: 12px 16px; }
  /* editor */
  .editor-header { position: sticky; top: 60px; z-index: 15; background: var(--paper, #fffafd); flex-wrap: nowrap; gap: 8px; padding: 10px 0; }
  .editor-header > div { gap: 8px; min-width: 0; }
  .editor-header .fine { font-size: 12px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
  .editor-header > .text-button { font-size: 13px; }
  .editor-meta { gap: 8px; margin: 18px 0 14px; }
  .editor-meta input, .editor-meta select { max-width: 100%; flex: 1 1 140px; min-height: 44px; padding: 8px 10px; }
  .entry-title-input { font-size: 26px !important; }
  .editor-toolbar { gap: 4px; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding: 6px 0; }
  .editor-toolbar button { min-width: 44px; height: 44px; font-size: 15px; flex: 0 0 auto; }
  .editor-footer { flex-direction: column; align-items: stretch; }
  .editor-footer .text-button, .attachment-button { font-size: 14px; min-height: 44px; }
  [contenteditable] { font-size: 17px; line-height: 1.65; min-height: 40vh; }
}

/* Slide-out menu: dimmed backdrop (the menu button and backdrop tap are wired up in app.js). */
@media (max-width: 620px) {
  .sidebar { width: min(300px, 86vw); max-width: 86vw; z-index: 60; box-shadow: none; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .sidebar.open { box-shadow: 15px 0 60px rgba(0, 0, 0, .25); }
  .sidebar.open + .app-main::after { content: ''; position: fixed; inset: 0; background: rgba(17, 38, 17, .45); z-index: 55; }
  .sidebar .brand-logo { height: 56px; }
  .sidebar-note { display: none; }
  .app-nav a { font-size: 15px; padding: 12px 14px; }
  .sidebar-label { font-size: 11px; }
  .sidebar-bottom strong { font-size: 14px; max-width: 160px; }
  .sidebar-bottom small { font-size: 12px; }
  .sidebar-bottom .text-button { font-size: 14px; }
  .avatar { width: 40px; height: 40px; }
}
@media (min-width: 621px) and (max-width: 900px) {
  .app-nav a { min-height: 44px; }
  .mood-options button { min-height: 60px; }
}

/* Dialogs become comfortable full-width sheets on phones. */
@media (max-width: 620px) {
  dialog { width: calc(100% - 20px); max-width: none; padding: 22px 18px; max-height: 92vh; max-height: 92dvh; border-radius: 16px; }
  dialog h2 { font-size: 26px; margin-bottom: 14px; }
  dialog > p, dialog p { font-size: 15px; line-height: 1.55; }
  .dialog-heading { margin-bottom: 6px; }
  .radio-card { padding: 14px; }
  .payment-options { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .payment-options label { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid #f3dcea; border-radius: 10px; }
  .toast { left: 12px; right: 12px; bottom: 84px; max-width: none; font-size: 14px; }
}

/* Delete-account panel (new) */
.danger-panel { border-color: #e8b9b3 !important; background: #fff8f7; }
.danger-panel h2 { color: #8c2f26; }
.button.danger { background: #a6493e; border-color: #a6493e; color: #fff; }
.button.danger:hover { background: #8c2f26; }
#delete-form .form-feedback { color: #8c2f26; background: #fff0ed; border-radius: 8px; padding: 10px 12px; }

/* ---- Shop, purchases, admin ---------------------------------------------------------------------------------- */
@media (max-width: 850px) {
  .commerce-header { flex-wrap: wrap; gap: 10px 16px; padding: 12px 16px; }
  .commerce-header nav { width: 100%; gap: 4px 16px; }
  .commerce-header nav a, .commerce-header nav .text-button { display: inline-flex; align-items: center; font-size: 15px; }
}
@media (max-width: 540px) {
  .commerce.dashboard { padding: 18px 14px 96px; }
  .commerce h1 { font-size: clamp(2rem, 9vw, 2.6rem); margin: 8px 0 16px; }
  .commerce .panel { padding: 16px; margin: 18px 0; }
  .commerce .notice { font-size: 15px; }
  .product-card img, .product-placeholder { height: 240px; }
  .product-copy { padding: 18px; }
  .product-copy h2 { font-size: 24px; }
  .product-copy .button, .commerce .button { width: 100%; min-height: 48px; }
  .basket-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .basket-row label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .basket-row input, .basket-row select { width: auto; min-width: 90px; min-height: 44px; }
  .basket-total { font-size: 22px; }
  .commerce-fields { grid-template-columns: 1fr; }
  .format-option { padding: 14px 12px; }
  .format-option small { font-size: 14px; }
  .order-card { padding: 16px; overflow-wrap: anywhere; }
  .order-meta { flex-direction: column; align-items: flex-start; gap: 4px; }
  .order-meta h3 { font-size: 15px; word-break: break-all; }
  .slide-btn { width: 44px; height: 44px; }
  .slide-dots button { width: 12px; height: 12px; }
  .dashboard-tabs { overflow-x: auto; flex-wrap: nowrap; gap: 6px; padding: 8px 10px; -webkit-overflow-scrolling: touch; }
  .dashboard-tabs a { white-space: nowrap; display: inline-flex; align-items: center; padding: 0 12px; }
  .pagination { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
}

/* Sign-in / sign-up / PIN screens: no floating chat button over the form fields. */
@media (max-width: 900px) {
  body:has(.auth-layout) .whatsapp-float { display: none; }
  body:has(.auth-layout) { padding-bottom: 0; }
}

/* Narrow-screen and hosted WebView refinements. Desktop branding is unchanged. */
@media(max-width:900px){
  .commerce-header nav{flex-wrap:wrap;min-width:0}
  .commerce-header nav a,.commerce-header nav button{overflow-wrap:anywhere}
  .app-main,.app-content,.commerce,.panel,.entry-card,.product-copy,
  .workspace-heading>div,.dashboard-grid>*,.account-grid>*{min-width:0}
  .commerce h1,.page-heading h1,.entry-card h2,.product-copy h2{overflow-wrap:anywhere}
  .sidebar{overflow-y:auto;max-height:100dvh;overscroll-behavior:contain}
  .commerce input,.commerce select,.commerce textarea{max-width:100%;box-sizing:border-box}
  dialog{box-sizing:border-box;overflow-y:auto;overscroll-behavior:contain}
  .commerce-header,.mast{padding-left:max(14px,env(safe-area-inset-left));padding-right:max(14px,env(safe-area-inset-right))}
  .app-content,.commerce.dashboard{padding-bottom:max(28px,env(safe-area-inset-bottom))}
}
@media(max-width:620px){
  .commerce-header nav{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 10px}
  .commerce-header nav a,.commerce-header nav .text-button{font-size:13px;line-height:1.4;justify-content:flex-start;text-align:left;padding:6px 0}
  .commerce-header .brand-logo{max-width:150px;height:auto}
  .editor-header{flex-wrap:wrap;top:0}
  .editor-header>div{flex-wrap:wrap}
  .editor-header .fine{max-width:100%}
  .filter-bar input,.filter-bar select{width:100%;min-width:0;box-sizing:border-box}
  .calendar-grid{grid-template-columns:repeat(7,minmax(0,1fr))}
  .calendar-grid button,.calendar-empty{padding:6px 0;min-width:0}
  .attachment-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:380px){
  .auth-card{padding:20px 16px}
  .commerce.dashboard{padding-inline:10px}
  .commerce .panel{padding:16px 12px}
  .filter-bar{grid-template-columns:minmax(0,1fr)}
  .foot-grid{grid-template-columns:minmax(0,1fr)}
  .app-content{padding-inline:12px}
}
@media(max-height:500px) and (max-width:900px){
  .app-topbar,.editor-header{position:static}
  dialog{max-height:94dvh}
}
