/* FAR-240 Theme Authority — must be the LAST stylesheet in Preview.
   High-contrast coherent Day/Night palettes; semantic green/red states preserved. */

html[data-theme="light"]{
  color-scheme:light;
  --bg:#f4efe5;
  --surface:#fffaf2;
  --panel:#ffffff;
  --panel-2:#f8f1e5;
  --panel-3:#eee4d3;
  --line:#d7c7aa;
  --text:#211d17;
  --muted:#655d52;
  --gold:#956919;
  --green:#177a58;
  --red:#b43e4b;
}
html[data-theme="dark"]{
  color-scheme:dark;
  --bg:#0f0d0a;
  --surface:#17140f;
  --panel:#1d1912;
  --panel-2:#242017;
  --panel-3:#2b251b;
  --line:#443a2c;
  --text:#f5f1e8;
  --muted:#b8afa2;
  --gold:#e0b65d;
  --green:#55d8aa;
  --red:#ff7b86;
}

/* ===== DAY ===== */
html[data-theme="light"],
html[data-theme="light"] body,
html[data-theme="light"] body.v7-ui,
html[data-theme="light"] #app,
html[data-theme="light"] #app.shell,
html[data-theme="light"] #app.app.marfa-converted,
html[data-theme="light"] .main,
html[data-theme="light"] main,
html[data-theme="light"] .view,
html[data-theme="light"] #dashboard{
  background:#f4efe5!important;
  color:#211d17!important;
}

html[data-theme="light"] body.v7-ui :is(
  .side,aside.side,
  article,.card,.panel,
  .dv2-sec,.dv2-card,.dv3-k,
  .sentiment-card,.analysis-hub-card,.connected-card,
  .bx-intel,.bx-priority,.bx-period,.bx-compare>div,
  .multi-card,.portfolio-risk-card,.lifecycle-ledger,
  .bb-card,.bb-col,.bb-score,.bb-verdict,.oi-card,.mi-card,
  .news-strip,.marfa-site-footer,
  .workspace-card,.ua-card,.mcc-card
){
  background:#fffaf2!important;
  color:#211d17!important;
  border-color:#d7c7aa!important;
  box-shadow:none!important;
}

html[data-theme="light"] body.v7-ui :is(
  .main>header.top,
  .main>.ticker,
  .market-clock,
  .demo
){
  background:#eee3d0!important;
  color:#2b2419!important;
  border-color:#cfb98d!important;
}

html[data-theme="light"] body.v7-ui :is(
  .market-choice,.market-profile,.market-user-clock,
  .theme-btn,.header-alert,.header-language,
  button:not(.up):not(.dn):not(.danger),
  input,select,textarea
){
  background:#fffdf8!important;
  color:#2a241c!important;
  border-color:#cdbb99!important;
}

html[data-theme="light"] body.v7-ui :is(
  h1,h2,h3,h4,h5,h6,
  .title,.dv2-hd,.dv2-ch,
  strong,b
){
  color:#211d17!important;
}

html[data-theme="light"] body.v7-ui :is(
  p,small,.muted,.sub,.desc,
  .dv2-mu,.dv3-k small,.dv3-k em,
  .dv3-mv li span,.dv3-ev small,.dv3-ac small,.dv3-lg small
){
  color:#655d52!important;
}

html[data-theme="light"] body.v7-ui :is(
  .market-choice.active,
  .header-language button.active,
  .dv2-seg button.on,
  .tabs button.active
){
  background:#ead8b8!important;
  color:#38280c!important;
  border-color:#ad7b24!important;
  font-weight:800!important;
}

html[data-theme="light"] #dashboard #dv3 .dv2-hero{
  background:linear-gradient(120deg,#fffdf8 0%,#f0e6d5 100%)!important;
  border-color:#d7c7aa!important;
  color:#211d17!important;
}
html[data-theme="light"] #dashboard #dv3 .dv2-hero h1{
  background:none!important;
  -webkit-background-clip:initial!important;
  background-clip:initial!important;
  color:#211d17!important;
}
html[data-theme="light"] #dashboard #dv3 .dv2-hnote{
  background:#f8f0e3!important;
  border-color:#d7c7aa!important;
  color:#574f45!important;
}
html[data-theme="light"] #dashboard .dv3-ctl input{
  background:#fff!important;
  color:#211d17!important;
  border-color:#cdbb99!important;
}
html[data-theme="light"] .ticker.live-ticker span,
html[data-theme="light"] .ticker.tick span{
  background:#fffaf2!important;
  color:#211d17!important;
  border-color:#d7c7aa!important;
}
html[data-theme="light"] .ticker .ticker-source{
  color:#744d0a!important;
  background:#f2e3c7!important;
}
html[data-theme="light"] .marfa-site-footer :is(a,button,h3,h4,b,strong){
  color:#30271c!important;
}

