/* Rotavia v16 responsive system
   Desktop: full sidebar; tablet: compact icon rail; phone: compact header + bottom navigation. */
:root {
  --mobile-dock-height: 66px;
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
}
.mobile-dock, .mobile-more-overlay { display: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: clip; }
.app, .main, .side, .view, .panel, .travel-page,
.translate-grid, .course-layout, .travel-workspace { min-width: 0; }
img, canvas, video, iframe { max-width: 100%; }
button, a, input, select, textarea { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; }

/* Keep wide data tables and long generated content inside their cards. */
.panel, .card, .translate-card, .travel-map-panel, .travel-results-panel,
.my-travel-panel, .course-content, .course-lesson-list { min-width: 0; }
.panel :where(p, h1, h2, h3, h4, small, strong, label),
.card :where(p, h1, h2, h3, h4, small, strong, label) { overflow-wrap: anywhere; }
.panel :where(input, select, textarea), .card :where(input, select, textarea) { max-width: 100%; }
.panel :where(pre, code), .card :where(pre, code) { max-width: 100%; overflow-wrap: anywhere; }

/* Tablet portrait: replace crowded text sidebar with a slim navigation rail. */
@media (min-width: 641px) and (max-width: 860px) {
  .app { grid-template-columns: 76px minmax(0, 1fr) !important; width: 100%; max-width: 100%; }
  .side { width: 76px; height: 100dvh; min-height: 100dvh; padding: 16px 8px; overflow-x: hidden; }
  .brand-mark { justify-content: center; margin: 0 0 16px; }
  .brand-copy, .sublogo, .account-copy, .account-open, .sidebar-foot,
  .side #langs .lang b, .side #langs .lang small, .nav button span, .nav button em { display: none !important; }
  .brand-symbol { width: 44px; height: 44px; flex: 0 0 44px; }
  .account-widget { display: grid; grid-template-columns: minmax(0,1fr); justify-items: center; gap: 5px; margin: 10px 0 14px; padding: 5px 2px; border: 0; background: transparent; }
  .account-avatar { width: 42px; height: 42px; }
  .account-open { display: block !important; width: 100%; min-width: 0; min-height: 32px; padding: 5px 1px; font-size: 9px; white-space: nowrap; }
  .side #langs { display: grid; grid-template-columns: 1fr; gap: 7px; }
  .side .lang { display: grid; place-items: center; width: 100%; min-height: 44px; margin: 0; padding: 6px; }
  .side .lang .flag { font-size: 22px; }
  .nav { display: grid; grid-template-columns: 1fr; gap: 5px; margin-top: 14px; padding-top: 12px; }
  .nav button { display: grid; place-items: center; width: 100%; min-height: 43px; padding: 8px 4px; margin: 0; }
  .nav button > i { width: auto; margin: 0; font-size: 18px; }
  .main { width: 100%; max-width: none; padding: 20px 18px 36px; }
  .stats-cards { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 9px; }
  .stat-card { padding: 13px; }
  .stat-card h3 { font-size: 17px; }
  .cards:not(.stats-cards) { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dashboard-lower { grid-template-columns: minmax(0,1.2fr) minmax(220px,.8fr); }
  .hero { grid-template-columns: minmax(0,1fr); }
  .hero-photo { min-height: 190px; }
  .translate-grid { grid-template-columns: minmax(0,1fr); }
  .course-layout, .travel-workspace { grid-template-columns: minmax(0,1fr); }
  .travel-search-bar { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .travel-search-button { width: 100%; }
}

/* Smaller laptop / wide tablet: retain readable sidebar labels while tightening spacing. */
@media (min-width: 861px) and (max-width: 1100px) {
  .app { grid-template-columns: 205px minmax(0,1fr) !important; }
  .side { padding: 17px 11px; }
  .nav button { gap: 8px; padding: 9px 9px; font-size: 11px; }
  .nav button span { overflow-wrap: anywhere; }
  .main { padding: 22px 20px 38px; }
  .dashboard-lower { grid-template-columns: minmax(0,1.1fr) minmax(220px,.9fr); }
  .travel-workspace { grid-template-columns: minmax(0,1fr); }
  .travel-search-bar { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

/* Phone: content-first header, no squeezed horizontal sidebar menu, persistent bottom dock. */
@media (max-width: 640px) {
  html, body { width: 100%; min-width: 320px; overflow-x: hidden; overflow-x: clip; }
  body { padding-bottom: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom) + 10px); }
  .app { display: flex !important; flex-direction: column; width: 100%; max-width: 100%; min-height: 100dvh; margin: 0; }
  .side { position: relative !important; inset: auto; display: block; width: 100%; height: auto !important; min-height: 0; max-height: none; overflow: visible; padding: 12px 14px 10px; border: 0; border-bottom: 1px solid #e4e9eb; border-radius: 0; background: rgba(255,255,255,.98); box-shadow: 0 5px 18px rgba(29,52,63,.045); }
  .brand-mark { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; }
  .brand-symbol { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 13px; }
  .brand-copy { display: grid; gap: 1px; min-width: 0; }
  .brand-copy strong { font-size: 19px; line-height: 1.15; }
  .brand-copy small { font-size: 8px; letter-spacing: .8px; }
  .sublogo { display: none !important; }
  .account-widget { display: grid; grid-template-columns: 34px minmax(0,1fr) auto; align-items: center; gap: 8px; width: 100%; margin: 7px 0 10px; padding: 8px 9px; border-radius: 13px; }
  .account-avatar { width: 34px; height: 34px; border-radius: 10px; }
  .account-copy { display: grid; min-width: 0; gap: 1px; }
  .account-copy strong { font-size: 11px; line-height: 1.25; }
  .account-copy small { font-size: 9px; line-height: 1.3; }
  .account-open { grid-column: auto; width: auto; min-width: 78px; min-height: 36px; padding: 7px 10px; border-radius: 9px; font-size: 10px; white-space: nowrap; }
  .side #langs { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; width: 100%; min-width: 0; }
  .side .lang { display: flex; align-items: center; justify-content: flex-start; gap: 6px; min-width: 0; min-height: 45px; width: 100%; margin: 0; padding: 7px 8px; border-radius: 11px; }
  .side .lang .flag { flex: 0 0 auto; font-size: 18px; }
  .side .lang b { display: block; min-width: 0; font-size: 10px; line-height: 1.15; overflow-wrap: anywhere; }
  .side .lang small { display: block; font-size: 8px; line-height: 1.2; }
  .side .nav, .side .sidebar-foot { display: none !important; }
  .main { width: 100%; max-width: 100%; min-width: 0; margin: 0; padding: 14px 13px calc(22px + var(--mobile-dock-height) + var(--mobile-safe-bottom)); }
  .view, .panel, .travel-page { width: 100%; max-width: 100%; min-width: 0; }
  .top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  .top > div:first-child > b { font-size: 13px; }
  .top > div:first-child .muted { font-size: 10px; }
  .xp-pill { max-width: none !important; gap: 7px; padding: 5px 9px; font-size: 10px; }
  .xp-gem { width: 24px; height: 24px; }
  .hero { display: flex !important; flex-direction: column; align-items: stretch; gap: 13px; min-height: 0; margin-top: 12px; padding: 18px; border-radius: 17px; }
  .hero-copy { min-width: 0; }
  .hero h1 { max-width: none; margin: 10px 0 8px; font-size: clamp(23px,6vw,27px); line-height: 1.18; letter-spacing: -.65px; }
  .hero-description { max-width: none; font-size: 13px; line-height: 1.55; }
  .hero-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
  .hero-pills span { font-size: 10px; padding: 6px 9px; }
  .hero-cta { display: inline-flex; justify-content: center; align-items: center; gap: 9px; min-height: 46px; width: 100%; margin-top: 13px !important; }
  .hero-photo { display: block; width: 100%; height: 155px; min-height: 155px; border-radius: 12px; }
  .hero-photo-caption { left: 13px; right: 13px; bottom: 12px; }
  .hero-photo-caption strong { font-size: 15px; }
  .stats-cards { display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 8px; margin-top: 12px; }
  .stats-cards .stat-card { display: block; min-width: 0; min-height: 0; padding: 12px; border-radius: 13px; }
  .stats-cards .stat-card:nth-child(3) { grid-column: 1 / -1; }
  .stat-card .stat-icon { width: 32px; height: 32px; margin-bottom: 7px; }
  .stat-card .muted { font-size: 10px; }
  .stat-card h3 { margin: 4px 0; font-size: 16px; line-height: 1.25; }
  .stat-card > small { font-size: 9px; }
  .cards:not(.stats-cards), .dashboard-lower, .cards { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .cards:not(.stats-cards) > .card { padding: 15px; }
  .dashboard-lower { gap: 10px; }
  .chart-wrap { height: 180px; }
  .card, .panel { min-width: 0; padding: 15px; border-radius: 15px; }
  .panel { margin: 0; }
  .panel h2, .sectionTitle h2 { font-size: clamp(20px,5.5vw,23px); line-height: 1.25; }
  .panel h3, .card h3 { font-size: 16px; line-height: 1.35; }
  .sectionTitle { align-items: flex-start; gap: 9px; }
  .sectionTitle > * { min-width: 0; }
  .back { min-height: 40px; padding: 8px 11px; }
  .course-weeks { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
  .week-btn { min-width: 0; padding: 10px 8px; }
  .course-layout { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .course-content, .course-lesson-list { min-width: 0; }
  .course-lesson { padding: 12px; }
  .course-content .lettergrid, .lettergrid { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 6px; }
  .letterbtn { min-width: 0; padding: 8px 2px; }
  .letterbtn strong { font-size: 20px; }
  .translate-intro { display: grid; grid-template-columns: minmax(0,1fr); gap: 12px; margin: 12px 0; }
  .translate-intro > div { min-width: 0 !important; width: 100%; }
  .translate-intro h2 { font-size: 23px !important; }
  .translate-grid { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .translate-card { width: 100%; min-width: 0; padding: 13px; border-radius: 14px; }
  .translate-card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
  .translate-card .direction { font-size: 9px; letter-spacing: .02em; }
  .translate-card h3 { font-size: 16px; }
  .translate-textarea { width: 100%; min-width: 0; min-height: 100px; max-height: 220px; resize: vertical; font-size: 16px; }
  .translate-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
  .translate-actions button { width: 100%; min-width: 0; min-height: 44px; padding: 9px 7px; font-size: 11px; white-space: normal; overflow-wrap: anywhere; }
  .translate-result { min-width: 0; padding: 12px; font-size: 13px; overflow-wrap: anywhere; }
  .translate-history { min-width: 0; }
  .history-head { align-items: flex-start; flex-wrap: wrap; }
  .history-item { padding: 11px; }
  .history-original, .history-translation { overflow-wrap: anywhere; }
  .toolbar { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; }
  .toolbar .search, .search { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 44px; }
  .wordline { grid-template-columns: minmax(0,1fr); gap: 8px; }
  .wordline button { justify-self: start; min-height: 42px; }
  .options { grid-template-columns: minmax(0,1fr); }
  .option, .match-item { min-height: 46px; }
  .question { margin: 18px 0 9px; font-size: 22px; line-height: 1.3; overflow-wrap: anywhere; }
  .match-grid { grid-template-columns: minmax(0,1fr); }
  .travel-page { padding-bottom: 12px; }
  .travel-hero { display: grid; grid-template-columns: minmax(0,1fr); gap: 0; margin-bottom: 12px; border-radius: 15px; }
  .travel-hero-copy { min-width: 0; padding: 18px 16px; }
  .travel-hero-copy h1 { font-size: clamp(23px,6vw,28px); line-height: 1.18; }
  .travel-hero-copy p { font-size: 12px; line-height: 1.6; }
  .travel-hero-pills { gap: 6px; margin-top: 13px; }
  .travel-hero-pills span { font-size: 10px; padding: 6px 8px; }
  .travel-hero-image { grid-row: auto; width: 100%; height: 150px; min-height: 150px; }
  .travel-search-bar { display: grid; grid-template-columns: minmax(0,1fr); gap: 9px; padding: 11px; }
  .travel-search-field, .travel-search-field input, .travel-search-field select { width: 100%; min-width: 0; max-width: 100%; }
  .travel-search-field input, .travel-search-field select { min-height: 44px; font-size: 16px; }
  .travel-search-button { width: 100%; min-height: 46px; }
  .travel-location-row { display: flex; flex-direction: column; align-items: stretch; gap: 9px; padding: 11px; }
  .travel-location-button { width: 100%; min-height: 44px; white-space: normal; }
  .travel-workspace { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .travel-map-panel, .travel-results-panel, .my-travel-panel { width: 100%; min-width: 0; padding: 11px; border-radius: 14px; }
  .travel-map-panel #travelMap { width: 100%; height: min(62vh,360px); min-height: 250px; }
  .map-setup-state { min-height: 250px; padding: 16px; }
  .travel-result-list, .my-travel-list { display: grid; grid-template-columns: minmax(0,1fr); gap: 10px; }
  .place-card-photo { height: 175px; }
  .travel-map-top, .travel-results-head { align-items: flex-start; flex-wrap: wrap; }
  .manual-place { padding: 13px 2px; }
  .manual-place input, .manual-place textarea, .manual-place select { width: 100%; min-width: 0; min-height: 44px; }
  .travel-list-toolbar { align-items: stretch; flex-direction: column; gap: 8px; }
  .travel-list-tabs { display: grid; width: 100%; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 5px; }
  .travel-list-tabs button { min-width: 0; min-height: 40px; padding: 7px 4px; font-size: 10px; white-space: normal; }
  .trip-card-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
  .trip-card-actions button { min-width: 0; min-height: 42px; white-space: normal; }
  .google-rating-disclosure { padding: 10px; font-size: 10px; }
  .google-rating { max-width: 100%; justify-content: flex-start; }
  .modal-overlay { align-items: flex-end; padding: 8px 8px calc(8px + var(--mobile-safe-bottom)); }
  .account-modal { width: 100%; max-width: 100%; max-height: calc(100dvh - 16px - var(--mobile-safe-bottom)); margin: 0 auto; padding: 22px 17px 18px; border-radius: 20px 20px 16px 16px; }
  .account-modal h2 { font-size: 23px; }
  #accountForm .account-input { min-height: 48px; font-size: 16px; }
  .mobile-dock { position: fixed; z-index: 9000; inset: auto 0 0; display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 2px; width: 100%; min-height: calc(var(--mobile-dock-height) + var(--mobile-safe-bottom)); padding: 6px 7px calc(6px + var(--mobile-safe-bottom)); border-top: 1px solid rgba(213,223,226,.95); background: rgba(255,255,255,.96); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 -8px 26px rgba(28,49,60,.08); }
  .mobile-dock button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; min-height: 48px; padding: 4px 2px; border-radius: 11px; background: transparent; color: #74838b; }
  .mobile-dock button i { font-size: 19px; line-height: 1; }
  .mobile-dock button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; line-height: 1.2; font-weight: 700; }
  .mobile-dock button.active { background: #edf3f5; color: #244f63; }
  .mobile-dock button.active i { color: #244f63; }
  .mobile-dock button:focus-visible { outline: 2px solid #527c8d; outline-offset: -2px; }
  .mobile-more-overlay { position: fixed; z-index: 9200; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 0 0 calc(var(--mobile-safe-bottom)); }
  .mobile-more-overlay[hidden] { display: none !important; }
  .mobile-more-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; background: rgba(15,30,39,.42); backdrop-filter: blur(3px); }
  .mobile-more-sheet { position: relative; z-index: 1; width: 100%; max-height: min(78dvh,620px); overflow-y: auto; padding: 9px 17px 20px; border-radius: 22px 22px 0 0; background: #fff; box-shadow: 0 -12px 38px rgba(22,43,54,.16); }
  .mobile-sheet-handle { width: 38px; height: 4px; margin: 2px auto 15px; border-radius: 999px; background: #d8e0e3; }
  .mobile-sheet-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 13px; }
  .mobile-sheet-heading h2 { margin: 3px 0 0; font-size: 21px; }
  .mobile-sheet-close { width: 38px; height: 38px; border: 1px solid #e0e7e9; border-radius: 11px; background: #f6f8f9; color: #385868; }
  .mobile-more-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .mobile-more-grid button { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 56px; padding: 10px; border: 1px solid #e3e9eb; border-radius: 12px; background: #fff; color: #304b59; text-align: left; font-size: 12px; font-weight: 700; }
  .mobile-more-grid button i { flex: 0 0 auto; font-size: 18px; color: #315f73; }
  .mobile-more-grid button span { min-width: 0; overflow-wrap: anywhere; }
  .mobile-sheet-account { display: flex; align-items: center; justify-content: center; gap: 9px; width: 100%; min-height: 46px; margin-top: 12px; border: 1px solid #d9e4e8; border-radius: 12px; background: #edf3f5; color: #2d596f; font-weight: 800; }
  body.mobile-sheet-open { overflow: hidden; }
  body.modal-open .mobile-dock { visibility: hidden; }
}

@media (max-width: 380px) {
  .side { padding-left: 10px; padding-right: 10px; }
  .account-widget { grid-template-columns: 31px minmax(0,1fr) auto; gap: 6px; padding: 7px; }
  .account-avatar { width: 31px; height: 31px; }
  .account-open { min-width: 69px; padding: 6px 7px; font-size: 9px; }
  .side .lang { justify-content: center; flex-direction: column; gap: 3px; padding: 6px 3px; }
  .side .lang .flag { font-size: 17px; }
  .side .lang b { font-size: 9px; text-align: center; }
  .side .lang small { text-align: center; }
  .main { padding-left: 10px; padding-right: 10px; }
  .mobile-more-grid { grid-template-columns: minmax(0,1fr); }
  .translate-actions { grid-template-columns: minmax(0,1fr); }
}

/* Short landscape phones and split-screen windows. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .mobile-dock { --mobile-dock-height: 56px; }
  .side { padding-top: 7px; padding-bottom: 7px; }
  .brand-mark { margin-bottom: 5px; }
  .account-widget { margin: 5px 0 7px; }
  .hero-photo { height: 125px; min-height: 125px; }
  .account-modal { max-height: calc(100dvh - 12px); overflow-y: auto; }
}

@media (min-width: 641px) {
  .mobile-dock, .mobile-more-overlay { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .mobile-dock *, .mobile-more-sheet *, .side *, .main * { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
