:root{
      --navy:#0d243f;
      --navy2:#102b4c;
      --gold:#d4a017;
      --cream:#f8f6ef;
      --card:#ffffff;
      --text:#0d243f;
      --muted:#667085;
      --line:#d9d6cc;
      --input:#ffffff;
      --soft:#f3f0e8;
      --green:#15803d;
      --red:#b42318;
    }

    body.dark{
      --cream:#071423;
      --card:#0f2136;
      --text:#f8fafc;
      --muted:#cbd5e1;
      --line:#2f4158;
      --input:#10243b;
      --soft:#122b46;
    }
    body.dark header{
      background:#06111f;
      color:#fff;
    }
    body.dark h2,
    body.dark label{
      color:#f8fafc;
    }
    body.dark input,
    body.dark select,
    body.dark textarea,
    body.dark .calc-display{
      background:#10243b;
      color:#f8fafc;
      border-color:#3d526c;
    }
    body.dark .result,
    body.dark .history-item{
      background:#0b1a2c;
      color:#f8fafc;
      border-color:#33465f;
    }
    body.dark button.secondary,
    body.dark .preset,
    body.dark .calc-key,
    body.dark .calc-key.clear,
    body.dark .calc-key.op{
      background:#1b3656;
      color:#f8fafc;
      border-color:#38506b;
    }
    body.dark .small,
    body.dark .calc-expression{
      color:#cbd5e1;
    }
    .header-actions{
      display:flex;
      justify-content:flex-end;
      margin-top:18px;
    }

    .theme-switch{
      display:flex;
      align-items:center;
      gap:10px;
      user-select:none;
      font-weight:700;
      color:#fff;
    }
    .theme-switch input{
      display:none;
    }
    .theme-slider{
      position:relative;
      width:52px;
      height:30px;
      border-radius:999px;
      background:rgba(255,255,255,.22);
      border:1px solid rgba(255,255,255,.18);
      transition:.25s ease;
      cursor:pointer;
      flex:0 0 52px;
    }
    .theme-slider::before{
      content:'';
      position:absolute;
      top:3px;
      left:3px;
      width:22px;
      height:22px;
      border-radius:50%;
      background:#fff;
      transition:.25s ease;
      box-shadow:0 2px 6px rgba(0,0,0,.25);
    }
    .theme-switch input:checked + .theme-slider{
      background:var(--gold);
    }
    .theme-switch input:checked + .theme-slider::before{
      transform:translateX(22px);
      background:#fff;
    }
    .theme-label{
      font-size:.95rem;
      color:#f3f4f6;
    }


    .calc-title{
      display:flex;
      align-items:center;
      gap:10px;
    }
    .calc-icon{
      width:38px;
      height:38px;
      border-radius:14px;
      background:#f8f6ef;
      color:var(--navy);
      display:inline-flex;
      align-items:center;
      justify-content:center;
      flex:0 0 38px;
      border:1.5px solid #d8d2c5;
      box-shadow:0 2px 8px rgba(13,36,63,.06);
    }
    .calc-icon svg{
      width:21px;
      height:21px;
      stroke:currentColor;
      stroke-width:2;
      fill:none;
      stroke-linecap:round;
      stroke-linejoin:round;
    }
    body.dark .calc-icon{
      background:#10243b;
      border-color:#38506b;
      color:#f8fafc;
    }


    *{box-sizing:border-box}
    body{
      margin:0;
      font-family:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
      background:var(--cream);
      color:var(--text);
    }
    header{
      padding:26px 28px 28px;
      background:var(--navy);
      color:#fff;
      border-bottom:7px solid var(--gold);
    }
    .brand-lockup{
      display:flex;
      align-items:center;
      gap:10px;
      max-width:900px;
    }
    .header-logo{
      width:60px;
      height:60px;
      flex:0 0 60px;
      display:block;
      object-fit:contain;
      filter:drop-shadow(0 12px 22px rgba(0,0,0,.28));
    }
    h1{
      margin:0;
      font-size:clamp(2rem,4vw,3rem);
      line-height:1.05;
      font-weight:800;
      letter-spacing:-.03em;
    }
    .sub{
      color:#f2efe7;
      margin-top:8px;
      font-size:clamp(.98rem,2.1vw,1.18rem);
      line-height:1.28;
      max-width:900px;
    }
    main{max-width:1180px;margin:0 auto;padding:28px 18px}
    .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(330px,1fr));gap:18px}
    .card{
      background:var(--card);
      border:2px solid var(--line);
      border-radius:22px;
      padding:22px;
      box-shadow:0 10px 28px rgba(13,36,63,.08);
    }
    h2{
      font-size:1.35rem;
      margin:0 0 16px;
      padding-bottom:10px;
      border-bottom:4px solid var(--gold);
      color:var(--navy);
      font-weight:850;
      letter-spacing:-.02em;
    }
    label{
      display:block;
      font-size:.95rem;
      color:var(--navy);
      font-weight:750;
      margin-top:13px;
    }
    input,select,textarea{
      width:100%;
      margin-top:7px;
      padding:13px 14px;
      border-radius:14px;
      border:2px solid #c9c9c9;
      background:var(--input);
      color:#111827;
      font-size:1.03rem;
      outline:none;
    }
    input:focus,select:focus,textarea:focus{
      border-color:var(--gold);
      box-shadow:0 0 0 3px rgba(212,160,23,.18);
    }
    input::placeholder,textarea::placeholder{color:#a3a3a3}
    textarea{min-height:96px;resize:vertical}
    .row{display:grid;grid-template-columns:1fr 1fr;gap:12px}
    .btns{display:flex;gap:10px;flex-wrap:wrap;margin-top:16px}
    button{
      border:0;
      border-radius:14px;
      padding:12px 16px;
      background:var(--navy);
      color:#fff;
      font-weight:850;
      cursor:pointer;
      box-shadow:0 4px 0 rgba(13,36,63,.18);
    }
    button:hover{filter:brightness(1.05)}
    button.secondary{
      background:#e9e5da;
      color:var(--navy);
      border:1px solid #d1cabc;
      box-shadow:none;
    }
    button.good{background:var(--green);color:#fff}
    button.warn{background:var(--gold);color:#1f1300}

    button.reset-btn{
      background:#7c2d12;
      color:#fff;
    }

    .result{
      margin-top:14px;
      padding:14px;
      border:2px solid #d8d2c5;
      border-radius:16px;
      background:#fbfaf7;
      white-space:pre-wrap;
      line-height:1.38;
      color:#111827;
      min-height:56px;
    }
    .small{font-size:.86rem;color:var(--muted);margin-top:10px;line-height:1.35}

    .result.result-smart{
      white-space:normal;
    }
    .result-primary{
      display:flex;
      flex-direction:column;
      gap:4px;
      padding-bottom:10px;
      margin-bottom:10px;
      border-bottom:1px solid #e4dfd2;
    }
    .result-label{
      font-size:.78rem;
      font-weight:850;
      text-transform:uppercase;
      letter-spacing:.06em;
      color:var(--muted);
    }
    .result-value{
      font-size:1.35rem;
      font-weight:900;
      color:var(--navy);
      line-height:1.15;
    }
    .result-details{
      white-space:pre-wrap;
      font-size:.94rem;
      line-height:1.42;
      color:#111827;
    }
    .result-status-good .result-value{color:var(--green);}
    .result-status-warn .result-value{color:#92400e;}
    .result-status-danger .result-value{color:var(--red);}
    body.dark .result-value{color:#f8fafc;}
    body.dark .result-details{color:#f8fafc;}
    body.dark .result-primary{border-bottom-color:#33465f;}
    body.dark .result-status-good .result-value{color:#86efac;}
    body.dark .result-status-warn .result-value{color:#facc15;}
    body.dark .result-status-danger .result-value{color:#fca5a5;}

    .pill{display:inline-block;padding:4px 9px;border-radius:999px;background:#f8f6ef;border:1px solid #d8d2c5;color:var(--navy);font-size:.8rem;margin:2px}
    .danger{color:var(--red)}.ok{color:var(--green)}.yellow{color:#92400e}
    footer{
      padding:24px 8px 10px;
      text-align:center;
      color:var(--muted);
      font-size:.86rem;
      line-height:1.35;
    }

    .history{
      margin-top:14px;
      padding-top:12px;
      border-top:1px dashed #d8d2c5;
    }
    .history h3{
      margin:0 0 8px;
      font-size:.9rem;
      color:var(--muted);
      text-transform:uppercase;
      letter-spacing:.04em;
    }
    .history-item{
      background:#fbfaf7;
      border:1px solid #e4dfd2;
      border-radius:12px;
      padding:8px 10px;
      margin-bottom:8px;
      font-size:.88rem;
      line-height:1.3;
    }
    .preset-row{
      display:flex;
      flex-wrap:wrap;
      gap:8px;
      margin-top:12px;
    }
    .preset{
      background:#f3f0e8;
      color:var(--navy);
      border:1px solid #d8d2c5;
      box-shadow:none;
      padding:8px 10px;
      font-size:.85rem;
    }



    .calc-display{
      width:100%;
      min-height:74px;
      padding:14px 18px;
      border:2px solid #cfd3dc;
      border-radius:18px;
      background:#fff;
      color:#111827;
      font-size:2rem;
      font-weight:750;
      text-align:right;
      display:flex;
      align-items:center;
      justify-content:flex-end;
      overflow:hidden;
      white-space:nowrap;
    }
    .calc-expression{
      margin-top:8px;
      min-height:20px;
      color:var(--muted);
      font-size:.86rem;
      text-align:right;
      overflow:hidden;
      white-space:nowrap;
    }
    .calc-keypad{
      display:grid;
      grid-template-columns:repeat(4,1fr);
      gap:8px;
      margin-top:12px;
    }
    .calc-key{
      min-height:44px;
      border-radius:999px;
      background:#f1f1f1;
      color:#1f2937;
      box-shadow:none;
      font-size:1rem;
      font-weight:750;
      padding:10px 0;
    }
    .calc-key.op{
      background:#e9eefc;
      color:var(--navy);
    }
    .calc-key.equals{
      background:#1f5bd8;
      color:#fff;
    }
    .calc-key.clear{
      background:#e9eefc;
      color:var(--navy);
    }
    .calc-hidden-input{
      position:absolute;
      opacity:0;
      height:1px;
      width:1px;
      left:-9999px;
    }
    .calc-card{
      cursor:text;
    }

    .scientific-key{
      display:none;
    }


    .enzyme-card .row > div{
      display:flex;
      flex-direction:column;
    }
    .enzyme-card .row > div label{
      min-height:42px;
      display:flex;
      align-items:flex-end;
    }
    .enzyme-card input,
    .enzyme-card select{
      height:50px;
    }
    .aligned-card .row > div{
      display:flex;
      flex-direction:column;
    }
    .aligned-card .row > div label{
      min-height:42px;
      display:flex;
      align-items:flex-end;
    }
    .aligned-card input,
    .aligned-card select{
      height:50px;
    }

    #gen_titration_mode .row,
    #gen_multi_mode .row{
      align-items:start;
    }
    #gen_titration_mode .row > div,
    #gen_multi_mode .row > div{
      min-width:0;
    }


    /* Day Supply spacing/alignment: tighten simple modes without collapsing fields */
    #gen_units_mode .row > div,
    #gen_liquid_mode .row > div,
    #gen_quantity_mode .row > div,
    #gen_titration_mode .row > div,
    #gen_multi_mode .row > div,
    #gen_pattern_mode .row > div{
      display:flex;
      flex-direction:column;
      justify-content:flex-start;
    }

    #gen_units_mode .row > div label,
    #gen_liquid_mode .row > div label,
    #gen_quantity_mode .row > div label,
    #gen_pattern_mode .row > div label{
      min-height:0;
      display:block;
      margin-top:12px;
    }

    #gen_titration_mode .row > div label,
    #gen_multi_mode .row > div label{
      min-height:42px;
      display:flex;
      align-items:flex-end;
    }

    #gen_units_mode input,
    #gen_liquid_mode input,
    #gen_quantity_mode input,
    #gen_titration_mode input,
    #gen_titration_mode select,
    #gen_multi_mode input,
    #gen_multi_mode select,
    #gen_pattern_mode input,
    #gen_pattern_mode select{
      height:50px;
    }

    .help-link{
      display:inline-flex;
      align-items:center;
      gap:8px;
      margin-top:16px;
      padding:10px 14px;
      border-radius:14px;
      background:rgba(255,255,255,.12);
      color:#fff;
      text-decoration:none;
      font-weight:800;
      border:1px solid rgba(255,255,255,.18);
      transition:.2s ease;
    }
    .help-link:hover{
      background:rgba(255,255,255,.2);
    }


/* Keep form controls inside cards on iPhone/Safari */
html,
body{
  max-width:100%;
  overflow-x:hidden;
}

.card,
.row,
.row > div{
  min-width:0;
}

input,
select,
textarea,
.calc-display,
.result{
  display:block;
  max-width:100%;
  min-width:0;
}

input[type="date"]{
  -webkit-appearance:none;
  appearance:none;
  min-width:0;
}

.checkbox-row{
  display:flex;
  align-items:flex-start;
  gap:12px;
  margin-top:14px;
}

.checkbox-row input[type="checkbox"]{
  width:22px;
  height:22px;
  margin-top:2px;
  flex:0 0 22px;
  accent-color:var(--navy);
}

.checkbox-row span{
  display:block;
  line-height:1.35;
  padding-top:1px;
}



/* Stronger dark-mode action buttons */
body.dark button:not(.secondary):not(.reset-btn):not(.calc-key):not(.quick-tool-btn):not(.tool-list-item):not(.tool-search-fav-btn):not(.favorite-layout-name):not(.favorite-layout-remove){
  background:#2563eb;
  color:#ffffff;
  border:1px solid #60a5fa;
  box-shadow:0 4px 0 rgba(0,0,0,.35), 0 0 0 1px rgba(96,165,250,.18);
}

body.dark button:not(.secondary):not(.reset-btn):not(.calc-key):not(.quick-tool-btn):not(.tool-list-item):not(.tool-search-fav-btn):not(.favorite-layout-name):not(.favorite-layout-remove):hover{
  background:#3b82f6;
  filter:none;
}

body.dark button.secondary{
  background:#1e3a5f;
  color:#ffffff;
  border:1px solid #5b789f;
  box-shadow:0 4px 0 rgba(0,0,0,.25);
}

body.dark button.secondary:hover{
  background:#284b78;
  filter:none;
}

body.dark button.reset-btn{
  background:#b43a1d;
  color:#ffffff;
  border:1px solid #f9735b;
  box-shadow:0 4px 0 rgba(0,0,0,.35);
}

body.dark button.reset-btn:hover{
  background:#c2410c;
  filter:none;
}

body.dark button.good{
  background:#15803d;
  border:1px solid #4ade80;
}

body.dark .checkbox-row input[type="checkbox"]{
  accent-color:#2563eb;
}



/* Branded app polish */
.app-splash{
  position:fixed;
  inset:0;
  z-index:9999;
  display:flex;
  align-items:center;
  justify-content:center;
  background:linear-gradient(145deg,#06111f,#0d243f);
  color:#fff;
  transition:opacity .18s ease, visibility .18s ease;
}
.app-splash.is-hidden{
  opacity:0;
  visibility:hidden;
  pointer-events:none;
}
.splash-card{
  width:min(86vw,360px);
  padding:30px 24px;
  border-radius:28px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.08);
  box-shadow:0 24px 70px rgba(0,0,0,.32);
  text-align:center;
  backdrop-filter:blur(12px);
}
.splash-icon{
  width:104px;
  height:104px;
  border-radius:26px;
  margin:0 auto 18px;
  display:block;
  box-shadow:0 12px 30px rgba(0,0,0,.28);
}
.splash-title{
  font-size:1.7rem;
  font-weight:900;
  letter-spacing:-.03em;
  line-height:1.05;
}
.splash-subtitle{
  margin-top:8px;
  color:#f2efe7;
  font-weight:700;
}
.splash-loader{
  height:7px;
  margin:22px auto 0;
  max-width:220px;
  overflow:hidden;
  border-radius:999px;
  background:rgba(255,255,255,.18);
}
.splash-loader span{
  display:block;
  width:42%;
  height:100%;
  border-radius:999px;
  background:var(--gold);
  animation:splashLoad 1.1s ease-in-out infinite;
}
@keyframes splashLoad{
  0%{transform:translateX(-120%)}
  100%{transform:translateX(260%)}
}
.version-footer{
  margin-top:10px;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  flex-wrap:wrap;
}
.version-chip{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius:999px;
  background:var(--soft);
  border:1px solid var(--line);
  color:var(--text);
  font-weight:850;
}
.changelog-link{
  border:1px solid var(--line);
  background:var(--card);
  color:var(--text);
  box-shadow:none;
  padding:7px 11px;
  border-radius:999px;
  font-size:.84rem;
}
body.dark .changelog-link,
body.dark .version-chip{
  background:#10243b;
  color:#f8fafc;
  border-color:#38506b;
}
.changelog-modal{
  position:fixed;
  inset:0;
  z-index:9998;
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(2,6,23,.62);
}
.changelog-modal.is-open{display:flex;}
.changelog-panel{
  width:min(92vw,560px);
  max-height:82vh;
  overflow:auto;
  background:var(--card);
  color:var(--text);
  border:2px solid var(--line);
  border-radius:24px;
  box-shadow:0 24px 80px rgba(0,0,0,.34);
  padding:22px;
}
.changelog-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding-bottom:12px;
  border-bottom:4px solid var(--gold);
}
.changelog-head h2{
  border:0;
  padding:0;
  margin:0;
}
.changelog-close{
  min-width:42px;
  min-height:42px;
  padding:0;
  border-radius:14px;
  box-shadow:none;
  background:var(--soft);
  color:var(--text);
  border:1px solid var(--line);
}
.changelog-panel ul{
  margin:14px 0 0;
  padding-left:22px;
  line-height:1.5;
}
.changelog-panel li{margin:7px 0;}
.changelog-note{
  margin-top:14px;
  padding:12px 14px;
  border-radius:16px;
  background:var(--soft);
  border:1px solid var(--line);
  font-size:.92rem;
  line-height:1.4;
}
body.dark .changelog-close{
  background:#1b3656;
  color:#f8fafc;
  border-color:#38506b;
}

/* Customize Layout overlay test */
.layout-toolbar{
  max-width:1180px;
  margin:0 auto 18px;
  padding:0 0 4px;
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}
.layout-toolbar button{
  box-shadow:none;
}
.layout-toolbar .small{
  margin:0;
  flex-basis:100%;
}
.layout-modal{
  position:fixed;
  inset:0;
  z-index:9998;
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(2,6,23,.62);
}
.layout-modal.is-open{
  display:flex;
}
.layout-panel{
  width:min(94vw,680px);
  max-height:84vh;
  overflow:hidden;
  background:var(--card);
  color:var(--text);
  border:2px solid var(--line);
  border-radius:24px;
  box-shadow:0 24px 80px rgba(0,0,0,.34);
  padding:22px;
}
.layout-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding-bottom:12px;
  border-bottom:4px solid var(--gold);
}
.layout-head h2{
  border:0;
  padding:0;
  margin:0;
}
.layout-close{
  min-width:42px;
  min-height:42px;
  padding:0;
  border-radius:14px;
  box-shadow:none;
  background:var(--soft);
  color:var(--text);
  border:1px solid var(--line);
}
.layout-list{
  display:flex;
  flex-direction:column;
  gap:9px;
  margin-top:14px;
}
.layout-row{
  display:flex;
  align-items:center;
  gap:12px;
  padding:13px 14px;
  border:1px solid var(--line);
  border-radius:16px;
  background:var(--soft);
  touch-action:none;
}
.layout-row.sortable-chosen{
  box-shadow:0 10px 24px rgba(13,36,63,.16);
}
.layout-row.sortable-drag{
  opacity:.92;
}
.layout-ghost{
  opacity:.45;
  border-style:dashed;
}
.layout-drag-handle{
  width:34px;
  height:34px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  flex:0 0 34px;
  border-radius:12px;
  background:rgba(13,36,63,.08);
  color:var(--navy);
  font-weight:950;
  cursor:grab;
  user-select:none;
}
.layout-drag-handle:active{
  cursor:grabbing;
}
.layout-name{
  font-weight:900;
  line-height:1.2;
}
.layout-footer{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  margin-top:16px;
  padding-top:14px;
  border-top:1px solid var(--line);
}
body.dark .layout-panel{
  background:#0f2136;
  color:#f8fafc;
  border-color:#38506b;
}
body.dark .layout-close,
body.dark .layout-row{
  background:#10243b;
  color:#f8fafc;
  border-color:#38506b;
}
body.dark .layout-drag-handle{
  background:#1b3656;
  color:#f8fafc;
}
@media (max-width:560px){
  .layout-row{
    padding:14px;
  }
  .layout-drag-handle{
    width:38px;
    height:38px;
    flex-basis:38px;
  }
}
@media print{
  .layout-toolbar,
  .layout-modal{
    display:none !important;
  }
}

@media (prefers-reduced-motion:reduce){
  .app-splash{transition:none;}
  .splash-loader span{animation:none;width:100%;}
}

@media (max-width:560px){
      header{padding:30px 22px}
      main{padding:22px 14px}
      .grid{grid-template-columns:1fr}
      .row{grid-template-columns:1fr}
      .card{padding:20px 18px}
    }
  
.disclaimer-link{
  border:1px solid var(--line);
  background:var(--card);
  color:var(--text);
  box-shadow:none;
  padding:7px 11px;
  border-radius:999px;
  font-size:.84rem;
}
body.dark .disclaimer-link{
  background:#10243b;
  color:#f8fafc;
  border-color:#38506b;
}
.disclaimer-modal{
  position:fixed;
  inset:0;
  z-index:9998;
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(2,6,23,.62);
}
.disclaimer-modal.is-open{display:flex;}
.disclaimer-panel{
  width:min(92vw,620px);
  max-height:82vh;
  overflow:auto;
  background:var(--card);
  color:var(--text);
  border:2px solid var(--line);
  border-radius:24px;
  box-shadow:0 24px 80px rgba(0,0,0,.34);
  padding:22px;
}
.disclaimer-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding-bottom:12px;
  border-bottom:4px solid var(--gold);
}
.disclaimer-head h2{
  border:0;
  padding:0;
  margin:0;
}
.disclaimer-close{
  min-width:42px;
  min-height:42px;
  padding:0;
  border-radius:14px;
  box-shadow:none;
  background:var(--soft);
  color:var(--text);
  border:1px solid var(--line);
}
.disclaimer-panel ul{
  margin:14px 0 0;
  padding-left:22px;
  line-height:1.5;
}
.disclaimer-panel li{margin:7px 0;}
.disclaimer-note{
  margin-top:14px;
  padding:12px 14px;
  border-radius:16px;
  background:var(--soft);
  border:1px solid var(--line);
  font-size:.92rem;
  line-height:1.4;
}
body.dark .disclaimer-close{
  background:#1b3656;
  color:#f8fafc;
  border-color:#38506b;
}


.result-hidden{
  display:none !important;
}


/* Quick Tool Icons + Advanced Favorites */
.header-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  flex-wrap:wrap;
  margin-top:12px;
}
.quick-tool-icons{
  display:inline-flex;
  align-items:center;
  gap:0;
  padding:3px;
  border:1px solid rgba(255,255,255,.16);
  border-radius:16px;
  background:rgba(255,255,255,.055);
}
.quick-tool-btn{
  width:36px;height:34px;padding:0;border-radius:11px;
  display:inline-flex;align-items:center;justify-content:center;
  background:transparent;color:#fff;
  border:0;box-shadow:none;
  font-size:.98rem;
  position:relative;
}
.quick-tool-btn + .quick-tool-btn::before{
  content:'';
  position:absolute;
  left:0;
  top:8px;
  bottom:8px;
  width:1px;
  background:rgba(255,255,255,.18);
}
.quick-tool-btn:hover{background:rgba(255,255,255,.12);}
.favorite-toggle{
  width:38px;height:38px;padding:0;border-radius:999px;
  display:inline-flex;align-items:center;justify-content:center;
  margin-left:auto;flex:0 0 38px;box-shadow:none;
  font-size:1.05rem;line-height:1;background:#e9e5da;
  color:var(--navy);border:1px solid #d1cabc;
}
.favorite-toggle.is-active{
  background:var(--gold);color:#1f1300;border-color:#b8870d;
}
.calc-title{width:100%;}
.tool-modal-backdrop{
  position:fixed;inset:0;z-index:10000;display:none;
  align-items:center;justify-content:center;padding:18px;
  background:rgba(2,6,23,.66);backdrop-filter:blur(5px);
}
.tool-modal-backdrop.is-open{display:flex;}
.tool-modal{
  width:min(92vw,760px);max-height:84vh;overflow:hidden;
  background:var(--card);color:var(--text);border:2px solid var(--line);
  border-radius:24px;box-shadow:0 24px 80px rgba(0,0,0,.35);
}
.tool-modal-head{
  position:sticky;top:0;z-index:1;display:flex;
  align-items:flex-start;justify-content:space-between;gap:12px;
  padding:20px 22px;background:var(--navy);color:#fff;
  border-bottom:6px solid var(--gold);
}
.tool-modal-head h2{margin:0;padding:0;border:0;color:#fff;}
.tool-modal-head p{margin:6px 0 0;color:#f2efe7;line-height:1.35;font-size:.95rem;}
.tool-modal-close{
  min-width:42px;min-height:42px;padding:0;border-radius:14px;
  border:1px solid rgba(255,255,255,.35);background:rgba(255,255,255,.14);
  color:#fff;box-shadow:none;font-size:1.25rem;
}
.tool-modal-body{padding:20px 22px 22px;}
.tool-modal-search{margin-top:0;min-height:48px;}
.tool-list{margin-top:14px;display:grid;gap:10px;}
.tool-list-item{
  width:100%;display:flex;align-items:center;justify-content:space-between;
  gap:12px;text-align:left;padding:13px 14px;border-radius:16px;
  border:1px solid var(--line);background:var(--soft);color:var(--text);
  box-shadow:none;
}
.tool-list-item:hover{filter:none;border-color:var(--gold);}
.tool-list-main{display:flex;flex-direction:column;gap:3px;}
.tool-list-title{font-weight:900;color:var(--text);}
.tool-list-meta{color:var(--muted);font-size:.84rem;line-height:1.3;}
.tool-list-star{font-size:1.15rem;color:#b8870d;flex:0 0 auto;}
.tool-search-row{
  display:grid;
  grid-template-columns:1fr auto;
  gap:8px;
  align-items:stretch;
}
.tool-search-main{
  width:100%;
}
.tool-search-fav-btn{
  min-width:48px;
  padding:10px 12px;
  border-radius:16px;
  box-shadow:none;
  background:var(--soft);
  color:#b8870d;
  border:1px solid var(--line);
  font-size:1.25rem;
  line-height:1;
}
.tool-search-fav-btn.is-active{
  background:var(--gold);
  color:#1f1300;
  border-color:var(--gold);
}
.tool-search-fav-btn:hover{
  filter:brightness(1.05);
}
body.dark .tool-search-fav-btn{
  background:#1b3656;
  color:#facc15;
  border-color:#38506b;
}
body.dark .tool-search-fav-btn.is-active{
  background:var(--gold);
  color:#1f1300;
  border-color:var(--gold);
}

.tool-empty{
  display:none;margin-top:14px;padding:16px;border-radius:16px;
  border:2px dashed var(--line);color:var(--muted);font-weight:800;text-align:center;
}
.tool-empty.is-visible{display:block;}
.fav-picker-note{
  margin-top:10px;
  color:var(--muted);
  font-size:.86rem;
  line-height:1.35;
}
body.dark .quick-tool-icons{background:rgba(255,255,255,.035);border-color:rgba(255,255,255,.12);}
body.dark .quick-tool-icons .quick-tool-btn{
  background:transparent !important;
  border:0 !important;
  box-shadow:none !important;
  color:#f8fafc !important;
}
body.dark .quick-tool-icons .quick-tool-btn:hover{
  background:rgba(255,255,255,.10) !important;
}
body.dark button.quick-tool-btn,
body.dark button.quick-tool-btn:hover,
body.dark .quick-tool-icons button.quick-tool-btn,
body.dark .quick-tool-icons button.quick-tool-btn:hover{
  background:transparent !important;
  border:0 !important;
  box-shadow:none !important;
  filter:none !important;
  color:#f8fafc !important;
}

body.dark .quick-tool-icons button.quick-tool-btn:hover{
  background:rgba(255,255,255,.10) !important;
}

body.dark .favorite-toggle{background:#1b3656;color:#f8fafc;border-color:#38506b;}
body.dark .favorite-toggle.is-active{background:var(--gold);color:#1f1300;}
body.dark .tool-list-item{background:#10243b;border-color:#38506b;}
@media (max-width:600px){
  .header-actions{justify-content:space-between;align-items:center;}
  .quick-tool-btn{width:36px;height:34px;}
  .tool-modal-backdrop{align-items:flex-end;padding:10px;}
  .tool-modal{max-height:90vh;border-radius:22px 22px 0 0;}
}



/* iOS Safari keyboard overlap fix for Search/Favorites modals */
@media (max-width:600px){
  .tool-modal-backdrop{
    align-items:flex-start !important;
    padding:calc(env(safe-area-inset-top, 0px) + 10px) 10px 10px !important;
    overflow:auto;
  }

  .tool-modal{
    max-height:90dvh !important;
    border-radius:22px !important;
    margin:0 auto !important;
  }

  .tool-modal-body{
    padding-bottom:calc(env(safe-area-inset-bottom, 0px) + 22px);
  }
}


/* iOS Safari input focus keyboard fix */
input,
select,
textarea{
  scroll-margin-top:calc(env(safe-area-inset-top, 0px) + 24px);
  scroll-margin-bottom:340px;
}

@supports (height: 100dvh){
  input,
  select,
  textarea{
    scroll-margin-bottom:38dvh;
  }
}


@media (max-width:560px){
  /* Tighten the Favorites modal header on mobile Safari */
  #favorites_modal .tool-modal-head{
    padding:16px 18px 14px;
    gap:10px;
  }

  #favorites_modal .tool-modal-head h2{
    font-size:1.65rem;
    line-height:1.08;
  }

  #favorites_modal .tool-modal-head p{
    font-size:.92rem;
    line-height:1.25;
    margin-top:5px;
  }

  #favorites_modal .tool-modal-close{
    min-width:46px;
    min-height:46px;
    border-radius:16px;
    font-size:1.35rem;
  }
}

@media (max-width:380px){
  #favorites_modal .tool-modal-head p{
    display:none;
  }
}

/* Make Customize Layout / Settings modal match Search/Favorites modal on mobile */
@media (max-width:600px){
  .layout-modal{
    align-items:flex-start !important;
    justify-content:center !important;
    padding:calc(env(safe-area-inset-top, 0px) + 10px) 10px 10px !important;
    overflow:auto !important;
  }

  .layout-panel{
    width:100% !important;
    max-height:90dvh !important;
    margin:0 auto !important;
    border-radius:22px !important;
  }
}

/* Mobile header + Favorites modal polish */
@media (max-width:600px){

  header{
    padding:18px 18px 20px !important;
  }

  .brand-lockup{
    gap:9px !important;
    align-items:center !important;
  }

  .header-logo{
    width:46px !important;
    height:46px !important;
    flex-basis:46px !important;
  }

  h1{
    font-size:clamp(1.75rem, 9vw, 2.35rem) !important;
    line-height:1 !important;
  }

  .sub{
    margin-top:6px !important;
    font-size:.94rem !important;
    line-height:1.24 !important;
  }

  .header-actions{
    margin-top:10px !important;
    gap:10px !important;
    align-items:center !important;
  }

  .quick-tool-icons{
    gap:0 !important;
    padding:3px !important;
    border-radius:15px !important;
  }

  .quick-tool-btn{
    width:34px !important;
    height:32px !important;
    min-width:34px !important;
    padding:0 !important;
    border-radius:10px !important;
    font-size:.94rem !important;
  }

  .theme-switch{
    gap:7px !important;
  }

  .theme-slider{
    width:46px !important;
    height:26px !important;
    flex-basis:46px !important;
  }

  .theme-slider::before{
    width:20px !important;
    height:20px !important;
    top:2px !important;
    left:3px !important;
  }

  .theme-switch input:checked + .theme-slider::before{
    transform:translateX(20px) !important;
  }

  .theme-label{
    font-size:.82rem !important;
  }

  #favorites_modal .tool-modal{
    width:calc(100vw - 20px) !important;
    max-height:90dvh !important;
    border-radius:22px !important;
  }

  #favorites_modal .tool-modal-head{
    padding:16px 16px 13px !important;
    gap:10px !important;
  }

  #favorites_modal .tool-modal-head h2{
    font-size:1.35rem !important;
    line-height:1.05 !important;
    margin:0 !important;
  }

  #favorites_modal .tool-modal-head p{
    margin-top:5px !important;
    font-size:.84rem !important;
    line-height:1.25 !important;
  }

  #favorites_modal .tool-modal-close{
    width:42px !important;
    height:42px !important;
    min-width:42px !important;
    min-height:42px !important;
    border-radius:14px !important;
    font-size:1.25rem !important;
    padding:0 !important;
  }

  #favorites_modal .tool-modal-body{
    padding:14px !important;
    padding-bottom:calc(env(safe-area-inset-bottom, 0px) + 18px) !important;
  }

  #favorites_modal .tool-list{
    gap:9px !important;
  }

  #favorites_modal .tool-list-item{
    min-height:54px !important;
    padding:12px 13px !important;
    border-radius:16px !important;
  }

  #favorites_modal .tool-list-title{
    font-size:.96rem !important;
    line-height:1.15 !important;
  }

  #favorites_modal .tool-list-meta{
    font-size:.78rem !important;
    line-height:1.25 !important;
  }

}