/* ===== NIGHT ===== */
html[data-theme="dark"],
html[data-theme="dark"] body,
html[data-theme="dark"] body.v7-ui,
html[data-theme="dark"] #app,
html[data-theme="dark"] #app.shell,
html[data-theme="dark"] #app.app.marfa-converted,
html[data-theme="dark"] .main,
html[data-theme="dark"] main,
html[data-theme="dark"] .view,
html[data-theme="dark"] #dashboard{
  background:#0f0d0a!important;
  color:#f5f1e8!important;
}

html[data-theme="dark"] body.v7-ui :is(
  .side,aside.side,
  article,.card,.panel,
  .dv2-sec,.dv2-card,.dv3-k,
  .sentiment-card,.analysis-hub-card,.connected-card,
  .bx-intel,.bx-priority,.bx-period,.bx-compare>div,
  .multi-card,.portfolio-risk-card,.lifecycle-ledger,
  .bb-card,.bb-col,.bb-score,.bb-verdict,.oi-card,.mi-card,
  .news-strip,.marfa-site-footer,
  .workspace-card,.ua-card,.mcc-card
){
  background:#1b1711!important;
  color:#f5f1e8!important;
  border-color:#443a2c!important;
}

html[data-theme="dark"] body.v7-ui :is(
  .main>header.top,
  .main>.ticker,
  .market-clock,
  .demo
){
  background:#17130e!important;
  color:#f5f1e8!important;
  border-color:#443821!important;
}

html[data-theme="dark"] body.v7-ui :is(
  .market-choice,.market-profile,.market-user-clock,
  .theme-btn,.header-alert,.header-language,
  button:not(.up):not(.dn):not(.danger),
  input,select,textarea
){
  background:#211c14!important;
  color:#f3eee4!important;
  border-color:#52452f!important;
}

html[data-theme="dark"] body.v7-ui :is(
  h1,h2,h3,h4,h5,h6,
  .title,.dv2-hd,.dv2-ch,
  strong,b
){
  color:#f5f1e8!important;
}
html[data-theme="dark"] body.v7-ui :is(
  p,small,.muted,.sub,.desc,
  .dv2-mu,.dv3-k small,.dv3-k em,
  .dv3-mv li span,.dv3-ev small,.dv3-ac small,.dv3-lg small
){
  color:#b8afa2!important;
}

html[data-theme="dark"] body.v7-ui :is(
  .market-choice.active,
  .header-language button.active,
  .dv2-seg button.on,
  .tabs button.active
){
  background:#3a2e1c!important;
  color:#f6d98b!important;
  border-color:#b88a38!important;
  font-weight:800!important;
}

html[data-theme="dark"] #dashboard #dv3 .dv2-hero{
  background:linear-gradient(120deg,#282217 0%,#17140f 100%)!important;
  border-color:#51432f!important;
  color:#f5f1e8!important;
}
html[data-theme="dark"] #dashboard #dv3 .dv2-hero h1{
  background:none!important;
  -webkit-background-clip:initial!important;
  background-clip:initial!important;
  color:#fffaf0!important;
}
html[data-theme="dark"] #dashboard #dv3 .dv2-hnote{
  background:#211b13!important;
  border-color:#4b3d29!important;
  color:#d4cbbd!important;
}
html[data-theme="dark"] #dashboard .dv3-ctl input{
  background:#18140f!important;
  color:#f5f1e8!important;
  border-color:#51432f!important;
}
html[data-theme="dark"] .ticker.live-ticker span,
html[data-theme="dark"] .ticker.tick span{
  background:#1b1711!important;
  color:#f5f1e8!important;
  border-color:#443a2c!important;
}
html[data-theme="dark"] .ticker .ticker-source{
  color:#f0cb76!important;
  background:#241d12!important;
}
html[data-theme="dark"] .marfa-site-footer :is(a,button,h3,h4,b,strong){
  color:#f0eadf!important;
}

/* Preserve semantic colors in both palettes. */
html[data-theme] body.v7-ui :is(.up,.green,.ok,.positive){color:var(--green)!important}
html[data-theme] body.v7-ui :is(.dn,.red,.bad,.negative){color:var(--red)!important}
html[data-theme] body.v7-ui .market-status-dot.is-open{background:#2fbf71!important}
html[data-theme] body.v7-ui .market-status-dot.is-closed{background:#e05252!important}

/* Links and focus remain visible instead of disappearing into beige/gold. */
html[data-theme="light"] body.v7-ui a{color:#72500f}
html[data-theme="dark"] body.v7-ui a{color:#edc66f}
html[data-theme] body.v7-ui :focus-visible{
  outline:2px solid #c99538!important;
  outline-offset:2px!important;
}

/* Avoid accidental low-opacity copy that becomes unreadable in either theme. */
html[data-theme] body.v7-ui :is(.view,.panel,.card,article) [style*="opacity:.5"],
html[data-theme] body.v7-ui :is(.view,.panel,.card,article) [style*="opacity: .5"]{
  opacity:.72!important;
}
