/* Ajustes de leitura e interação. A identidade e a composição desktop são preservadas. */
.mobile-header { display: none; }
.mobile-menu { border: 0; padding: 0; color: var(--text); background: var(--surface); }
.mobile-menu-close { position: absolute; top: 18px; right: 14px; z-index: 2; }
.mobile-menu:not([open]) { display: none; }
body:has(dialog[open]) { overflow: hidden; }

.main > section, .stack, .panel, .form-grid > *, .summary-row > div,
.view-header > div, .board-title, .card-actions { min-width: 0; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pj-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.cl-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.lead-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.board-card { min-width: 0; }
.url-row code { min-width: 0; overflow-wrap: anywhere; }
.modal { max-height: calc(100dvh - 32px); overscroll-behavior: contain; }
.auth-screen { min-height: 100dvh; }
.view-header h1, .board-title h1, .cf-id-text h2 { overflow-wrap: anywhere; }
.table-wrap, .kb-scroll, .tg-panel { max-width: 100%; overscroll-behavior-x: contain; }
.peak-row { overflow-x: clip; overflow-y: visible; }

/* iPad e tablets: menu com nomes e espaço útil para o conteúdo. */
@media screen and (min-width: 761px) and (max-width: 1180px) {
  .app { grid-template-columns: 208px minmax(0, 1fr); }
  .sidebar { align-items: stretch; height: 100dvh; padding: 22px 12px 16px; gap: 18px; }
  .sidebar .brand { padding: 0 8px; }
  .sidebar .brand-name { display: inline; }
  .sidebar .nav { flex: 1; overflow-y: auto; }
  .sidebar .nav-item { width: 100%; justify-content: flex-start; padding: 10px; min-height: 44px; font-size: 15px; }
  .sidebar .nav-item span { display: inline; }
  .sidebar .nav-section { font-size: 12px; }
  .sidebar .nav-search { width: 100%; height: 44px; margin: 0; padding: 0 12px; justify-content: flex-start; }
  .sidebar .nav-search span { display: inline; }
  .sidebar .nav-search kbd { display: none; }
  .main { padding: 30px 24px 48px; }
  .fin-split, .dash-grid, .dash-pair, .cal-layout, .settings-grid, .cf-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-grid .span-2 { grid-column: auto; }
  .day-panel { position: static; }
  .header-actions { width: 100%; }
  .kd-layout { grid-template-columns: minmax(0, 1fr); }
  .kd-side { border-left: 0; border-top: 1px solid var(--separator); }
}

/* Texto de conteúdo confortável sem precisar ampliar a página. */
@media screen and (max-width: 1180px) {
  :root { --fs-small: 14px; --fs-caption: 14px; --fs-micro: 12px; --fs-h2: 19px; }
  body { font-size: 16px; line-height: 1.5; }
  h2 { font-size: 19px; }
  h3 { font-size: 15px; }
  .meta, .hint, .field, .form-error, .check, .colors legend,
  .kb-meta, .kb-type, .kb-client, .due, .stage-total, .crm-card .value,
  .info-grid dt, .table th, .table td, .mini-stats span, .tx-date,
  .cat-row, .chart-legend, .chart-x, .cl-stats span, .cl-stats b,
  .cf-kpis span, .cf-kpis small, .kd-props dt, .kd-sec h4, .kd-ck-head,
  .pj-next b, .pw-steps li, .scope-list li, .asset-main b,
  .lf, .lf-check, .leads-usage, .lead-card > .meta, .lc-intel,
  .fin-balance span, .fin-side-totals span, .te-range, .te-day-head b,
  .tpl-body small, .pi-text small, .ba-row dd, .kd-activity p { font-size: 14px; }
  .kb-title, .crm-card-top b, .cl-id b, .pri-title, .fu-main b,
  .asset-main b, .rec-main b, .task-item b, .event-title { font-size: 16px; line-height: 1.45; }
  .badge, .prio, .kb-chip, .tpl-cols i { font-size: 12px; }
  .btn, .btn.small, .chip, .link, .segmented button, .seg-tabs a,
  .inline-select, select.kb-filter, .cf-tabs button { font-size: 15px; }
  input:where(:not([type=checkbox]):not([type=radio]):not([type=file])),
  select, textarea, .search, .lf-search input, .share-link input,
  .profit-settings input, .fu-settings select, .th-form input { font-size: 16px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar > .search { flex: 1 1 220px; }
  .panel-header { flex-wrap: wrap; gap: 12px; }
  .modal-actions { flex-wrap: wrap; }
  .table { font-size: 15px; }
  .table:has(tr > :nth-child(4)) { min-width: 560px; }
  .table:has(tr > :nth-child(6)) { min-width: 760px; }
  .table th, .table td { padding: 14px 12px; }
  .table td .link { white-space: normal; min-width: 120px; }
  .kb-col { width: 316px; }
  .kb-col-tools, .kb-play { opacity: 1; }
  .kb-card, .crm-card { padding: 16px; gap: 10px; }
  .kb-col { max-height: calc(100dvh - 180px); }
  .kb-col-name { min-height: 44px; font-size: 16px; }
  .kb-col-name .count { font-size: 14px; }
  .kb-desc, .kb-client-row b, .kb-client-row small, .kp > span, .kp b, .kp b small, .kb-stage, .kb-age { font-size: 14px; }
  .kb-client-row b, .kb-client-row small { white-space: normal; line-height: 1.4; overflow-wrap: anywhere; }
  .kp b { white-space: normal; line-height: 1.4; }
  .kb-filters { min-width: 0; max-width: 100%; }
  select.kb-filter { min-width: 0; max-width: 100%; }
  .pstatus { font-size: 13px; }
  .bc-title b { white-space: normal; overflow-wrap: anywhere; line-height: 1.4; }
  .bc-title span, .bc-foot { font-size: 14px; }
  .bc-foot { flex-wrap: wrap; gap: 8px 12px; }
  .cl-stats b, .cf-kpis b, .summary-row b, .stat-value { overflow-wrap: anywhere; }
  .tx-desc, .event-title, .cl-id b, .asset-main b, .rec-main b, .te-main b { white-space: normal; overflow-wrap: anywhere; }
  .tx-desc { line-height: 1.45; }
  .tx-row { gap: 10px; padding: 14px 4px; }
  .tx-amount { min-width: 0; font-size: 16px; }
  .funnel-row { font-size: 14px; }
  .funnel-val { font-size: 13px; }
  .chart-col:last-child .bar-val { left: auto; right: 0; transform: none; }
  .chart { overflow-x: clip; overflow-y: visible; }
  .paper { font-size: 16px; }
  .tg-panel { overflow-x: auto; }
  .tg:not(.single) { min-width: 840px; }
  .tg-ev { font-size: 14px; }
  .tg-ev span { font-size: 13px; }
  .peak-row {
    grid-template-columns: none; grid-auto-flow: column;
    grid-auto-columns: min(340px, calc(100% - 24px));
    overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity;
    max-width: 100%; margin: 0 0 20px; padding: 8px 0 16px;
  }
  .peak-row > .peak { scroll-snap-align: start; }
  .pk-updated { max-width: calc(100% - 120px); overflow: hidden; text-overflow: ellipsis; }
  .pk-pill { min-height: 44px; }
  .pk-menu button { min-height: 44px; }
}

/* Áreas de toque também nos iPads maiores, sem depender de hover. */
@media screen and (max-width: 1180px), (pointer: coarse) {
  .btn, .btn.small, .icon-btn, .icon-btn.tiny, .chip,
  .segmented button, .pop-menu button, .kb-play, .kb-add, .kb-quick input,
  .inline-select, select.kb-filter, .fu-settings select,
  .contact-btns .btn.small, .btn.ev-remind, .tx-check, .cov { min-height: 44px; }
  .icon-btn, .icon-btn.tiny, .kb-play, .contact-btns .btn.small, .btn.ev-remind, .tx-check, .cov { min-width: 44px; }
  input:where(:not([type=checkbox]):not([type=radio]):not([type=file])), select { min-height: 46px; }
  .check, .kd-ck li label, .theme-opt { min-height: 44px; }
  .check input, .kd-ck input, .ck-item input[type=checkbox] { width: 22px; height: 22px; }
  .segmented { flex-shrink: 0; }
  .segmented button { padding: 0 12px; }
  .btn { white-space: normal; height: auto; padding-top: 10px; padding-bottom: 10px; line-height: 1.35; }
  .icon-btn svg, .btn svg { width: 19px; height: 19px; }
  .link { min-height: 44px; }
  .kb-col-tools { opacity: 1; }
}

/* Celular: navegação identificada, largura livre e leitura por blocos. */
@media screen and (max-width: 760px) {
  :root { --fs-display: 28px; --fs-title: 21px; --num-lg: 24px; --num-xl: 28px; }
  .app { display: block; min-height: 100dvh; }
  .mobile-header {
    position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px;
    min-height: calc(64px + env(safe-area-inset-top));
    padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
    background: var(--sidebar-bg); border-bottom: 1px solid var(--separator);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  }
  .mobile-menu-toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px 0 0; background: transparent; border: 0; cursor: pointer; font-size: 16px; font-weight: 600; }
  .mobile-menu-close { top: calc(18px + env(safe-area-inset-top)); }
  .mobile-menu-toggle svg, .mobile-header .icon-btn svg, .mobile-menu-close svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .mobile-page-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-header .icon-btn { background: transparent; }
  .mobile-menu { width: min(360px, calc(100vw - 32px)); max-width: none; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0 22px 22px 0; box-shadow: var(--shadow-lg); }
  .mobile-menu::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
  .mobile-menu .sidebar { position: static; display: flex; flex-direction: column; align-items: stretch; width: 100%; height: 100%; padding: calc(22px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); gap: 18px; background: var(--surface); border: 0; overflow: hidden; }
  .mobile-menu .brand { display: flex; padding: 0 54px 0 8px; }
  .mobile-menu .brand-name { display: inline; }
  .mobile-menu .nav { display: flex; flex-direction: column; order: initial; flex: 1; min-height: 0; overflow: auto; margin: 0; padding: 0 4px; gap: 3px; }
  .mobile-menu .nav-section { display: block; margin: 14px 12px 5px; font-size: 12px; }
  .mobile-menu .nav-item { width: 100%; height: auto; min-height: 48px; justify-content: flex-start; padding: 10px 12px; gap: 12px; font-size: 16px; flex-shrink: 0; }
  .mobile-menu .nav-item span { display: inline; }
  .mobile-menu .nav-item.active { background: var(--accent-soft); color: var(--text); }
  .mobile-menu .nav-item svg { width: 22px; height: 22px; }
  .mobile-menu .sidebar-footer { order: initial; display: flex; flex-direction: column; flex-shrink: 0; margin: 0; border-top: 1px solid var(--separator); padding-top: 10px; }
  .mobile-menu .sidebar-footer #btn-logout { display: flex; }
  .mobile-menu .clock, .mobile-menu .nav-search { display: none; }
  .main { padding: 24px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .view-header { gap: 18px; }
  .view-header .muted { font-size: 16px; line-height: 1.5; }
  .header-actions { gap: 10px; }
  .header-actions > .search { flex: 1 1 100%; }
  .header-actions > .btn { flex: 1 1 auto; }
  .form-grid, .info-grid { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 20px 16px; }
  .panel .panel { padding: 16px 12px; }
  .summary-row, .stats, .goal-summary, .kpi-strip, .cf-kpis { gap: 12px; }
  .summary-row b, .stat-value { font-size: 24px; line-height: 1.2; }
  .summary-row .hero b { font-size: 28px; }
  .goal-summary > div { padding: 16px 12px; }
  .goal-summary b { font-size: 20px; overflow-wrap: anywhere; }
  .pri-top { flex-wrap: wrap; gap: 4px 8px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { padding: 16px 12px; }
  .seg-tabs { min-height: 48px; margin-bottom: 20px; scroll-padding-inline: 8px; }
  .seg-tabs a { padding: 10px 14px; flex-shrink: 0; }
  .filters { gap: 8px; }
  .filters .chip { flex-shrink: 0; }
  .quick-add input[name="q"] { order: 0; flex-basis: 100%; }
  .quick-add > .qa-ic { display: none; }
  .quick-add .qa-paid { order: 1; }
  .quick-add > button { order: 2; margin-left: auto; }
  .kb-col { width: min(320px, calc(100vw - 48px)); max-height: none; }
  .kb-scroll { min-height: 0; padding: 2px 2px 18px; scroll-padding-inline: 2px; }
  .kb-list { max-height: min(65dvh, 640px); min-height: 100px; }
  .kb-embed-actions .search { min-width: 0; max-width: none; flex-basis: 100%; }
  .kb-views { width: 100%; max-width: 100%; overflow-x: auto; }
  .kb-views button { flex-shrink: 0; }
  .kb-views span { display: inline; }
  .board-title { align-items: flex-start; gap: 10px; }
  .board-cards { grid-template-columns: minmax(0, 1fr); }
  .board-title h1 { font-size: 26px; }
  .board-title h1:has(.pstatus) { display: block; }
  .board-title h1 .pstatus { margin: 8px 0 0; }
  .board-title > .icon-btn { flex-shrink: 0; }
  .cal-nav { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 6px; }
  .cal-nav h1 { min-width: 0; font-size: 22px; text-align: center; line-height: 1.25; }
  .cal-nav > [data-today] { grid-column: 2; justify-self: center; }
  .cal-day { min-height: 52px; padding: 4px 0; }
  .cal-day .num { width: 32px; height: 32px; font-size: 16px; }
  .cal-weekdays { font-size: 12px; letter-spacing: 0; }
  .cal-grid { gap: 2px; }
  .tg-panel { padding: 12px 0; overflow-x: auto; }
  .tg:not(.single) { min-width: 840px; }
  .tg-ev { font-size: 14px; padding: 5px 7px; }
  .tg-ev span { display: block; }
  .tg-dayhead b { font-size: 18px; }
  .tg.single { min-width: 0; }
  .event-item { align-items: flex-start; gap: 10px; padding-top: 14px; padding-bottom: 14px; }
  .event-title { display: block; white-space: normal; }
  .event-title .rep { margin-left: 4px; }
  .event-date .m { font-size: 12px; }
  .tx-row, .tx-row:not(:has(.tx-wa)) { grid-template-columns: 44px minmax(0, 1fr); gap: 6px 10px; }
  .tx-check { grid-row: 1 / span 3; align-self: start; }
  .tx-amount { grid-column: 2; grid-row: 2; text-align: left; }
  .tx-date { grid-column: 2; grid-row: 3; white-space: normal; flex-wrap: wrap; font-size: 14px; }
  .tx-wa { grid-column: 2; grid-row: 4; justify-self: start; }
  .tx-main { grid-column: 2; grid-row: 1; }
  .cl-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cl-stats > div:last-child { grid-column: 1 / -1; }
  .cf-hero { padding-right: 60px; }
  .cf-id { gap: 12px; }
  .cf-id-text h2 { line-height: 1.3; }
  .cf-tabs button { white-space: nowrap; min-height: 48px; flex-shrink: 0; }
  .modal, .modal.small, .modal.wide, .modal.xwide, .modal.cf-modal, .modal.kd-modal { width: calc(100vw - 24px); max-width: none; max-height: calc(100dvh - 24px); border-radius: 20px; }
  .modal-form, .modal-body, .modal.small .modal-body { padding: 24px 18px; }
  .modal-actions { gap: 10px; }
  .modal-actions .btn { min-width: 0; flex: 1 1 auto; }
  .modal-actions .spacer { display: none; }
  .modal.palette-modal { margin-top: max(12px, env(safe-area-inset-top)); }
  .auth-card { padding: 30px 24px; }
  .auth-card .brand-name { display: inline; }
  .auth-card .btn { min-height: 48px; }
  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); }
  .alerts { bottom: calc(20px + env(safe-area-inset-bottom)); max-height: calc(100dvh - 100px); overflow-y: auto; }
  .url-row { flex-wrap: wrap; }
  .url-row code { flex-basis: calc(100% - 8px); }
  .backup-row { flex-wrap: wrap; }
  .perm-row .hint { min-width: 0; flex-basis: 100%; }
  .theme-picker { flex-wrap: wrap; }
  .pw-steps { grid-template-columns: minmax(0, 1fr); }
  .req-main { min-width: 0; }
  .fu-actions { padding-left: 0; flex-wrap: wrap; }
}

@media screen and (max-width: 420px) {
  .summary-row { grid-template-columns: minmax(0, 1fr); }
  .summary-row > div { padding: 18px 20px; }
  .summary-row b { font-size: 28px; }
  .fin-side-totals { grid-template-columns: minmax(0, 1fr); }
  .bt-types { grid-template-columns: minmax(0, 1fr); }
  .mini-stats { grid-template-columns: minmax(0, 1fr); }
  .quick-add .qa-paid { white-space: normal; }
}

@media screen and (max-width: 360px) {
  .goal-summary, .kpi-strip { grid-template-columns: minmax(0, 1fr); }
  .goal-summary b { font-size: 24px; }
}

@media print {
  .mobile-header, .mobile-menu { display: none !important; }
}