@media (max-width:380px){
  .theme-label{
    display:none !important;
  }

  .quick-tool-btn{
    width:31px !important;
    height:31px !important;
    min-width:31px !important;
  }

  #favorites_modal .tool-modal-head p{
    display:none !important;
  }
}

/* Prevent iOS Safari input zoom jump */
input,
select,
textarea{
  font-size:16px;
}

.favorite-remove-btn{
min-width:42px;
padding:10px 12px;
border-radius:14px;
box-shadow:none;
background:var(--gold);
color:#1f1300;
border:1px solid var(--gold);
font-size:1.1rem;
}



/* v3.0.1 Workflow Dashboard + Interop */
.home-dashboard,
.workflow-preferences{
  margin-bottom:18px;
}

.dashboard-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(210px,1fr));
  gap:12px;
}

.dashboard-tile{
  width:100%;
  min-height:96px;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  justify-content:center;
  gap:6px;
  text-align:left;
  border:1px solid var(--line);
  background:var(--soft);
  color:var(--text);
  box-shadow:none;
}

.dashboard-tile strong{
  font-size:1.05rem;
  color:var(--text);
}

.dashboard-tile span{
  color:var(--muted);
  font-size:.9rem;
  line-height:1.3;
}

.workflow-actions{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:12px;
  padding-top:12px;
  border-top:1px solid var(--line);
}

