/* GEMBA LEAN · celular (até 760px). Carregado por último: nenhuma tela pode pedir rolagem
   para os lados. Tabelas largas viram cartões (responsive.js põe o título da coluna em cada
   célula), o Heijunka mostra um dia por vez e as grades com muitas colunas se reorganizam. */

/* Elementos que só existem no celular. */
.board-mobile,
.routine-legend {
  display: none;
}

@media (max-width: 760px) {
  /* ------------------------------------------------------------ base */

  html,
  body {
    overflow-x: clip;
  }
  .workspace {
    padding: 16px 14px 32px;
  }
  .panel {
    padding: 16px;
    margin-bottom: 14px;
  }
  .panel-head {
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .panel-head > * {
    min-width: 0;
  }
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat {
    padding: 12px 14px;
  }
  .stat small {
    font-size: 12px;
    line-height: 1.35;
  }
  /* Valores como "R$ 1.200,00/mês" quebram no espaço, não no meio da palavra. */
  .stat strong {
    font-size: 19px;
    line-height: 1.25;
    overflow-wrap: break-word;
  }
  .stat .hint {
    display: block;
    font-size: 11px;
    line-height: 1.35;
  }
  .topbar {
    gap: 10px;
    padding: 0 12px;
  }
  .topbar-left {
    gap: 10px;
  }
  .page-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }
  /* Textos longos sem espaço (códigos, e-mails) quebram em vez de alargar a página. */
  .workspace p,
  .workspace td,
  .workspace li,
  .modal-body p {
    overflow-wrap: anywhere;
  }
  /* Alvos de toque confortáveis. */
  .workspace button,
  .modal-foot button {
    min-height: 38px;
  }
  .workspace .icon-btn {
    min-height: 0;
  }

  /* ------------------------------------------------------------ barras de ações e ferramentas */

  .heading.slim {
    gap: 10px;
    margin-bottom: 14px;
  }
  .heading.slim .actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
  }
  .heading.slim .actions > * {
    width: 100%;
  }
  .toolbar {
    gap: 8px;
    margin: 12px 0;
  }
  .toolbar > *,
  .toolbar > .date-field {
    flex: 1 1 100%;
    min-width: 0;
  }
  .toolbar .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  /* Semana anterior / campo da semana / próxima semana ficam na mesma linha. */
  .toolbar > #prev-week,
  .toolbar > #next-week {
    flex: 0 0 42px;
    padding: 0;
    font-size: 20px;
  }
  .toolbar > #prev-week ~ .date-field,
  .toolbar > #week {
    flex: 1 1 0;
    max-width: none !important;
  }
  .filter-bar {
    gap: 8px;
  }
  .filter-search {
    width: 100%;
  }
  .filter-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* ------------------------------------------------------------ tabelas que viram cartões */

  .table-wrap:has(> table.stack) {
    overflow: visible;
  }
  table.stack,
  table.stack tbody {
    display: block;
  }
  table.stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  table.stack tr {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
  }
  table.stack tr:last-child {
    margin-bottom: 0;
  }
  table.stack td,
  table.stack tbody th {
    display: grid;
    grid-template-columns: minmax(84px, 36%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    justify-items: start;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 13.5px;
    text-align: left;
  }
  table.stack td::before,
  table.stack tbody th::before {
    content: attr(data-label);
    color: var(--muted-foreground);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
  }
  table.stack td:not([data-label]),
  table.stack td.wide {
    display: block;
  }
  table.stack td:not([data-label])::before,
  table.stack td.wide::before {
    content: none;
  }
  table.stack td:empty {
    display: none;
  }
  /* A primeira coluna é o título do cartão. */
  table.stack tr > :first-child {
    display: block;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
  }
  table.stack tr > :first-child::before {
    content: none;
  }
  table.stack tr > :first-child:only-child {
    padding-bottom: 0;
    border-bottom: 0;
  }
  /* Coluna de ações (sem título): botões lado a lado ocupando a largura. */
  table.stack td:not([data-label]):not(:first-child) {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 2px;
  }
  table.stack td:not([data-label]):not(:first-child) > button {
    flex: 1 1 0;
    margin: 0;
  }
  /* Campos de formulário dentro dos cartões (chamada dos setores). */
  table.stack td > input,
  table.stack td > select,
  table.stack td > textarea,
  table.stack td > .date-field {
    width: 100%;
    min-width: 0;
  }
  table.stack td label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  /* Tabelas pequenas (até 3 colunas) continuam tabela, mais compactas. */
  table:not(.stack):not(.heatmap):not(.board):not(.routine-table) th,
  table:not(.stack):not(.heatmap):not(.board):not(.routine-table) td {
    padding: 9px 8px;
  }

  /* ------------------------------------------------------------ listas e cadastros */

  .list-item {
    flex-wrap: wrap;
    gap: 10px 12px;
    padding: 12px;
  }
  .list-item > div:first-child,
  .user-row > div:nth-child(2) {
    flex: 1 1 0;
    min-width: 0;
  }
  .list-item small {
    overflow-wrap: anywhere;
  }
  .list-item > .actions {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    gap: 8px;
  }
  .user-row > .role-badge {
    flex-shrink: 0;
  }
  .chips {
    gap: 6px;
  }
  .chips .badge {
    white-space: normal;
  }

  /* ------------------------------------------------------------ Visão Geral */

  .overview-top {
    gap: 14px;
    margin-bottom: 14px;
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .kpi {
    gap: 6px;
    padding: 12px 14px;
  }
  .kpi small {
    font-size: 12px;
    line-height: 1.35;
  }
  .kpi-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .kpi strong {
    font-size: 26px;
  }
  .kpi .spark {
    width: 100%;
    height: 24px;
  }
  .kpi-foot {
    gap: 4px 6px;
    font-size: 11.5px;
  }
  .action-list {
    max-height: none;
  }
  .action-item {
    padding: 9px 6px;
  }

  /* ------------------------------------------------------------ gráficos */

  .chart.compact .tick {
    font-size: 12.5px;
  }
  .chart.compact .value {
    font-size: 13px;
  }
  .chart-legend {
    gap: 6px 14px;
  }
  /* A regra base das roscas vem depois da antiga quebra de linha; aqui ela vale de fato. */
  .donut-wrap {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .donut-chart svg {
    width: min(100%, 190px);
  }
  .donut-legend b {
    white-space: normal;
  }
  .pareto-row {
    grid-template-columns: minmax(0, 1fr) 108px;
    grid-template-areas:
      'label value'
      'track track';
    gap: 4px 10px;
    padding: 6px;
  }
  .pareto-label {
    grid-area: label;
  }
  .pareto-track {
    grid-area: track;
  }
  .pareto-value {
    grid-area: value;
  }

  /* Saúde das BUs: títulos curtos, sem o ponto (a cor da célula já diz a situação). */
  .heatmap {
    border-spacing: 2px;
  }
  .heatmap thead th {
    padding: 4px 2px;
    font-size: 11px;
  }
  .heatmap thead th:first-child,
  .heatmap tbody th {
    width: 27%;
  }
  .heatmap tbody th {
    padding: 4px 4px 4px 0;
    font-size: 12.5px;
  }
  .heatmap tbody th .swatch {
    width: 9px;
    height: 9px;
    margin-right: 5px;
  }
  .heatmap .hm {
    padding: 9px 2px;
    font-size: 12.5px;
  }
  .heatmap .hm .hm-dot {
    display: none;
  }
  .heatmap .hm-action {
    width: 26px;
  }
  .heatmap .hm-action .icon-btn {
    width: 26px;
  }
  .hm-long {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .hm-short {
    display: inline !important;
  }

  /* ------------------------------------------------------------ Heijunka e Kanban */

  .board-mobile {
    display: block;
  }
  .lane-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 14px;
  }
  .lane-tab.drop {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    min-width: 0;
    min-height: 54px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--foreground);
    text-align: left;
  }
  .lane-tab span {
    max-width: 100%;
    overflow: hidden;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .lane-tab small {
    font-size: 11px;
    color: var(--muted-foreground);
  }
  .lane-tab b {
    position: absolute;
    top: 6px;
    right: 6px;
    min-width: 20px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 11px;
    line-height: 18px;
    text-align: center;
  }
  .lane-tab.today {
    border-color: var(--accent-border);
  }
  .lane-tab.today small {
    color: var(--accent);
    font-weight: 600;
  }
  .lane-tab.late b {
    border-color: transparent;
    background: var(--status-critical);
    color: #fff;
  }
  .lane-tab.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 2px var(--ring-soft);
  }
  .lane-tab.active span {
    color: var(--accent-soft-fg);
  }
  .lane-tab.drop.over {
    outline-offset: -2px;
  }
  .lane-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
  }
  .lane-head h2 {
    margin: 0;
    font-size: 16px;
  }
  .lane-sectors {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .lane-sector.drop {
    min-height: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
  }
  .lane-sector h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 8px;
    font-size: 13.5px;
  }
  .lane-sector h3 b {
    min-width: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: var(--muted);
    font-size: 11.5px;
    line-height: 20px;
    text-align: center;
  }
  /* Setor sem post-it no dia: só uma linha, ainda recebendo cards arrastados. */
  .lane-sector.empty {
    padding: 8px 10px;
    background: transparent;
    border-style: dashed;
  }
  .lane-sector.empty h3 {
    margin: 0;
    font-weight: 500;
    color: var(--muted-foreground);
  }
  .lane-sector .postit:last-child {
    margin-bottom: 0;
  }
  .lane-hint {
    margin: 12px 0 0;
    font-size: 12px;
    color: var(--muted-foreground);
  }
  /* Backlog e "fora desta janela": grade em vez de fileira para o lado. */
  .backlog {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
    gap: 8px;
    overflow: visible;
    padding: 0;
    min-height: 0;
  }
  .backlog .postit {
    width: auto;
    min-width: 0;
    margin: 0;
  }
  .postit {
    font-size: 13px;
  }
  /* Kanban: colunas empilhadas; as vazias ficam compactas. */
  .kanban {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    overflow: visible;
    padding: 0 0 8px;
  }
  .kanban-col {
    min-height: 0;
    padding: 10px;
  }
  .kanban-col h3 {
    margin: 0 0 8px;
  }
  .kanban-col:not(:has(.postit)) {
    padding: 8px 10px;
    border-style: dashed;
    background: transparent;
  }
  .kanban-col:not(:has(.postit)) h3 {
    margin: 0;
    font-weight: 500;
    color: var(--muted-foreground);
  }
  .legend {
    gap: 8px 12px;
  }

  /* ------------------------------------------------------------ Rotina MC */

  /* Um cartão por atividade; os cinco dias em mini-grade com o ícone da situação. */
  .table-wrap:has(> .routine-table) {
    overflow: visible;
  }
  .routine-table {
    display: block;
    min-width: 0;
  }
  .routine-table thead {
    display: none;
  }
  .routine-table tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .routine-table tr {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
  }
  .routine-table tbody th {
    grid-column: 1 / -1;
    position: relative;
    min-width: 0 !important;
    padding: 0 36px 8px 0 !important;
    border: 0;
    background: transparent;
  }
  .routine-table .routine-edit {
    top: -4px;
    right: -4px;
  }
  .routine-table td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    min-width: 0;
    padding: 4px 2px;
    border: 0;
    border-radius: 8px;
    text-align: center;
  }
  .routine-table td::before {
    content: attr(data-day) '\A' attr(data-date);
    white-space: pre;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--muted-foreground);
  }
  .routine-table td.today::before {
    color: var(--accent);
  }
  .routine-table .routine-chip {
    justify-content: center;
    min-height: 34px;
    padding: 0;
  }
  .routine-table .routine-chip span {
    display: none;
  }
  .routine-table .routine-chip .icon {
    width: 16px;
    height: 16px;
  }
  .routine-table .routine-off {
    display: grid;
    place-items: center;
    min-height: 34px;
  }
  /* Totais no celular: a linha de totais vira um cartão como as atividades, e a
     "Semana" ocupa a largura toda no pé de cada cartão. */
  .routine-table tfoot {
    display: block;
    margin-top: 10px;
  }
  .routine-table tfoot th,
  .routine-table tfoot td {
    border-top: 0;
  }
  .routine-table tfoot th {
    grid-column: 1 / -1;
    padding: 0 0 8px !important;
    background: transparent;
  }
  .routine-table td.routine-week-sum {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: center;
    align-items: baseline;
    gap: 8px;
    border-left: 0;
  }
  .routine-table td.routine-week-sum::before {
    content: 'Semana';
    white-space: normal;
  }
  .routine-table .routine-sum b {
    font-size: 12px;
  }
  .routine-table .routine-note {
    display: -webkit-box;
    overflow: hidden;
    font-size: 10.5px;
    line-height: 1.25;
    overflow-wrap: anywhere;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .routine-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted-foreground);
  }
  .routine-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .routine-legend .routine-chip {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
  }
  .routine-legend .routine-chip .icon {
    width: 13px;
    height: 13px;
  }

  /* ------------------------------------------------------------ A3 */

  .a3-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
  .a3-summary {
    flex-wrap: wrap;
  }
  .a3-summary > div {
    min-width: 0;
  }
  .hours-bar {
    min-width: 0;
  }
  .hours-groups {
    gap: 12px;
  }

  /* ------------------------------------------------------------ janelas */

  dialog:not(.drawer):not(.stepped):not(.gate-dialog) {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px);
  }
  .modal-head {
    padding: 12px 12px 12px 16px;
  }
  .modal-head h2 {
    font-size: 16.5px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-foot {
    flex-wrap: wrap;
    padding: 12px 16px;
  }
  .modal-foot > * {
    flex: 1 1 auto;
  }
  .modal-body .actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px;
  }
  .stepper li .step-label {
    font-size: 11px;
  }
  .range-row {
    flex-wrap: wrap;
  }
  .range-value {
    width: 96px;
  }
  .evidence {
    max-height: 200px;
  }

  /* ------------------------------------------------------------ Configurações */

  .settings-nav nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }
  .settings-nav nav button {
    width: 100%;
    min-width: 0;
    gap: 8px;
    padding: 9px 10px;
  }
  .settings-nav nav button span {
    overflow: hidden;
  }
  .settings-nav nav b {
    overflow: hidden;
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .settings-card {
    padding: 14px 16px;
  }
  .settings-card button {
    width: 100%;
  }
  .about-list div {
    flex-wrap: wrap;
    gap: 2px 12px;
    padding: 11px 14px;
  }
  .about-list dd {
    text-align: left;
    overflow-wrap: anywhere;
  }
  .session-row {
    flex-wrap: wrap;
  }
  .account-card {
    flex-wrap: wrap;
  }

  /* ------------------------------------------------------------ relatórios */

  .daily-report-bu .panel-head {
    align-items: flex-start;
  }
  .split > div {
    min-width: 0;
  }
}

/* Telas bem estreitas (até 380px): o quadro de dias cabe em três colunas. */
@media (max-width: 380px) {
  .lane-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stats,
  .kpis {
    gap: 8px;
  }
}

.hm-short {
  display: none;
}
