/* MELAPORA V357: ONE SHARED THEME (screen only)
 * The live app stores preference in localStorage.melapora_color_mode and sets
 * html[data-melapora-theme="dark"|"default"]. Do NOT use only data-theme.
 * Load AFTER melapora-professional-v339.css AND melapora-v354-visual-fixes.css.
 * Never force these app colors into PDF/print output.
 */
:root,
html[data-melapora-theme="default"] {
  color-scheme: light;
  --theme-bg: #eef5ff;
  --theme-surface: #ffffff;
  --theme-surface-2: #f3f7ff;
  --theme-text: #102042;
  --theme-muted: #536581;
  --theme-hint: #647892;
  --theme-border: #d5e1f3;
  --theme-border-strong: #b6c9e4;
  --theme-accent: #245fdb;
  --theme-hover: #e8f1ff;
  --theme-selected: #dbe9ff;
}
html[data-melapora-theme="dark"] {
  color-scheme: dark;
  --theme-bg: #0b1425;
  --theme-surface: #152238;
  --theme-surface-2: #1b2c46;
  --theme-text: #f0f6ff;
  --theme-muted: #c6d5ed;
  --theme-hint: #aec3e0;
  --theme-border: #344a69;
  --theme-border-strong: #567096;
  --theme-accent: #87b4ff;
  --theme-hover: #253c5e;
  --theme-selected: #274671;
}
@media screen {
  /* The shared tokens belong to the account, workspace, and public shell.
     These aliases keep older module variables in sync without changing logic. */
  html[data-melapora-theme] {
    --mel-bg: var(--theme-bg);
    --mel-panel: var(--theme-surface);
    --mel-panel-2: var(--theme-surface-2);
    --mel-text: var(--theme-text);
    --mel-subtle: var(--theme-muted);
    --mel-hint: var(--theme-hint);
    --mel-border: var(--theme-border);
    --mel-border-strong: var(--theme-border-strong);
    --mel-hover: var(--theme-hover);
    --mp-bg: var(--theme-bg);
    --mp-panel: var(--theme-surface);
    --mp-text: var(--theme-text);
    --mp-sub: var(--theme-muted);
    --mp-border: var(--theme-border);
  }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate) {
    background-color: var(--theme-bg) !important;
    color: var(--theme-text) !important;
  }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate) :is(
    .campaign-panel,.profileBox,.panel,.card,.tablewrap,.table-box,.data,
    .mel-tool-help,.mel-home-section,.mel-home-dashboard,.appearance-collapsible
  ) {
    background-color: var(--theme-surface) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
  }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate)
    :is(input:not([type="checkbox"]):not([type="radio"]),textarea,select) {
    background: var(--theme-surface-2) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border-strong) !important;
  }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate)
    :is(input,textarea)::placeholder { color:var(--theme-hint) !important; opacity:1; }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate)
    :is(.mini,.muted,.appnote,.st-muted) { color:var(--theme-muted) !important; }
  html[data-melapora-theme] :is(#app,#accountView,#memberGate)
    :is(table,tbody,thead,tr,th,td) { border-color: var(--theme-border) !important; }

  /* Tool-help cards were white in some modules even when the surrounding app was dark. */
  html[data-melapora-theme="dark"] #app .mel-tool-help :is(details,summary,p,ul,li) {
    background-color: var(--theme-surface-2) !important;
    color: var(--theme-text) !important;
    border-color: var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #app .mel-tool-help :is(small,.mini,.muted) {
    color: var(--theme-muted) !important;
  }

  /* Feature 21 – Documents: counters, folder pane, file list, file labels. */
  html[data-melapora-theme="dark"] #md21Panel :is(
    .md21-metric,.md21-surface,.md21-file,.md21-file-row,.md21-folder,.md21-folder-row,
    .md21-entry,.md21-list-item,.md21-grid,.md21-list
  ) {
    background-color:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #md21Panel :is(
    .md21-metric,.md21-surface,.md21-file,.md21-folder,.md21-entry,.md21-list-item
  ) :is(h2,h3,h4,p,span,strong,b,label,small,time) { color:var(--theme-text) !important; }
  html[data-melapora-theme="dark"] #md21Panel :is(.mini,.muted,.md21-label) {
    color:var(--theme-muted) !important;
  }
  /* Keep action buttons coloured according to their own states. */

  /* Feature 12 – Support tickets. */
  html[data-melapora-theme="dark"] #melaporaSupport :is(.st-stat,.st-card,.st-history) {
    background-color:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #melaporaSupport :is(.st-stat,.st-card,.st-history)
    :is(strong,b,h3,span,small) { color:var(--theme-text) !important; }
  html[data-melapora-theme="dark"] #melaporaSupport .st-muted {color:var(--theme-muted) !important;}

  /* Feature 3 – Quotation catalogue lookup and selection. */
  html[data-melapora-theme="dark"] #melaporaQuotes :is(
    .mq-catalogue-picker,.mq-card,.mq-line-editor,.mq-list,.mq-items
  ) {
    background-color:var(--theme-surface-2) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #melaporaQuotes .mq-catalogue-picker :is(label,p,span,small) {
    color:var(--theme-muted) !important;
  }

  /* Features 15 & 16 – public enquiry forms and product catalogue inside app. */
  html[data-melapora-theme="dark"] :is(#melaporaEnquiryForms,#melaporaCatalogue)
    :is(.campaign-panel,.panel,.card,.mf-card,.tablewrap,article) {
    background-color:var(--theme-surface) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] :is(#melaporaEnquiryForms,#melaporaCatalogue)
    :is(.mini,.muted,small,.appnote) {color:var(--theme-muted) !important;}

  /* Feature 20 – Team chat (legacy chat module hardcoded light panels). */
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(
    .mt20-chat-sidebar,.mt20-app-rail,.mt20-room-topbar,.mt20-whatsapp-heading,
    .mt20-chat-compose,.mt20-chat-grid,.mt20-chat-list,.mt20-room-content,
    .mt20-room-history,.mt20-chat-filters,.mt20-room-msg,.mt20-msg-options
  ) {
    background-color:var(--theme-surface) !important;
    color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(
    .mt20-room-msg.mine,.mt20-room-choice.active,.mt20-room-choice:hover
  ) {background-color:var(--theme-selected) !important;color:var(--theme-text) !important;}
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(
    .mt20-chat-sidebar,.mt20-room-history,.mt20-room-topbar,.mt20-room-msg
  ) :is(h2,h3,h4,p,span,b,strong,label,time,small) {color:var(--theme-text) !important;}
  html[data-melapora-theme="dark"] #mt20DirectGroups :is(
    input:not([type="checkbox"]),textarea,select
  ) {background-color:var(--theme-surface-2) !important;color:var(--theme-text) !important;border-color:var(--theme-border) !important;}

  /* Account centre: don't confine the profile layout to a tiny desktop column.
     Browser zoom is separate; Ctrl+0 resets browser zoom to 100%. */
  #accountView > .wrap {width:min(1160px,calc(100% - 32px)) !important;max-width:1160px !important;}
  #accountView .mel-account-tabs {display:flex;flex-wrap:wrap;gap:8px;}
  html[data-melapora-theme="dark"] #accountView :is(
    .profileBox,.accountFields,.mel-acct-panel,.mel-account-section
  ) {color:var(--theme-text) !important;border-color:var(--theme-border) !important;}

  /* Public SEO pages use the very same preference, but keep their own layout. */
  html[data-melapora-theme="dark"] body.mel-seo-page {
    --bg:var(--theme-bg);--white:var(--theme-surface);--ink:var(--theme-text);
    --muted:var(--theme-muted);--line:var(--theme-border);--deep:#d6e7ff;--blue:#94bbff;
    background:var(--theme-bg);color:var(--theme-text);
  }
  html[data-melapora-theme="dark"] body.mel-seo-page :is(.top,.tile,.faq details,.button:not(.primary)) {
    background:var(--theme-surface) !important;color:var(--theme-text) !important;
    border-color:var(--theme-border) !important;
  }
  html[data-melapora-theme="dark"] body.mel-seo-page :is(.topnav a,.brand,.tile h3,.faq summary) {
    color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] body.mel-seo-page :is(.tile p,.lead,.prose p,.footer,.crumbs,.crumbs a) {
    color:var(--theme-muted) !important;
  }
  html[data-melapora-theme="dark"] body.mel-seo-page .cta {background:#182f56;color:var(--theme-text);}
  html[data-melapora-theme="dark"] body.mel-seo-page .button.primary {background:#2d61ca;color:#fff;}
  .mel-feature-hub-link {margin:14px 0 0;font-size:14px;line-height:1.6;}
  .mel-feature-hub-link a {color:var(--theme-accent);font-weight:750;text-decoration:underline;text-underline-offset:3px;}
  @media(max-width:700px){#accountView > .wrap {width:calc(100% - 24px) !important;}}
}

/* Independent policy, legal, standalone pricing and test pages: common colors.
   This is screen-only so print/PDF styles stay intact. */
@media screen {
  html[data-melapora-theme] body.mel-static-page {
    background:var(--theme-bg) !important;
    color:var(--theme-text) !important;
  }
  html[data-melapora-theme="dark"] body.mel-static-page :is(
    main,article,section,.card,.panel,.wrap,.content,.container,.box
  ) {color:var(--theme-text);border-color:var(--theme-border);}
  html[data-melapora-theme="dark"] body.mel-static-page :is(
    .card,.panel,article,.box
  ) {background-color:var(--theme-surface) !important;color:var(--theme-text) !important;}
  html[data-melapora-theme="dark"] body.mel-static-page :is(
    input:not([type="checkbox"]),textarea,select
  ) {background:var(--theme-surface-2);color:var(--theme-text);border-color:var(--theme-border);}
}