.workflow-action-btn{
  box-shadow:none;
  background:var(--soft);
  color:var(--text);
  border:1px solid var(--line);
  padding:9px 11px;
  font-size:.88rem;
}

body.dark .dashboard-tile,
body.dark .workflow-action-btn{
  background:#10243b;
  border-color:#38506b;
  color:#f8fafc;
}

body.dark .dashboard-tile strong{color:#f8fafc;}
body.dark .dashboard-tile span{color:#cbd5e1;}

/* v3.0.2 Settings polish */
.settings-section{
  margin-top:18px;
  padding-top:16px;
  border-top:1px solid var(--line);
}
.settings-section h3{
  margin:0 0 10px;
  color:var(--text);
  font-size:1rem;
}


/* v3.0.6 Favorite sorting */
#favorites_results .favorite-drag-handle{
  cursor:grab;
  touch-action:none;
  -webkit-user-select:none;
  user-select:none;
}

#favorites_results .sortable-ghost{
  opacity:.55;
}

#favorites_results .sortable-chosen{
  filter:brightness(1.03);
}


/* Modal rounded-corner scrollbar fix */
.tool-modal{
  overflow:hidden !important;
}

.tool-modal-body{
  overflow-y:auto;
  max-height:calc(84vh - 112px);
  scrollbar-gutter:stable;
}

