/* Integration gate: main must audit real interactions before merging.
   Screen only; no document, table, print, handler or business-logic changes. */
@media screen {
  .invoice-output {
    display: grid;
    gap: 10px;
    min-width: 0;
    align-content: start;
  }

  .invoice-output #invoice-download-pdf {
    margin: 0;
  }

  .invoice-output .invoice-preview {
    position: static;
  }

  .invoice-output .paper-table {
    min-width: 0;
    table-layout: fixed;
    font-size: 11px;
  }

  .invoice-output .paper-table :is(th, td) {
    padding: 7px 2px;
    overflow-wrap: anywhere;
  }

  #invoice_preview .paper-table :is(th, td):nth-child(1) { width: 30%; }
  #invoice_preview .paper-table :is(th, td):nth-child(2) { width: 10%; }
  #invoice_preview .paper-table :is(th, td):nth-child(3) { width: 16%; }
  #invoice_preview .paper-table :is(th, td):nth-child(4) { width: 12%; }
  #invoice_preview .paper-table :is(th, td):nth-child(5) { width: 9%; }
  #invoice_preview .paper-table :is(th, td):nth-child(6) { width: 23%; }

  @media (max-width: 620px) {
    #invoice_preview .paper-table { font-size: 12px; }
    #invoice_preview .paper-table :is(th, td):nth-child(n+2):nth-child(-n+5) { display: none; }
    #invoice_preview .paper-table :is(th, td):first-child { width: 70%; }
    #invoice_preview .paper-table :is(th, td):last-child { width: 30%; }
  }

  @media (min-width: 901px) {
    .invoice-output {
      position: sticky;
      top: 16px;
    }
  }

  /* Accounting rows retain their own compact grid and controls. */
  :is(#app, #main_menu) :where(button):not(:where(
    .accounting-workbench *, .invoice-paper *, table *, .document-dropzone
  )) {
    --hbc7-face: #f5f7fa;
    --hbc7-edge: #919ca8;
    --hbc7-depth: #b7c1ca;
    min-inline-size: 44px;
    min-block-size: 44px;
    max-inline-size: 100%;
    border: 1px solid var(--hbc7-edge);
    border-radius: 6px;
    background: var(--hbc7-face);
    color: #101418;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .85),
      0 2px 0 var(--hbc7-depth);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.4;
    letter-spacing: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
    text-overflow: clip;
    transition: transform 100ms ease, box-shadow 100ms ease,
      background-color 100ms ease, border-color 100ms ease;
  }

  #app button.primary {
    --hbc7-face: #56e6ff;
    --hbc7-edge: #297580;
    --hbc7-depth: #297580;
  }

  #app button.secondary {
    --hbc7-face: #e8faff;
    --hbc7-edge: #759ba4;
    --hbc7-depth: #9dbbc3;
  }

  #app button.ghost {
    --hbc7-face: #fff;
  }

  #app button:is(.primary, .secondary, .ghost) {
    padding: 10px 14px;
  }

  #app button:is(#new_company_btn, #new_client_btn, #new_invoice_btn,
    #new_contract_btn, #as_new_chat) {
    --hbc7-face: #ff4fd8;
    --hbc7-edge: #853475;
    --hbc7-depth: #853475;
    flex-shrink: 1;
  }

  #app button:is(#save_company_btn, #save_client_btn, #issue_invoice_btn,
    #save_contract_btn, #save_document_btn) {
    --hbc7-face: #43f59b;
    --hbc7-edge: #267c54;
    --hbc7-depth: #267c54;
    min-block-size: 48px;
  }

  #app button:is(.danger-text, .as-delete-button, .as-stop-voice,
    [data-del-contract], [data-delete-document], [data-remove-line],
    [data-as-file-remove], [data-chat-control="delete"]) {
    --hbc7-face: #fff0ee;
    --hbc7-edge: #b95852;
    --hbc7-depth: #d1a09c;
  }

  #app button:is(.as-mode-btn.is-active, .as-chat.is-active,
    .tab.is-active, .as-tool.on, .as-mic-btn.is-listening) {
    --hbc7-face: #dcfff0;
    --hbc7-edge: #267c54;
    --hbc7-depth: #7eae93;
    color: #101418;
    box-shadow: inset 0 -3px 0 #267c54, 0 1px 0 var(--hbc7-depth);
  }

  #app .as-chat.is-active small {
    color: #344b40;
  }

  #main_menu :is(.main-menu-list, .main-menu-tools) button {
    --hbc7-face: transparent;
    --hbc7-edge: transparent;
    --hbc7-depth: transparent;
    min-block-size: 44px;
    padding: 10px 11px;
    box-shadow: none;
    text-align: left;
  }

  #main_menu .main-menu-list button.is-active {
    --hbc7-face: #e3fbff;
    --hbc7-edge: #7fb8c2;
    box-shadow: inset 3px 0 0 #267580;
    font-weight: 750;
  }

  #main_menu .main-menu-list button.is-active .nav-icon {
    color: inherit;
  }

  /* Keep icon-only controls square and preserve existing display/hidden rules. */
  :is(#app, #main_menu) button:is(.main-menu-trigger, .main-menu-close,
    .as-icon-button, .as-copy-icon, .closing-icon-button,
    [data-remove-line], [data-delete-document], [data-as-file-remove]) {
    inline-size: 44px;
    block-size: 44px;
    flex: 0 0 44px;
    padding: 0;
    text-align: center;
  }

  #app #private_archive_refresh {
    inline-size: 44px;
    block-size: 44px;
    flex: 0 0 44px;
    padding: 0;
  }

  #app .as-form .as-mic-btn {
    inline-size: 64px;
    max-inline-size: 64px;
    flex: 0 0 64px;
    padding: 8px;
    overflow: visible;
  }

  #app .active-company-pill {
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
  }

  @media (hover: hover) and (pointer: fine) {
    :is(#app, #main_menu) button:not(:where(.accounting-workbench *,
      .invoice-paper *, table *, .document-dropzone)):where(:not(:disabled):not([aria-disabled="true"]):not([aria-busy="true"])):hover {
      transform: translateY(-1px);
      box-shadow: inset 0 1px 0 #fff, 0 3px 0 var(--hbc7-depth);
    }

    #main_menu :is(.main-menu-list, .main-menu-tools) button:not(:disabled):hover {
      background: #edf6f8;
      box-shadow: none;
      transform: none;
    }

    #main_menu .main-menu-list button.is-active:not(:disabled):hover {
      box-shadow: inset 3px 0 0 #267580;
    }
  }

  :is(#app, #main_menu) button:not(:where(.accounting-workbench *,
    .invoice-paper *, table *, .document-dropzone)):where(:not(:disabled):not([aria-disabled="true"]):not([aria-busy="true"])):active {
    transform: translateY(2px);
    box-shadow: inset 0 1px 2px rgba(16, 20, 24, .18);
  }

  :is(#app, #main_menu) button:not(:where(.accounting-workbench *,
    .invoice-paper *, table *, .document-dropzone)):focus-visible {
    outline: 3px solid #1453b8;
    outline-offset: 3px;
  }

  :is(#app, #main_menu) button:not(:where(.accounting-workbench *,
    .invoice-paper *, table *, .document-dropzone)):is(:disabled, [aria-disabled="true"]) {
    background: #e6e9ed;
    border-color: #aab2bb;
    border-style: dashed;
    color: #505a66;
    box-shadow: none;
    opacity: 1;
    cursor: not-allowed;
    transform: none;
  }

  /* Busy comes from existing form/history state, never from disabled alone. */
  #app button[aria-busy="true"],
  #app #as_form:is([data-busy="1"], [aria-busy="true"]) .as-send,
  #app #as_conversations[aria-busy="true"] [data-chat-control],
  #app [data-panel="asistente"]:has(#as_conversations[aria-busy="true"])
    #as_history_export {
    background: #ffc766;
    border: 1px solid #805714;
    color: #101418;
    box-shadow: inset 0 -3px 0 #805714;
    opacity: 1;
    cursor: wait;
    transform: none;
  }

  #app .as-msg,
  #app .as-msg :where(p, li, .as-source, .as-actions-log > div,
    .as-development-card, .as-command-summary) {
    font-size: 18px;
    line-height: 1.6;
  }

  #app .as-form textarea {
    /* workspace.css uses !important for mobile inputs. */
    font-size: 18px !important;
    line-height: 1.5;
  }

  #app [data-tooltip]::after {
    max-inline-size: min(280px, calc(100vw - 32px));
    white-space: normal;
    overflow-wrap: anywhere;
  }

  @media (max-width: 620px) {
    #app .module-heading {
      flex-wrap: wrap;
    }

    #app .module-heading > button {
      flex-shrink: 1;
      max-inline-size: 100%;
    }

    #app .editor-actions > button {
      flex: 1 1 140px;
    }

    #app .company-card .card-actions button {
      min-inline-size: 0;
      padding-inline: 8px;
    }
  }

  @media (max-width: 420px) {
    #app .app-back-button {
      inline-size: 44px;
      block-size: 44px;
      flex: 0 0 44px;
      padding: 0;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    :is(#app, #main_menu) button:not(:where(.accounting-workbench *,
      .invoice-paper *, table *, .document-dropzone)) {
      transition: none;
      animation: none;
      transform: none !important;
    }

    #app .as-activity::before {
      animation: none;
    }
  }
}
