/* MELAPORA V358 — shared default/dark presentation corrections.
   This is intentionally screen-only: generated invoice/quotation PDFs and print
   pages keep their independent tax-document styles. Backend access is unchanged. */
@media screen {
  html[data-melapora-theme] {
    --mp-card: var(--theme-surface);
    --mp-muted: var(--theme-muted);
    --card-bg: var(--theme-surface-2);
    --card: var(--theme-surface);
    --line: var(--theme-border);
    --text: var(--theme-text);
  }
  #accountView > .wrap {
    width:min(1180px,calc(100% - 32px)) !important;
    max-width:1180px !important;
    margin-inline:auto !important;
    box-sizing:border-box;
  }
  #melAdminBillingPanel[hidden],#melAdmBilling[hidden],#melCustomerRefunds[hidden],
  #melAdminBillingTab[hidden] {display:none !important;}
  #melAdminBillingPanel {min-width:0;max-width:100%;}
  #melAdminBillingPanel :is(.meladm-tablewrap,.gstscroll,.mgc-panel,.gcp-table-wrap,.reconscroll,.scroll) {
    max-width:100%;min-width:0;
  }
  #melAdminBillingPanel :is(table) {white-space:normal;}
  #melAdmBilling,#melCustomerRefunds,#melGstCenter,#melGstCheckpoint,
  #melGstDebits,#melGstDocumentEntry,#melGstClassification,#melGstAudit,
  #melGstAdmin,#melStorageSupplierReview {
    background:var(--theme-surface) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
    min-width:0;
    max-width:100%;
    box-sizing:border-box;
  }
  #melAdminBillingPanel :is(.mgc-panel,.mgc-more,.gcp-tile,.meladm-stat,details) {
    border-color:var(--theme-border);
  }
  #melAdminBillingPanel :is(.meladm-note,.meladm-empty,.mgc-note,.mgc-step,.gcp-muted,.reconstatus,.dnstatus) {
    color:var(--theme-muted) !important;
  }
  #melAdminBillingPanel :is(.meladm-bar,.meladm-filters,.mgc-panel) {min-width:0;}
  #melAdminBillingPanel .meladm-tablewrap {overflow-x:auto;}
  #melCustomerRefunds textarea {min-width:0;}

  /* Document lists were not covered by V357: the actual class is .md21-item. */
  html[data-melapora-theme="dark"] #md21Panel :is(.md21-item,.md21-status) {
    background:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #md21Panel .md21-item :is(b,strong,small,span) {
    color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] #md21Panel .md21-item small,
  html[data-melapora-theme="dark"] #md21Panel .md21-status {color:var(--theme-muted) !important;}

  /* Legacy team chat has a light bottom composer and hard-coded muted labels. */
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(
    .mt20-chat-compose,.mt20-room-status,.mt20-chat-footer,.mt20-room-footer,
    .mt20-room-content,.mt20-room-topbar,.mt20-whatsapp-heading
  ) {background:var(--theme-surface) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(#mt20RoomStatus,#mt20RoomMessage,#mt20RoomSearch) {
    background:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(.mt20-room-msg,.mt20-room-choice) :is(small,time,span) {
    color:var(--theme-muted) !important;
  }

  /* The Meta/WhatsApp setup cards still used body.dark instead of the real root attr. */
  html[data-melapora-theme="dark"] #melWhatsAppInbox :is(
    .mel-connect-panel,.mel-connect-steps>div,.mel-inbox-list,.mel-inbox-conversation,
    .mel-inbox-form,.mel-inbox-conversation-head,.mel-inbox-shell
  ) {background:var(--theme-surface) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}
  html[data-melapora-theme="dark"] #melWhatsAppInbox :is(.mel-connect-head p,.mel-connect-steps small,
    .mel-inbox-header p,.mel-inbox-form-bottom small,.mel-inbox-placeholder,.mel-connect-badge) {
    color:var(--theme-muted) !important;
  }
  html[data-melapora-theme="dark"] #melWhatsAppInbox .mel-connect-badge,
  html[data-melapora-theme="dark"] #melWhatsAppInbox .mel-inbox-person[aria-current="true"] {
    background:var(--theme-selected) !important;color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] #melWhatsAppInbox :is(.mel-inbox-messages,.mel-inbox-bubble,.mel-inbox-person) {
    background:var(--theme-surface-2) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #melWhatsAppInbox .mel-inbox-bubble.out {
    background:var(--theme-selected) !important;color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] #melWhatsAppInbox .mel-inbox-notice,
  html[data-melapora-theme="dark"] #melWhatsAppInbox .mel-inbox-person small {color:var(--theme-muted) !important;}

  /* Admin-only financial dashboard: override inline styles inserted by the JS module. */
  html[data-melapora-theme="dark"] #melAdmBilling :is(.meladm-stat,.meladm-tabs button:not([aria-selected="true"])) {
    background:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #melAdmBilling .meladm-stat :is(small,strong) {
    color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] #melAdmBilling .meladm-stat small {color:var(--theme-muted) !important;}
  html[data-melapora-theme="dark"] #melAdmBilling :is(td,.meladm-tablewrap) {border-color:var(--theme-border) !important;color:var(--theme-text) !important;}
  html[data-melapora-theme="dark"] #melAdminBillingPanel :is(
    input:not([type="checkbox"]):not([type="radio"]),select,textarea
  ) {background:var(--theme-surface-2) !important;color:var(--theme-text) !important;border-color:var(--theme-border-strong) !important;}
  html[data-melapora-theme="dark"] #melAdminBillingPanel :is(
    .gcp-tile,.mgc-panel,.mgc-more,#melGstr1Offline,details:not(.mel-export-menu)
  ) {background:var(--theme-surface-2) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}
  html[data-melapora-theme="dark"] #melAdminBillingPanel .gcp-tile strong,
  html[data-melapora-theme="dark"] #melAdminBillingPanel .mgc-links a {color:#a8c9ff !important;}
  /* Notice blocks retain warning/error semantics rather than blending with the background. */
  html[data-melapora-theme="dark"] #melAdminBillingPanel :is(.gcp-info,.meladm-empty,.mgc-step) {
    background:var(--theme-surface-2) !important;color:var(--theme-muted) !important;
    border-color:var(--theme-border) !important;
  }
  @media(max-width:720px) {
    #accountView > .wrap{width:calc(100% - 24px) !important;}
    #melAdmBilling,#melGstCenter,#melGstCheckpoint{padding:14px !important;}
    #melAdmBilling .meladm-filters>*{flex:1 1 135px;min-width:0;}
  }
}