.layout-panel{
  overflow:hidden !important;
  display:flex;
  flex-direction:column;
}

.layout-list{
  overflow-y:auto;
  max-height:calc(84vh - 145px);
  padding-right:6px;
  scrollbar-gutter:stable;
}

@media (max-width:600px){
  .tool-modal-body{
    max-height:calc(90dvh - 106px);
  }

  .layout-list{
    max-height:calc(90dvh - 145px);
  }
}


/* v3.0.7 iOS Settings modal rebuild
   Goal: stop the settings panel from acting like a giant desktop modal on iPhone.
   The panel becomes a fixed-height flex shell; the tool list + preferences scroll inside;
   the bottom action buttons stay usable without the content blowing past the viewport. */
.layout-modal.is-open{
  display:flex;
}

.layout-panel{
  display:flex !important;
  flex-direction:column !important;
  overflow:hidden !important;
}

.layout-head{
  flex:0 0 auto !important;
}

.layout-list{
  flex:1 1 auto !important;
  min-height:0 !important;
  overflow-y:auto !important;
  -webkit-overflow-scrolling:touch !important;
  max-height:none !important;
  padding-right:6px !important;
}

.layout-footer{
  flex:0 0 auto !important;
  position:sticky !important;
  bottom:0 !important;
  z-index:3 !important;
  background:var(--card) !important;
  margin-top:10px !important;
  padding-top:12px !important;
  padding-bottom:max(0px, env(safe-area-inset-bottom, 0px)) !important;
}

