/* InfraMINA · camada final compartilhada
   Organiza ritmo, enquadramento e responsividade sem alterar os fluxos. */

@media screen {
  :root {
    --ui-page-gutter: var(--container-gutter);
    --ui-section-gap: clamp(1rem, 1.8vw, 1.5rem);
    --ui-control-height: 44px;
    --ui-content-max: var(--container-app);
  }

  /* Contêiner. Uma classe, a mesma régua em qualquer pagina: largura
     maxima travada no token e centralizada, com respiro lateral que
     nunca deixa o conteudo encostar na borda. */
  .container {
    width: min(calc(100% - 2 * var(--container-gutter)), var(--container-site));
    margin-inline: auto;
  }
  .container-wide { --container-site: var(--container-app); }

  body {
    font-family: var(--font-body, Archivo), system-ui, sans-serif;
    text-rendering: optimizeLegibility;
  }

  :where(button, input, select, textarea) { font: inherit; }
  :where(p, td, th, label, button, input, select, textarea) { overflow-wrap: anywhere; }
  :where(.content, .tc-content, .section-inner, .container) > * { min-width: 0; }

  /* Site público */
  .landing-page .header-inner,
  .landing-page .hero-inner,
  .landing-page .section-inner,
  .landing-page .banner-inner,
  .landing-page .footer-inner,
  .landing-page .footer-copy {
    width: min(calc(100% - 2 * var(--container-gutter)), var(--container-site));
    margin-inline: auto;
  }
  .landing-page .header { border-bottom-color: var(--console-line, #34495b); }
  .landing-page .header-inner { min-height: 72px; }
  .landing-page .nav { gap: clamp(.9rem, 2vw, 1.8rem); }
  .landing-page .nav a { line-height: 1.25; }
  .landing-page .hero-content { max-width: 760px; }
  .landing-page .hero h1 { max-width: 18ch; text-wrap: balance; }
  .landing-page .hero p { max-width: 62ch; line-height: 1.7; }
  .landing-page .section { padding-block: clamp(4rem, 8vw, 7rem); }
  .landing-page .section-head { max-width: 760px; margin-bottom: clamp(2rem, 4vw, 3.5rem); }
  .landing-page .section-head h2 { text-wrap: balance; }
  .landing-page :where(.pillar-card, .principle, .gallery-item) {
    min-width: 0;
    border-color: var(--console-line, #34495b);
  }
  .landing-page :where(.pillar-card, .principle) p { line-height: 1.65; }
  .landing-page :where(.btn-primary, .btn-outline, .btn-white) {
    min-height: var(--ui-control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 1.15rem;
  }
  /* O segundo acesso existe apenas para substituir a navegação no celular. */
  .landing-page .header-inner > .btn-white { display: none; }

  /* Autenticação */
  .auth-gate { padding: clamp(1rem, 4vw, 2rem); }
  .auth-card {
    width: min(100%, 460px);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
  }
  .auth-card-head { gap: 1rem; }
  .auth-card-head img { flex: 0 0 auto; }
  .auth-form { gap: .8rem; }
  .auth-field { gap: .4rem; }
  .auth-form .btn { width: 100%; min-height: var(--ui-control-height); }

  /* Estrutura dos dois sistemas */
  .app .content,
  .tc-content { padding: var(--ui-page-gutter); }
  .app .view,
  .tc-content > * { width: min(100%, var(--ui-content-max)); margin-inline: auto; }
  .app .topbar { gap: 1rem; }
  .app .topbar-title { min-width: 0; }
  .app .topbar-title h1 { text-wrap: balance; }
  .app .toolbar,
  .card-head,
  .modal-head,
  .modal-foot,
  .tc-actions { gap: .65rem; }

  /* Seções, cartões e hierarquia */
  .app .view > :where(.card, .stats, .layout-split, .daily-block, .technical-section, .empty-state) + *,
  #tcFormSections > * + * { margin-top: var(--ui-section-gap); }
  :where(.app, .terceirizada-page) :where(.card-head, .modal-head, .daily-block-head) {
    min-height: 58px;
    padding: .9rem 1rem;
  }
  :where(.app, .terceirizada-page) :where(.card-head, .modal-head) > div { min-width: 0; }
  :where(.app, .terceirizada-page) :where(.card-head, .modal-head) h3 {
    line-height: 1.25;
    text-wrap: balance;
  }
  :where(.app, .terceirizada-page) :where(.card-head, .modal-head) p {
    margin-top: .25rem;
    max-width: 70ch;
    line-height: 1.45;
  }
  :where(.app, .terceirizada-page) :where(.card-body, .modal-body) { padding: clamp(1rem, 2vw, 1.35rem); }

  /* O relatório é composto por cartões sem um `.card-body` explícito.
     Estes recuos criam o mesmo enquadramento dos demais cartões sem
     alterar o HTML dinâmico nem reduzir a área útil das tabelas. */
  .app .daily-report { gap: var(--ui-section-gap); }
  .app .daily-block-head {
    border-bottom-color: var(--console-line-strong);
  }
  .app .daily-block-head > div {
    min-width: 0;
    flex-wrap: wrap;
  }
  .app .daily-block-head strong {
    line-height: 1.3;
    text-wrap: balance;
  }
  .app .daily-block > .daily-grid {
    padding: 1rem;
    gap: 1rem;
  }
  .app .daily-block > textarea.form-control {
    margin: 1rem;
    width: calc(100% - 2rem);
  }
  .app .daily-block > .table-wrap + .daily-totals {
    border-top: 0;
  }
  .app .daily-block > .daily-totals {
    padding: .85rem 1rem;
  }
  .app .daily-block > .daily-activity {
    margin-top: 1rem;
  }
  .app .daily-block > .daily-photos {
    margin: 0 1rem 1rem;
    padding-top: .9rem;
    border-top: 1px solid var(--console-line);
  }
  .app .daily-block > textarea.form-control + .daily-photos {
    margin-top: 0;
  }
  .app .daily-photo-add {
    width: 100%;
    justify-content: center;
  }
  .app .daily-environmental > .material-adjust-note {
    margin: 0;
    padding: 0 1rem 1rem;
    line-height: 1.5;
  }
  .app .daily-section-title {
    padding: .35rem .15rem;
    align-items: center;
  }

  /* Formulários */
  :where(.app, .terceirizada-page) :where(.form-row, .form-grid, .tc-fields-grid) {
    align-items: start;
  }
  :where(.app, .terceirizada-page) :where(.form-group, .tc-field, label) { min-width: 0; }
  :where(.app, .terceirizada-page) :where(.form-group, .tc-field) > label {
    display: block;
    margin-bottom: .42rem;
    line-height: 1.25;
  }
  :where(.app, .terceirizada-page) :where(.form-control, .cell-in) {
    width: 100%;
    min-width: 0;
    min-height: var(--ui-control-height);
    padding: .68rem .75rem;
    line-height: 1.3;
  }
  :where(.app, .terceirizada-page) textarea.form-control { min-height: 96px; resize: vertical; }
  :where(.app, .terceirizada-page) .form-hint {
    display: block;
    margin-top: .42rem;
    color: var(--console-muted);
    font-size: var(--t-sm);
    line-height: 1.45;
  }
  :where(.app, .terceirizada-page) .qe-mobilization-field {
    padding: .85rem;
    border: 1px solid var(--console-line);
    background: var(--console-panel-2);
  }
  :where(.app, .terceirizada-page) .qe-mobilization-field[hidden] { display: none; }
  :where(.app, .terceirizada-page) .number-stepper { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  :where(.app, .terceirizada-page) .number-stepper button { min-width: 44px; min-height: 44px; }

  /* Botões e ações */
  :where(.app, .terceirizada-page) .btn {
    min-height: 40px;
    padding: .62rem .9rem;
    line-height: 1.15;
    text-align: center;
  }
  :where(.app, .terceirizada-page) .btn-icon { width: 40px; padding-inline: 0; flex: 0 0 40px; }
  :where(.app, .terceirizada-page) .modal-close { flex: 0 0 40px; width: 40px; height: 40px; }

  /* Tabelas */
  :where(.app, .terceirizada-page) .table-wrap {
    max-width: 100%;
    overscroll-behavior-inline: contain;
  }
  :where(.app, .terceirizada-page) table { width: 100%; border-collapse: collapse; }
  :where(.app, .terceirizada-page) th {
    padding: .72rem .75rem;
    line-height: 1.25;
    text-align: left;
    vertical-align: bottom;
  }
  :where(.app, .terceirizada-page) td {
    padding: .68rem .75rem;
    line-height: 1.4;
    vertical-align: middle;
  }
  :where(.app, .terceirizada-page) .actions-cell { width: 1%; white-space: nowrap; }

  /* Modais */
  .modal-overlay { padding: clamp(.75rem, 3vw, 2rem); }
  .modal { width: min(100%, 640px); }
  .modal.lg { width: min(100%, 860px); }
  .modal.xl { width: min(100%, 1120px); }
  .modal-foot { flex-wrap: wrap; }

  /* Estados vazios e feedback */
  :where(.empty, .empty-state, .empty-inline) {
    min-height: 120px;
    display: grid;
    place-content: center;
    gap: .65rem;
    padding: clamp(1.25rem, 3vw, 2.25rem);
    text-align: center;
    line-height: 1.55;
  }
  .toast { max-width: min(420px, calc(100vw - 2rem)); line-height: 1.45; }

  /* Terceirizada */
  .tc-intro { display: grid; gap: .3rem; }
  .tc-intro h1 { text-wrap: balance; }
  .tc-team-card { min-width: 0; }
  .tc-team-numbers { align-items: start; }
  .tc-actions { flex-wrap: wrap; }

  /* Mapas e áreas densas */
  .map3d-head,
  .map3d-toolbar { flex-wrap: wrap; }
  .map3d-head-actions { flex-wrap: wrap; justify-content: flex-end; }
  .map3d-toolbar > * { min-width: 0; }
  .kanban-board { align-items: start; }
  .kanban-col { min-width: min(280px, 85vw); }

  @media (max-width: 900px) {
    .landing-page .nav { display: none; }
    .app .topbar { align-items: flex-start; }
    .app .toolbar { width: 100%; overflow-x: auto; padding-bottom: .2rem; }
    :where(.app, .terceirizada-page) :where(.form-row, .form-grid) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .app .daily-block > .daily-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (max-width: 640px) {
    :root { --ui-page-gutter: .8rem; --ui-section-gap: .8rem; }
    .landing-page .header-inner,
    .landing-page .hero-inner,
    .landing-page .section-inner,
    .landing-page .banner-inner,
    .landing-page .footer-inner { width: min(calc(100% - 1.25rem), 1240px); }
    .landing-page .header-inner {
      max-width: 100%;
      gap: .75rem;
      padding-inline: .35rem;
    }
    .landing-page .logo { min-width: 0; }
    .landing-page .logo-icon { flex: 0 0 auto; }
    .landing-page .logo-text { font-size: .82rem; }
    .landing-page .header-inner > .btn-white {
      flex: 0 0 auto;
      padding-inline: .8rem;
      font-size: .7rem;
    }
    .landing-page .hero { overflow: hidden; }
    .landing-page .hero-content,
    .landing-page .hero-content p { max-width: 100%; }
    .landing-page .section { padding-block: 3.5rem; }
    .landing-page .header-inner > .btn-white { display: inline-flex; }
    .auth-gate { padding: .65rem; }
    .auth-card { max-height: calc(100dvh - 1.3rem); }
    :where(.app, .terceirizada-page) :where(.form-row, .form-grid, .tc-fields-grid) { grid-template-columns: 1fr; }
    .app .daily-block > .daily-grid { grid-template-columns: 1fr; padding: .8rem; }
    .app .daily-block > textarea.form-control {
      margin: .8rem;
      width: calc(100% - 1.6rem);
    }
    .app .daily-block > .daily-photos { margin: 0 .8rem .8rem; }
    :where(.app, .terceirizada-page) :where(.card-head, .modal-head, .daily-block-head) { align-items: flex-start; }
    :where(.app, .terceirizada-page) .modal-foot > .btn { flex: 1 1 140px; }
    .tc-actions .btn { flex: 1 1 100%; }
    .map3d-head-actions { width: 100%; justify-content: stretch; }
    .map3d-head-actions .btn { flex: 1; }
  }

  /* ——— Zoom do navegador · a altura util e que encolhe ———
     Ampliar a pagina nao aumenta a tela: reduz a viewport em pixels CSS.
     A largura menor acionava o arranjo de celular — que empilha a tira de
     cotacoes — bem onde ja faltava altura, e a moldura fixa passava a
     ocupar quase metade da tela antes de qualquer conteudo. As regras
     abaixo olham a altura, nao a largura: valem para 150% de zoom num
     notebook e para o telefone deitado, e nao mexem no celular em pe. */
  @media (max-height: 620px) {
    /* A tira volta para uma linha so, com rolagem lateral, como no desktop. */
    .market-ticker-strip { flex-direction: row; align-items: center; gap: .6rem; }
    .market-ticker-items { width: auto; }
    .market-chip { grid-template-columns: auto auto auto; align-items: baseline; min-width: 0; }

    /* A marca cede altura para o menu manter itens a vista. */
    .app .brand { min-height: 0; padding-block: .5rem; }
    .app .brand h2 { font-size: 1rem; }
    .app .brand-logo-frame { width: 34px; height: 32px; }
    .app .brand-logo-top { width: 34px; height: 32px; }
  }

  @media (max-height: 460px) {
    /* Cotacao e contexto, nao tarefa: a partir daqui a tela e do trabalho. */
    .market-ticker { display: none; }
    .app .topbar { min-height: 0; padding-block: .5rem; }
    .app .topbar-title h1 { font-size: 1.05rem; }
    .app .topbar-title span { display: none; }
  }
}

/* ——— Biblioteca de Atividades ————————————————————————————————————————
   Segue o mesmo mundo do resto do sistema: cartão claro sobre o preto de
   galeria, raio zero, rótulo em versal e valor em fonte tabular. Nada de
   linguagem visual nova — a Biblioteca é mais uma via do mesmo documento. */
@media screen {
  .app .library-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: .75rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--console-line);
  }
  .app .library-filters .library-search { grid-column: 1 / -1; }

  .app .library-count {
    margin: .9rem 0 .7rem;
    color: var(--console-muted);
    font-family: var(--font-label, Archivo), sans-serif;
    font-size: var(--t-label);
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  .app .library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: .85rem;
  }

  .app .library-card {
    display: flex;
    flex-direction: column;
    gap: .7rem;
    padding: .95rem;
    border: 1px solid var(--console-line);
    background: var(--console-panel-2);
  }
  /* Arquivada e inativa perdem cor, como o "vencido" do resto do sistema. */
  .app .library-card.is-archived,
  .app .library-card.is-inactive { opacity: .62; }
  .app .library-card.is-archived { border-style: dashed; }

  .app .library-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .6rem;
  }
  .app .library-card-head h4 {
    font-size: var(--t-value);
    line-height: 1.3;
    text-wrap: balance;
  }
  .app .library-flag {
    flex: 0 0 auto;
    padding: .12rem .4rem;
    border: 1px solid var(--console-line-strong);
    color: var(--console-muted);
    font-family: var(--font-label, Archivo), sans-serif;
    font-size: var(--t-micro);
    letter-spacing: .06em;
    text-transform: uppercase;
  }

  .app .library-card-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem .8rem;
  }
  .app .library-card-facts dt,
  .app .library-detail dt {
    color: var(--console-muted);
    font-family: var(--font-label, Archivo), sans-serif;
    font-size: var(--t-micro);
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  .app .library-card-facts dd,
  .app .library-detail dd {
    margin-top: .16rem;
    color: var(--console-text);
    font-size: var(--t-sm);
    line-height: 1.35;
  }

  .app .library-codes {
    color: var(--console-muted);
    font-family: var(--font-value, 'Fira Mono'), monospace;
    font-size: var(--t-micro);
    letter-spacing: .08em;
  }

  .app .library-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: auto;
    padding-top: .7rem;
    border-top: 1px solid var(--console-line);
  }
  .app .library-card-actions .btn { flex: 1 1 auto; min-height: 36px; padding-inline: .6rem; }

  /* Detalhes e regra */
  .app .library-detail { display: grid; gap: .7rem; }
  .app .library-detail-row { display: grid; gap: .1rem; }
  /* Painel regrado, como o resto do mundo "Permissão de Trabalho": régua
     inteira e raio zero, e não uma tarja de acento em um lado só. */
  .app .library-detail-desc,
  .app .library-rule-text {
    margin-bottom: 1rem;
    padding: .8rem;
    border: 1px solid var(--console-line);
    background: var(--console-panel-2);
    line-height: 1.55;
  }
  .app .library-detail-subtitle {
    margin: 1.2rem 0 .5rem;
    font-family: var(--font-label, Archivo), sans-serif;
    font-size: var(--t-label);
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  .app .library-log { display: grid; gap: .3rem; list-style: none; }
  .app .library-log li {
    padding: .4rem .55rem;
    border: 1px solid var(--console-line);
    color: var(--console-muted);
    font-size: var(--t-sm);
  }

  .app .library-rule-fields {
    padding: .9rem;
    border: 1px solid var(--console-line);
    background: var(--console-panel-2);
  }
  .app .library-rule-fields[hidden] { display: none; }

  /* Escolher da biblioteca */
  .app .library-picker-list {
    display: grid;
    gap: .35rem;
    max-height: min(52vh, 460px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .app .library-picker-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: .65rem;
    padding: .6rem .7rem;
    border: 1px solid var(--console-line);
    cursor: pointer;
  }
  .app .library-picker-item:hover { background: var(--console-panel-2); }
  .app .library-picker-item input { margin-top: .2rem; }
  .app .library-picker-item strong { display: block; line-height: 1.3; }
  .app .library-picker-item small {
    display: block;
    margin-top: .15rem;
    color: var(--console-muted);
    font-size: var(--t-sm);
  }

  @media (max-width: 640px) {
    .app .library-grid { grid-template-columns: 1fr; }
    .app .library-card-facts { grid-template-columns: 1fr; }
    .app .library-card-actions .btn { flex: 1 1 100%; }
  }
}

/* Reordenar a biblioteca arrastando os cards. */
@media screen {
  .app .library-card[draggable="true"] { cursor: grab; }
  .app .library-card.is-dragging { opacity: .4; cursor: grabbing; }
  .app .library-card.is-drop-target { outline: 2px dashed var(--stamp-void, var(--console-line-strong)); outline-offset: 2px; }
  @media (hover: none) and (pointer: coarse) {
    /* No toque o arrasto disputa com a rolagem: a ordem se ajusta no desktop. */
    .app .library-card[draggable="true"] { cursor: default; }
  }
}
