/* MADPILOT v3.29 — unified component template.
   Loaded LAST. Normalises switches, checkboxes, buttons, fields, chips and the
   card grids that overflowed (raids catalogue, inventory, settings mode cards).
   Everything uses the active theme tokens, so all 5 themes stay consistent. */

/* ------------------------------------------------------------------ 1. SWITCHES
   One look for every toggle in the panel: .switch, .task-toggle, .work-switch-track,
   .weapon-auto-switch, .equipment-master-switch. Track 46×26, knob 20. */
html[data-theme] body .switch{flex:0 0 46px!important;width:46px!important;min-width:46px!important;height:26px!important;vertical-align:middle;cursor:pointer}
html[data-theme] body .switch input{position:absolute!important;inset:0!important;width:100%!important;height:100%!important;margin:0!important;opacity:0!important;display:block!important;z-index:2;cursor:pointer;appearance:none!important;-webkit-appearance:none!important;background:none!important;border:0!important}
html[data-theme] body :is(.switch i,.task-toggle i,.weapon-auto-switch i,.equipment-master-switch i,.work-switch-track){position:relative!important;display:block!important;box-sizing:border-box!important;width:46px!important;min-width:46px!important;height:26px!important;flex:0 0 46px!important;margin:0!important;border-radius:999px!important;background:var(--t-field)!important;border:1px solid var(--t-border)!important;box-shadow:inset 0 2px 5px rgba(0,0,0,.45)!important;transition:background .2s,border-color .2s,box-shadow .2s!important;overflow:visible!important}
html[data-theme] body .switch i{position:absolute!important;inset:0!important}
/* knob */
html[data-theme] body .switch i:before,html[data-theme] body .weapon-auto-switch i:after,html[data-theme] body .equipment-master-switch i:after{content:""!important;position:absolute!important;top:3px!important;left:3px!important;right:auto!important;width:18px!important;height:18px!important;border-radius:50%!important;background:var(--tx-muted)!important;box-shadow:0 2px 5px rgba(0,0,0,.5)!important;transform:none!important;transition:transform .2s,background .2s!important;margin:0!important}
html[data-theme] body :is(.task-toggle i span,.work-switch-track i){position:absolute!important;top:3px!important;left:3px!important;width:18px!important;height:18px!important;border-radius:50%!important;background:var(--tx-muted)!important;box-shadow:0 2px 5px rgba(0,0,0,.5)!important;transition:transform .2s,background .2s,left .2s!important;margin:0!important}
html[data-theme] body .switch i:after,html[data-theme] body .weapon-auto-switch i:before,html[data-theme] body .equipment-master-switch i:before{content:none!important;display:none!important}
/* on */
html[data-theme] body :is(.switch input:checked+i,.task-toggle input:checked+i,.weapon-auto-switch input:checked+i,.equipment-master-switch input:checked+i,.work-block-switch input:checked+.work-switch-track){background:linear-gradient(90deg,var(--t-accent-2),var(--t-accent))!important;border-color:var(--t-accent)!important;box-shadow:inset 0 1px 3px rgba(0,0,0,.3),0 0 12px var(--t-glow)!important}
html[data-theme] body .switch input:checked+i:before,html[data-theme] body .weapon-auto-switch input:checked+i:after,html[data-theme] body .equipment-master-switch input:checked+i:after{transform:translateX(20px)!important;left:3px!important;background:#fff!important}
html[data-theme] body :is(.task-toggle input:checked+i span,.work-block-switch input:checked+.work-switch-track i){left:23px!important;background:#fff!important}
html[data-theme] body .switch input:focus-visible+i{outline:2px solid var(--t-accent);outline-offset:2px}

/* rows that contain a switch: text left, switch right, never overlapping */
html[data-theme] body .switchrow{display:flex!important;align-items:center!important;justify-content:space-between!important;gap:14px!important;min-width:0}
html[data-theme] body .switchrow>:first-child{min-width:0;flex:1 1 auto}
html[data-theme] body .switchrow b{color:var(--tx-title)!important}
html[data-theme] body .switchrow small{color:var(--tx-muted)!important}

/* ------------------------------------------------------------------ 2. CHECKBOX / RADIO */
html[data-theme] body input[type=checkbox]:not(.switch input):not(.task-toggle input):not(.weapon-auto-switch input):not(.work-block-switch input):not(.equipment-master-switch input):not(.equipment-currency-card input),
html[data-theme] body input[type=radio]{appearance:none!important;-webkit-appearance:none!important;flex:0 0 20px;width:20px!important;height:20px!important;min-width:20px;margin:0;border-radius:6px!important;border:1px solid var(--t-border)!important;background:var(--t-field) center/14px no-repeat!important;box-shadow:inset 0 1px 3px rgba(0,0,0,.4)!important;cursor:pointer;vertical-align:middle;transition:background-color .15s,border-color .15s,box-shadow .15s}
html[data-theme] body input[type=radio]{border-radius:50%!important}
html[data-theme] body input[type=checkbox]:not(.switch input):not(.task-toggle input):not(.weapon-auto-switch input):not(.work-block-switch input):not(.equipment-master-switch input):not(.equipment-currency-card input):checked{background-color:var(--t-accent)!important;border-color:var(--t-accent)!important;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")!important;box-shadow:0 0 10px var(--t-glow)!important}
html[data-theme] body input[type=radio]:checked{background-color:var(--t-field)!important;border-color:var(--t-accent)!important;box-shadow:inset 0 0 0 5px var(--t-accent)!important}
html[data-theme] body .stat-pick,html[data-theme] body .stat-pick-compact{background:var(--t-field)!important;border:1px solid var(--t-border-soft)!important;border-radius:10px!important}

/* ------------------------------------------------------------------ 3. BUTTONS */
html[data-theme] body .btn.light,html[data-theme] body .btn.secondary,html[data-theme] body button.light{background:var(--t-field)!important;border:1px solid var(--t-border)!important;color:var(--tx-title)!important;box-shadow:none!important;text-shadow:none!important}
html[data-theme] body .btn.light:hover{border-color:var(--t-accent)!important;box-shadow:0 0 12px var(--t-glow)!important}
html[data-theme] body .btn{white-space:nowrap;max-width:100%;overflow:hidden;text-overflow:ellipsis}
html[data-theme] body .mode-control-state{background:var(--t-field)!important;border:1px solid var(--t-border)!important;color:var(--tx-body)!important;box-shadow:none!important}
html[data-theme] body .mode-control.is-on .mode-control-state{background:linear-gradient(180deg,var(--t-accent),var(--t-accent-2))!important;border-color:var(--t-accent)!important;color:#fff!important}
/* settings "Current boss" mode cards: same compact tile as on the home page */
html[data-theme] body .settings-v201 .mode-control,html[data-theme] body .settings-section .mode-control{display:grid!important;grid-template-columns:44px minmax(0,1fr) auto!important;align-items:center!important;gap:10px!important;min-height:64px!important;height:auto!important;padding:10px 12px!important;background:var(--t-card-soft)!important;border:1px solid var(--t-border-soft)!important}
html[data-theme] body .settings-section .mode-control.is-on{border-color:var(--t-accent)!important;box-shadow:0 0 0 1px var(--t-glow),0 0 16px var(--t-glow)!important}
html[data-theme] body .settings-section .mode-control-copy b{font-size:13px!important;line-height:1.2!important;white-space:normal!important}
html[data-theme] body .settings-section .mode-control-copy small{font-size:10px!important;line-height:1.3!important}
html[data-theme] body .settings-section .mode-control-icon{width:44px!important;height:44px!important}

/* ------------------------------------------------------------------ 4. FIELDS */
html[data-theme] body main :is(input[type=number],input[type=text],input[type=search],select,textarea){box-sizing:border-box;max-width:100%;min-width:0;border-radius:11px}
html[data-theme] body main :is(input[type=number],input[type=text],input[type=search],select){min-height:38px}

/* ------------------------------------------------------------------ 5. LEGACY TEXT (brown / dark red) */
html[data-theme] body :is(.combat-rule b,.combat-rule>div>b,.combat-items-settings hr+b,.combat-items-settings>b,.stat-upgrade-foot b){color:var(--tx-title)!important}
html[data-theme] body :is(.combat-rule small,.combat-items-settings small,.stat-upgrade-foot,.stat-upgrade-foot span,.stat-upgrade-foot small){color:var(--tx-muted)!important}
html[data-theme] body .stat-upgrade-foot b{color:var(--t-accent)!important}
html[data-theme] body .combat-items-settings hr{border:0;border-top:1px solid var(--t-border-soft);margin:14px 0}

/* ------------------------------------------------------------------ 6. RAIDS — boss catalogue tiles (button used to cover the name) */
html[data-theme] body .raid-catalog-grid{display:grid!important;grid-template-columns:repeat(auto-fill,minmax(230px,1fr))!important;gap:10px!important}
html[data-theme] body .raid-boss-tile{display:grid!important;grid-template-columns:58px minmax(0,1fr)!important;grid-template-rows:auto auto!important;gap:8px 12px!important;align-items:center!important;min-width:0!important;height:auto!important;min-height:0!important;padding:12px!important;border-radius:16px!important;background:var(--t-card-soft)!important;border:1px solid var(--t-border-soft)!important;overflow:hidden}
html[data-theme] body .raid-boss-tile:hover{border-color:var(--t-border)!important}
html[data-theme] body .raid-boss-art{position:relative;grid-column:1;grid-row:1;width:58px!important;height:58px!important;border-radius:14px!important;overflow:hidden;border:1px solid var(--t-border-soft)}
html[data-theme] body .raid-boss-art img{width:100%!important;height:100%!important;object-fit:cover}
html[data-theme] body .raid-boss-art span{position:absolute;left:0;right:0;bottom:0;padding:2px 0!important;font-size:8px!important;line-height:1.2;text-align:center;background:rgba(0,0,0,.65)!important;color:var(--tx-title)!important;letter-spacing:.06em}
html[data-theme] body .raid-boss-copy{grid-column:2;grid-row:1;display:grid!important;gap:2px!important;min-width:0!important}
html[data-theme] body .raid-boss-copy small{font-size:10px!important;line-height:1.3!important;color:var(--tx-muted)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
html[data-theme] body .raid-boss-copy h4{margin:0!important;font-size:14px!important;line-height:1.25!important;color:var(--tx-title)!important;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:normal;word-break:normal}
html[data-theme] body .raid-boss-tile>.btn,html[data-theme] body .raid-boss-tile>button{grid-column:1/-1!important;grid-row:2!important;width:100%!important;min-height:36px!important;height:auto!important;margin:0!important;padding:7px 10px!important;font-size:12px!important;justify-content:center;position:static!important}

/* ------------------------------------------------------------------ 7. INVENTORY — compact tiles */
html[data-theme] body #bagGrid,html[data-theme] body #stashGrid{display:grid!important;grid-template-columns:repeat(auto-fill,minmax(210px,1fr))!important;grid-auto-rows:auto!important;gap:8px!important;min-width:0}
html[data-theme] body :is(#bagGrid,#stashGrid) :is(.item-card,.set-card){display:grid!important;grid-template-columns:52px minmax(0,1fr)!important;align-items:center!important;gap:10px!important;width:100%!important;height:auto!important;min-height:76px!important;max-height:none!important;padding:10px 12px!important;margin:0!important;border-radius:14px!important;background:var(--t-card-soft)!important;border:1px solid var(--t-border-soft)!important;box-sizing:border-box;overflow:hidden}
html[data-theme] body :is(#bagGrid,#stashGrid) :is(.item-card,.set-card):hover{border-color:var(--t-border)!important}
html[data-theme] body :is(#bagGrid,#stashGrid) .item-image,html[data-theme] body #stashGrid .set-card>img{width:52px!important;height:52px!important;min-width:52px;border-radius:12px!important;overflow:hidden;background:var(--t-field)!important;border:1px solid var(--t-border-soft);display:grid;place-items:center;margin:0!important}
html[data-theme] body :is(#bagGrid,#stashGrid) .item-image img{width:100%!important;height:100%!important;object-fit:contain!important}
html[data-theme] body #stashGrid .set-card>img{object-fit:contain!important;padding:4px;box-sizing:border-box}
html[data-theme] body :is(#bagGrid,#stashGrid) :is(.item-card,.set-card)>div{display:grid!important;grid-template-columns:minmax(0,1fr) auto!important;gap:2px 8px!important;align-items:center;min-width:0!important}
html[data-theme] body :is(#bagGrid,#stashGrid) :is(.item-card,.set-card) h4{grid-column:1/-1!important;margin:0!important;font-size:13px!important;line-height:1.25!important;color:var(--tx-title)!important;overflow-wrap:normal!important;word-break:normal!important;hyphens:none;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
html[data-theme] body :is(#bagGrid,#stashGrid) :is(.item-card,.set-card) p{grid-column:1!important;grid-row:auto!important;margin:0!important;font-size:10px!important;line-height:1.3!important;color:var(--tx-muted)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
html[data-theme] body #bagGrid .item-card .qty{grid-column:2!important;grid-row:2!important;margin:0!important;font-size:15px!important;line-height:1!important;color:var(--tx-number)!important;white-space:nowrap;padding:4px 8px;border-radius:99px;background:var(--t-field);border:1px solid var(--t-border-soft)}
html[data-theme] body #bagGrid .item-card .item-effect{grid-column:1/-1!important;font-size:9.5px!important;line-height:1.3!important;color:var(--tx-dim)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
html[data-theme] body #stashGrid .set-card .set-progress{grid-column:1/-1;height:5px!important;margin:4px 0 2px!important;border-radius:99px;background:var(--t-field)!important;overflow:hidden}
html[data-theme] body #stashGrid .set-card .set-progress i{background:linear-gradient(90deg,var(--t-accent-2),var(--t-accent))!important}
html[data-theme] body #stashGrid .set-card .set-meta{grid-column:1/-1;display:flex!important;justify-content:space-between;gap:6px;font-size:9.5px!important;color:var(--tx-muted)!important}
html[data-theme] body #stashGrid .set-card .set-meta b{color:var(--tx-number)!important}
html[data-theme] body .inventory-scroll,html[data-theme] body .inventory-scroll-tabbed{max-height:min(66vh,640px)!important;height:auto!important;overflow:auto!important;padding-right:4px!important;mask-image:none!important;-webkit-mask-image:none!important}
html[data-theme] body .inventory-scroll:after{display:none!important}
html[data-theme] body .inventory-tabs{display:flex!important;flex-wrap:wrap!important;gap:6px!important;margin-bottom:10px!important}
html[data-theme] body .inventory-tabs button{min-height:34px!important;padding:6px 10px!important;font-size:11px!important;border-radius:10px!important}

/* ------------------------------------------------------------------ 8. GENERIC CARD TEXT SAFETY */
html[data-theme] body main :is(.boss-card h4,.raid-boss-tile h4,.biz-card h4,.work-task h4,.set-card h4,.item-card h4){overflow-wrap:normal;word-break:normal}

/* ------------------------------------------------------------------ 9. RESPONSIVE */
@media (max-width:900px){
  html[data-theme] body .raid-catalog-grid{grid-template-columns:repeat(auto-fill,minmax(160px,1fr))!important}
  html[data-theme] body :is(#bagGrid,#stashGrid){grid-template-columns:repeat(auto-fill,minmax(170px,1fr))!important}
  html[data-theme] body .settings-section .mode-control{grid-template-columns:40px minmax(0,1fr) auto!important}
}
@media (max-width:560px){
  html[data-theme] body .raid-catalog-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important}
  html[data-theme] body .raid-boss-tile{grid-template-columns:44px minmax(0,1fr)!important;padding:10px!important}
  html[data-theme] body .raid-boss-art{width:44px!important;height:44px!important}
  html[data-theme] body .raid-boss-copy h4{font-size:12px!important}
  html[data-theme] body :is(#bagGrid,#stashGrid){grid-template-columns:minmax(0,1fr)!important}
  html[data-theme] body .inventory-scroll,html[data-theme] body .inventory-scroll-tabbed{max-height:none!important;overflow:visible!important}
  html[data-theme] body main :is(input[type=number],input[type=text],input[type=search],select){font-size:16px}/* no iOS zoom */
}

/* ------------------------------------------------------------------ 10. FRIENDS — stat icons from auto-upgrade */
.mp-stat-ico{width:24px;height:24px;object-fit:contain;flex:0 0 24px;border-radius:7px;background:var(--t-field);border:1px solid var(--t-border-soft);padding:2px;box-sizing:border-box;vertical-align:middle}
.mp-stat-ico.sm{width:20px;height:20px;flex-basis:20px;border-radius:6px;padding:1px}
.mp-fr-grid label>span{gap:8px!important;font-size:11px!important}
.mp-fr-th button{display:inline-flex;align-items:center;gap:6px}
.mp-fr-th .mp-stat-ico{width:20px;height:20px;flex-basis:20px}
.mp-fr-stat-cell{display:inline-flex;align-items:center;gap:6px}
.mp-fr-row>[data-k]:before{content:none!important}

/* inventory extras */
html[data-theme] body #stashGrid .set-card .stash-hint{grid-column:1/-1;font-size:9.5px!important;line-height:1.3!important;color:var(--tx-dim)!important;margin:2px 0 0!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
html[data-theme] body #stashGrid .set-card.craftable{border-color:var(--t-accent)!important;box-shadow:inset 0 0 0 1px var(--t-glow)!important}
html[data-theme] body .inventory-tabs .inventory-tab{display:inline-flex!important;align-items:center!important;gap:8px!important;width:auto!important;flex:0 0 auto!important;min-width:0!important}
html[data-theme] body .inventory-tabs .inventory-tab b{min-width:22px;padding:2px 7px;border-radius:99px;background:var(--t-field);font-size:10px!important;text-align:center}
html[data-theme] body :is(.combat-item-setting,.autobuy-card)>div>b,html[data-theme] body :is(.combat-item-setting,.autobuy-card) .autobuy-copy>b{padding-right:58px;display:block}
.mp-fr-grid label>span img.mp-stat-ico{width:24px!important;height:24px!important}
@media (max-width:640px){
  html[data-theme] body .mh-theme-settings .panel-body{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important}
  html[data-theme] body .mh-theme-card{min-height:84px!important;height:auto!important;padding:10px!important}
  html[data-theme] body .mh-theme-card b{font-size:12px!important}
  html[data-theme] body .mh-theme-card small{font-size:9px!important;line-height:1.3!important}
  html[data-theme] body .mp-fr-listacts{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px!important;width:100%}
  html[data-theme] body .mp-fr-listacts .btn{min-height:40px!important;padding:6px 4px!important;font-size:10px!important;white-space:normal!important;line-height:1.2;text-align:center;justify-content:center}
  html[data-theme] body .mp-fr-row>.mp-fr-lvl,html[data-theme] body .mp-fr-row>[data-k],html[data-theme] body .mp-fr-row>.mp-fr-seen{padding:2px 7px!important;font-size:10.5px!important;gap:4px!important}
  html[data-theme] body .mp-fr-row .mp-stat-ico.sm{width:16px!important;height:16px!important;flex-basis:16px!important;padding:0!important;border:0!important}
  html[data-theme] body .mp-fr-row>.mp-fr-lvl{margin-left:32px}
}

/* ------------------------------------------------------------------ 11. AUTO STAT UPGRADE cards (profile + settings) */
html[data-theme] body .stat-upgrade-grid{display:grid!important;grid-template-columns:repeat(auto-fit,minmax(230px,1fr))!important;gap:10px!important}
html[data-theme] body .stat-upgrade-card{min-width:0!important;padding:12px!important;box-sizing:border-box}
html[data-theme] body .stat-v127-top{display:grid!important;grid-template-columns:40px minmax(0,1fr) auto auto!important;align-items:center!important;gap:8px!important;min-width:0}
html[data-theme] body .stat-v127-top .stat-upgrade-icon{width:40px!important;height:40px!important;border-radius:11px!important;overflow:hidden}
html[data-theme] body .stat-v127-top .stat-upgrade-icon img{width:100%!important;height:100%!important;object-fit:cover}
html[data-theme] body .stat-v127-title{min-width:0!important;display:grid!important;gap:2px}
html[data-theme] body .stat-v127-title small{font-size:9px!important;letter-spacing:.1em;color:var(--tx-label)!important}
html[data-theme] body .stat-v127-title b{font-size:clamp(16px,1.5vw,22px)!important;line-height:1.1!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--tx-number)!important}
html[data-theme] body .stat-fixed-target{display:grid!important;justify-items:center;gap:1px;min-width:46px;padding:4px 6px!important;border-radius:10px!important;background:var(--t-field)!important;border:1px solid var(--t-border-soft)!important}
html[data-theme] body .stat-fixed-target small{font-size:8px!important;color:var(--tx-muted)!important;white-space:nowrap}
html[data-theme] body .stat-fixed-target b{font-size:15px!important;color:var(--tx-title)!important}
html[data-theme] body .stat-pick-compact{display:grid!important;place-items:center;width:32px;height:32px;padding:0!important}
html[data-theme] body .stat-pick-compact span{display:none!important}
html[data-theme] body .stat-upgrade-card :is(.stat-v127-stats,.stat-v127-metrics)>*{min-width:0}
html[data-theme] body .stat-v127-top{grid-template-columns:40px minmax(0,1fr) auto!important;grid-template-rows:auto auto!important;row-gap:6px!important}
html[data-theme] body .stat-v127-top .stat-upgrade-icon{grid-column:1;grid-row:1/3}
html[data-theme] body .stat-v127-title{grid-column:2;grid-row:1/3}
html[data-theme] body .stat-v127-top .stat-fixed-target{grid-column:3;grid-row:1;flex-direction:row;display:flex!important;align-items:baseline;gap:5px!important;padding:3px 8px!important}
html[data-theme] body .stat-v127-top .stat-pick-compact{grid-column:3;grid-row:2;justify-self:end;width:28px;height:28px}
html[data-theme] body .stat-v127-title b{font-size:clamp(17px,1.4vw,21px)!important;text-overflow:clip}
html[data-theme] body .stat-v127-top{grid-template-columns:40px minmax(0,1fr) auto auto!important;grid-template-rows:auto auto!important;column-gap:8px!important;row-gap:2px!important}
html[data-theme] body .stat-v127-title{display:contents!important}
html[data-theme] body .stat-v127-title small{grid-column:2;grid-row:1;align-self:center}
html[data-theme] body .stat-v127-title b{grid-column:2/5;grid-row:2;font-size:22px!important}
html[data-theme] body .stat-v127-top .stat-fixed-target{grid-column:3;grid-row:1;flex-direction:column;display:grid!important;padding:2px 7px!important;gap:0!important}
html[data-theme] body .stat-v127-top .stat-fixed-target b{font-size:13px!important}
html[data-theme] body .stat-v127-top .stat-pick-compact{grid-column:4;grid-row:1;width:28px;height:28px}
html[data-theme] body .stat-v127-top .stat-upgrade-icon{grid-column:1;grid-row:1/3;align-self:center}