body.dark .layout-footer{
  background:#0f2136 !important;
}

@media (max-width:600px){
  .layout-modal{
    align-items:center !important;
    justify-content:center !important;
    padding:calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
    overflow:hidden !important;
  }

  .layout-panel{
    width:calc(100vw - 20px) !important;
    height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px) !important;
    max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px) !important;
    margin:0 auto !important;
    padding:16px !important;
    border-radius:22px !important;
  }

  .layout-head{
    padding-bottom:10px !important;
    gap:10px !important;
    border-bottom-width:5px !important;
  }

  .layout-head h2{
    font-size:1.8rem !important;
    line-height:1.05 !important;
  }

  .layout-head .small{
    font-size:.94rem !important;
    line-height:1.28 !important;
    margin-top:6px !important;
  }

  .layout-close{
    width:42px !important;
    height:42px !important;
    min-width:42px !important;
    min-height:42px !important;
    border-radius:15px !important;
  }

  .layout-list{
    gap:8px !important;
    margin-top:12px !important;
    padding-right:2px !important;
  }

  .layout-row{
    min-height:58px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
    gap:10px !important;
  }

  .layout-drag-handle{
    width:38px !important;
    height:38px !important;
    flex:0 0 38px !important;
    border-radius:13px !important;
  }

  .layout-name{
    font-size:1rem !important;
    line-height:1.15 !important;
  }

  .settings-section{
    margin-top:12px !important;
    padding-top:12px !important;
  }

  .settings-section h3{
    font-size:1.15rem !important;
    margin-bottom:8px !important;
  }

  .settings-section label{
    font-size:.98rem !important;
    margin-top:10px !important;
  }

  .settings-section select,
  .settings-section input{
    min-height:48px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
  }

  .settings-section .btns{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:9px !important;
    margin-top:12px !important;
  }

  .settings-section .btns button{
    width:100% !important;
    min-height:46px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
    font-size:.88rem !important;
  }

  .settings-section .small{
    font-size:.88rem !important;
    line-height:1.3 !important;
    margin-top:9px !important;
  }

  .layout-footer{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:10px !important;
    align-items:center !important;
    justify-content:stretch !important;
    margin-top:10px !important;
    padding-top:10px !important;
  }

  .layout-footer button{
    width:100% !important;
    min-height:46px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
    font-size:.9rem !important;
  }
}

@media (max-width:380px){
  .layout-panel{
    padding:14px !important;
  }

  .layout-head h2{
    font-size:1.55rem !important;
  }

  .layout-head .small{
    font-size:.86rem !important;
  }

  .layout-row{
    min-height:54px !important;
  }

  .settings-section .btns,
  .layout-footer{
    grid-template-columns:1fr !important;
  }
}


/* v3.0.7 Settings modal iOS rebuild — real fix
   The previous CSS made only .layout-list scroll, while Saved Preferences stayed outside that scroll area.
   index.html now wraps the list + preferences in .layout-scroll, so the modal has:
   header fixed, middle scrollable, footer fixed. */
.layout-panel{
  display:flex !important;
  flex-direction:column !important;
  overflow:hidden !important;
}

.layout-head,
.layout-footer{
  flex:0 0 auto !important;
}

.layout-scroll{
  flex:1 1 auto !important;
  min-height:0 !important;
  overflow-y:auto !important;
  -webkit-overflow-scrolling:touch !important;
  overscroll-behavior:contain !important;
  padding-right:6px !important;
  scrollbar-gutter:stable !important;
}

.layout-list{
  max-height:none !important;
  overflow:visible !important;
  padding-right:0 !important;
}

.layout-footer{
  position:relative !important;
  z-index:3 !important;
  background:var(--card) !important;
  padding-bottom:max(0px, env(safe-area-inset-bottom, 0px)) !important;
}

body.dark .layout-footer{
  background:#0f2136 !important;
}

@media (max-width:600px){
  .layout-modal{
    align-items:center !important;
    justify-content:center !important;
    padding:calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
    overflow:hidden !important;
  }

  .layout-panel{
    width:calc(100vw - 20px) !important;
    height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
    max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
    padding:14px !important;
    border-radius:22px !important;
  }

  .layout-head{
    padding-bottom:9px !important;
    border-bottom-width:5px !important;
  }

  .layout-head h2{
    font-size:1.55rem !important;
    line-height:1.05 !important;
  }

  .layout-head .small{
    font-size:.86rem !important;
    line-height:1.22 !important;
    margin-top:5px !important;
  }

  .layout-close{
    width:40px !important;
    height:40px !important;
    min-width:40px !important;
    min-height:40px !important;
    border-radius:14px !important;
  }

  .layout-scroll{
    margin-top:10px !important;
    padding-right:2px !important;
  }

  .layout-list{
    gap:8px !important;
    margin-top:0 !important;
  }

  .layout-row{
    min-height:52px !important;
    padding:9px 10px !important;
    border-radius:15px !important;
    gap:9px !important;
  }

  .layout-drag-handle{
    width:36px !important;
    height:36px !important;
    flex:0 0 36px !important;
    border-radius:12px !important;
  }

  .layout-name{
    font-size:.95rem !important;
    line-height:1.1 !important;
  }

  .settings-section{
    margin-top:12px !important;
    padding-top:12px !important;
  }

  .settings-section h3{
    font-size:1rem !important;
    margin-bottom:8px !important;
  }

  .settings-section label{
    font-size:.9rem !important;
    line-height:1.15 !important;
    margin-top:9px !important;
  }

  .settings-section select,
  .settings-section input{
    min-height:46px !important;
    padding:9px 12px !important;
    border-radius:15px !important;
    font-size:16px !important;
  }

  .settings-section .row{
    gap:8px !important;
  }

  .settings-section .btns{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:8px !important;
    margin-top:10px !important;
  }

  .settings-section .btns button{
    width:100% !important;
    min-height:44px !important;
    padding:9px 10px !important;
    border-radius:15px !important;
    font-size:.82rem !important;
  }

  .settings-section .small{
    font-size:.82rem !important;
    line-height:1.25 !important;
    margin-top:8px !important;
  }

  .layout-footer{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:8px !important;
    margin-top:8px !important;
    padding-top:9px !important;
  }

  .layout-footer button{
    width:100% !important;
    min-height:44px !important;
    padding:9px 10px !important;
    border-radius:15px !important;
    font-size:.86rem !important;
  }
}

@media (max-width:380px){
  .layout-panel{
    padding:12px !important;
  }

  .layout-head h2{
    font-size:1.42rem !important;
  }

  .layout-head .small{
    font-size:.8rem !important;
  }

  .layout-row{
    min-height:48px !important;
    padding:8px 9px !important;
  }

  .layout-drag-handle{
    width:34px !important;
    height:34px !important;
    flex-basis:34px !important;
  }

  .settings-section .btns,
  .layout-footer{
    grid-template-columns:1fr !important;
  }
}

/* v3.0.8 iOS Settings modal scroll fix
   Keeps the Settings panel fixed in the viewport while making the middle content
   the only scroll area. Also stops reorder rows from stealing normal vertical swipes. */
.layout-panel{
  min-height:0 !important;
  overflow:hidden !important;
}

.layout-scroll{
  min-height:0 !important;
  overflow-x:hidden !important;
  overflow-y:auto !important;
  -webkit-overflow-scrolling:touch !important;
  touch-action:pan-y !important;
  overscroll-behavior:contain !important;
}

.layout-list{
  min-height:0 !important;
  overflow:visible !important;
}

.layout-row{
  touch-action:pan-y !important;
}

.layout-drag-handle{
  touch-action:none !important;
}

@media (max-width:600px){
  .layout-modal{
    align-items:center !important;
    justify-content:center !important;
    overflow:hidden !important;
    padding:calc(env(safe-area-inset-top, 0px) + 8px) 10px calc(env(safe-area-inset-bottom, 0px) + 8px) !important;
  }

  .layout-panel{
    display:flex !important;
    flex-direction:column !important;
    width:calc(100vw - 20px) !important;
    height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
    max-height:calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
    min-height:0 !important;
    overflow:hidden !important;
  }

  .layout-head,
  .layout-footer{
    flex:0 0 auto !important;
  }

  .layout-scroll{
    flex:1 1 auto !important;
    min-height:0 !important;
    max-height:none !important;
    overflow-y:auto !important;
    -webkit-overflow-scrolling:touch !important;
    touch-action:pan-y !important;
    padding-right:2px !important;
    padding-bottom:8px !important;
  }

  .layout-row{
    touch-action:pan-y !important;
  }

  .layout-drag-handle{
    touch-action:none !important;
  }
}

@media (max-width:600px) and (not (height:100dvh)){
  .layout-panel{
    height:calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
    max-height:calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 22px) !important;
  }
}

/* v3.0.9 Settings modal visual match
   Make Settings use the same shell styling as Search/Favorites while keeping
   header fixed, middle scrollable, footer fixed. */
#layout_modal.layout-modal{
  background:rgba(2,6,23,.66) !important;
  backdrop-filter:blur(5px) !important;
}

#layout_modal .layout-panel{
  width:min(92vw,760px) !important;
  max-height:84vh !important;
  padding:0 !important;
  overflow:hidden !important;
  background:var(--card) !important;
  color:var(--text) !important;
  border:2px solid var(--line) !important;
  border-radius:24px !important;
  box-shadow:0 24px 80px rgba(0,0,0,.35) !important;
  display:flex !important;
  flex-direction:column !important;
}

#layout_modal .layout-head{
  position:relative !important;
  top:auto !important;
  z-index:2 !important;
  display:flex !important;
  align-items:flex-start !important;
  justify-content:space-between !important;
  gap:12px !important;
  flex:0 0 auto !important;
  padding:20px 22px !important;
  background:var(--navy) !important;
  color:#fff !important;
  border-bottom:6px solid var(--gold) !important;
}

#layout_modal .layout-head h2{
  margin:0 !important;
  padding:0 !important;
  border:0 !important;
  color:#fff !important;
}

#layout_modal .layout-head .small{
  margin:6px 0 0 !important;
  color:#f2efe7 !important;
  line-height:1.35 !important;
  font-size:.95rem !important;
}

#layout_modal .layout-close{
  min-width:42px !important;
  min-height:42px !important;
  padding:0 !important;
  border-radius:14px !important;
  border:1px solid rgba(255,255,255,.35) !important;
  background:rgba(255,255,255,.14) !important;
  color:#fff !important;
  box-shadow:none !important;
  font-size:1.25rem !important;
}

#layout_modal .layout-scroll{
  flex:1 1 auto !important;
  min-height:0 !important;
  overflow-x:hidden !important;
  overflow-y:auto !important;
  -webkit-overflow-scrolling:touch !important;
  touch-action:pan-y !important;
  overscroll-behavior:contain !important;
  padding:20px 22px 0 !important;
  scrollbar-gutter:stable !important;
}

#layout_modal .layout-list{
  margin-top:0 !important;
  display:flex !important;
  flex-direction:column !important;
  gap:10px !important;
  max-height:none !important;
  overflow:visible !important;
  padding-right:0 !important;
}

#layout_modal .layout-row{
  min-height:64px !important;
  padding:13px 14px !important;
  border-radius:16px !important;
  background:var(--soft) !important;
  border:1px solid var(--line) !important;
  color:var(--text) !important;
  touch-action:pan-y !important;
}

#layout_modal .layout-drag-handle{
  touch-action:none !important;
}

#layout_modal .settings-section{
  margin-top:18px !important;
  padding-top:16px !important;
  border-top:1px solid var(--line) !important;
}

#layout_modal .layout-footer{
  flex:0 0 auto !important;
  display:flex !important;
  justify-content:flex-end !important;
  gap:10px !important;
  margin:0 !important;
  padding:16px 22px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  border-top:1px solid var(--line) !important;
  background:var(--card) !important;
  position:relative !important;
  z-index:3 !important;
}

body.dark #layout_modal .layout-row,
body.dark #layout_modal .layout-footer{
  background:#10243b !important;
  color:#f8fafc !important;
  border-color:#38506b !important;
}

body.dark #layout_modal .layout-panel{
  background:#0f2136 !important;
  color:#f8fafc !important;
  border-color:#38506b !important;
}

body.dark #layout_modal .layout-scroll,
body.dark #layout_modal .settings-section{
  border-color:#38506b !important;
}

body.dark #layout_modal .layout-footer{
  background:#0f2136 !important;
}

@media (max-width:600px){
  #layout_modal.layout-modal{
    align-items:center !important;
    justify-content:center !important;
    padding:calc(env(safe-area-inset-top, 0px) + 10px) 10px calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
    overflow:hidden !important;
  }

  #layout_modal .layout-panel{
    width:calc(100vw - 20px) !important;
    height:auto !important;
    max-height:90dvh !important;
    border-radius:22px !important;
  }

  #layout_modal .layout-head{
    padding:16px 18px 14px !important;
    gap:10px !important;
  }

  #layout_modal .layout-head h2{
    font-size:1.65rem !important;
    line-height:1.08 !important;
  }

  #layout_modal .layout-head .small{
    font-size:.92rem !important;
    line-height:1.25 !important;
    margin-top:5px !important;
  }

  #layout_modal .layout-close{
    min-width:46px !important;
    min-height:46px !important;
    border-radius:16px !important;
    font-size:1.35rem !important;
  }

  #layout_modal .layout-scroll{
    padding:14px 18px 0 !important;
  }

  #layout_modal .layout-list{
    gap:9px !important;
  }

  #layout_modal .layout-row{
    min-height:58px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
    gap:10px !important;
  }

  #layout_modal .layout-drag-handle{
    width:38px !important;
    height:38px !important;
    flex:0 0 38px !important;
    border-radius:13px !important;
  }

  #layout_modal .layout-name{
    font-size:1rem !important;
    line-height:1.15 !important;
  }

  #layout_modal .layout-footer{
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:10px !important;
    padding:12px 18px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }

  #layout_modal .layout-footer button{
    width:100% !important;
    min-height:48px !important;
    padding:10px 12px !important;
    border-radius:16px !important;
    font-size:.9rem !important;
  }
}

@media (max-width:380px){
  #layout_modal .layout-head .small{
    display:none !important;
  }
}

/* Day Supply polish: keep example presets close to actions */
#tool_standard_day_supply .gen-example-row{
  margin-top:10px;
}




/* Unified Settings/Favorites reorder rows */
.favorite-list-row.layout-row{
  display:flex;
  align-items:center;
  gap:8px;
  width:100%;
}

.favorite-layout-name{
  flex:1 1 auto;
  min-width:0;
  text-align:left;
  background:transparent;
  color:var(--text);
  border:0;
  box-shadow:none;
  padding:0;
  font:inherit;
  font-weight:850;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  cursor:pointer;
}

.favorite-layout-name:hover{
  text-decoration:underline;
}

.favorite-layout-remove{
  width:40px;
  min-width:40px;
  height:36px;
  flex:0 0 40px;
  padding:0;
  border-radius:12px;
  box-shadow:none;
  display:flex;
  align-items:center;
  justify-content:center;
}

body.dark .favorite-layout-name{
  color:#f8fafc;
}

/* Keep Search/Favorites modal rows from inheriting global dark action-button blue */
body.dark .tool-list-item,
body.dark button.tool-list-item,
body.dark .tool-search-main,
body.dark .favorite-layout-name{
  background:var(--soft) !important;
  color:var(--text) !important;
  border-color:var(--line) !important;
  box-shadow:none !important;
  filter:none !important;
}

body.dark .tool-list-item:hover,
body.dark button.tool-list-item:hover,
body.dark .tool-search-main:hover,
body.dark .favorite-layout-name:hover{
  background:rgba(255,255,255,.06) !important;
  border-color:rgba(216,168,51,.72) !important;
  filter:none !important;
}

body.dark .tool-search-fav-btn,
body.dark .favorite-layout-remove{
  background:var(--soft) !important;
  color:#facc15 !important;
  border-color:var(--line) !important;
  box-shadow:none !important;
  filter:none !important;
}

body.dark .tool-search-fav-btn:hover,
body.dark .favorite-layout-remove:hover{
  background:rgba(255,255,255,.08) !important;
  border-color:rgba(216,168,51,.72) !important;
  filter:none !important;
}

body.dark .tool-search-fav-btn.is-active{
  background:var(--gold) !important;
  color:#1f1300 !important;
  border-color:var(--gold) !important;
}

/* Card favorite buttons should stay gold after toggling in dark mode */
body.dark button.secondary.favorite-toggle.is-active,
body.dark button.favorite-toggle.is-active,
body.dark .card button.favorite-toggle.is-active{
  background:var(--gold) !important;
  color:#1f1300 !important;
  border-color:#b8870d !important;
  box-shadow:0 4px 0 rgba(0,0,0,.28) !important;
  filter:none !important;
}

body.dark button.secondary.favorite-toggle.is-active:hover,
body.dark button.favorite-toggle.is-active:hover,
body.dark .card button.favorite-toggle.is-active:hover{
  background:var(--gold) !important;
  color:#1f1300 !important;
  border-color:#b8870d !important;
  filter:none !important;
}

/* v3.0.28 Mobile spacing refinement */
@media (max-width:600px){
  main{
    padding:14px 12px 18px !important;
  }

  .grid{
    gap:14px !important;
  }

  .card{
    padding:18px 14px !important;
    border-radius:20px !important;
  }

  .card h2{
    margin-bottom:12px !important;
    padding-bottom:9px !important;
  }

  .row{
    gap:10px !important;
  }

  .btns{
    gap:8px !important;
    margin-top:12px !important;
  }

  .preset-row{
    gap:7px !important;
    margin-top:12px !important;
  }

  .history{
    margin-top:14px !important;
    padding-top:12px !important;
  }

  .small{
    margin-top:8px !important;
  }

  input,
  select,
  textarea,
  .result{
    margin-top:5px !important;
  }
}
