  :root{
    color-scheme: light only;
    --teal:#0d9488; --teal-dark:#0f766e; --teal-light:#ccfbf1;
    --bg:#f1f5f9; --card:#ffffff; --ink:#0f172a; --muted:#64748b;
    --line:#e2e8f0; --danger:#dc2626; --danger-bg:#fef2f2;
    --amber:#d97706; --amber-bg:#fffbeb; --radius:16px;
    --shadow:0 1px 3px rgba(0,0,0,.08),0 1px 2px rgba(0,0,0,.04);
  }
  *{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
  html,body{margin:0;padding:0}
  html{color-scheme:light only;background:var(--bg)}
  body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
    background:var(--bg);color:var(--ink);line-height:1.5;padding-bottom:90px}
  /* Header */
  header{position:sticky;top:0;z-index:50;background:var(--teal);
    color:#fff;padding:14px 16px;box-shadow:var(--shadow)}
  .hrow{display:flex;align-items:center;gap:10px;max-width:760px;margin:0 auto}
  .hrow h1{font-size:19px;margin:0;font-weight:700;flex:1;display:flex;align-items:center;gap:8px}
  .icon-btn{background:rgba(255,255,255,.18);border:none;color:#fff;width:38px;height:38px;
    border-radius:10px;font-size:18px;cursor:pointer;display:flex;align-items:center;justify-content:center}
  .icon-btn:active{background:rgba(255,255,255,.32)}
  .wrap{max-width:760px;margin:0 auto;padding:16px}
  /* Search */
  .search{position:relative;margin-bottom:16px}
  .search input{width:100%;padding:12px 14px 12px 40px;border:1px solid var(--line);
    border-radius:12px;font-size:15px;background:var(--card);outline:none}
  .search input:focus{border-color:var(--teal)}
  .search .s-ic{position:absolute;left:13px;top:50%;transform:translateY(-50%);color:var(--muted)}
  /* Profile cards grid */
  .grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
  @media(min-width:560px){.grid{grid-template-columns:1fr 1fr 1fr}}
  .pcard{background:var(--card);border-radius:var(--radius);padding:16px;box-shadow:var(--shadow);
    cursor:pointer;border:1px solid var(--line);transition:transform .08s;position:relative;overflow:hidden}
  .pcard:active{transform:scale(.97)}
  .avatar{width:52px;height:52px;border-radius:50%;background:var(--teal-light);color:var(--teal-dark);
    display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:700;margin-bottom:10px}
  .pcard h3{margin:0 0 2px;font-size:16px}
  .pcard .rel{color:var(--muted);font-size:13px}
  .pcard .badges{margin-top:8px;display:flex;gap:5px;flex-wrap:wrap}
  .badge{font-size:11px;padding:2px 8px;border-radius:20px;font-weight:600}
  .badge.concern{background:var(--danger-bg);color:var(--danger)}
  .badge.tx{background:var(--teal-light);color:var(--teal-dark)}
  .add-card{background:transparent;border:2px dashed var(--line);color:var(--muted);
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    min-height:150px;border-radius:var(--radius);cursor:pointer;font-weight:600}
  .add-card:active{border-color:var(--teal);color:var(--teal)}
  .add-card .plus{font-size:34px;line-height:1;margin-bottom:6px}
  .empty{text-align:center;padding:50px 20px;color:var(--muted)}
  .empty .big{font-size:52px;margin-bottom:12px}
  /* Detail view */
  #detail{display:none}
  .back{display:flex;align-items:center;gap:6px;background:none;border:none;color:var(--teal);
    font-size:15px;font-weight:600;cursor:pointer;padding:0;margin-bottom:14px}
  .phead{background:var(--card);border-radius:var(--radius);padding:18px;box-shadow:var(--shadow);
    margin-bottom:14px;border:1px solid var(--line)}
  .phead-top{display:flex;align-items:center;gap:14px;margin-bottom:14px}
  .phead-top .avatar{margin:0;width:60px;height:60px;font-size:26px}
  .phead-top h2{margin:0;font-size:22px}
  .phead-top .rel{color:var(--muted);font-size:14px}
  .vitals{display:grid;grid-template-columns:1fr 1fr;gap:10px}
  @media(min-width:560px){.vitals{grid-template-columns:repeat(4,1fr)}}
  .vital{background:var(--bg);border-radius:10px;padding:8px 10px}
  .vital .lbl{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.03em}
  .vital .val{font-size:15px;font-weight:600;margin-top:1px}
  .vital.allergy .val{color:var(--danger)}
  /* Sections */
  .section{background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow);
    margin-bottom:14px;border:1px solid var(--line);overflow:hidden}
  .sec-head{display:flex;align-items:center;gap:8px;padding:14px 16px;font-weight:700;font-size:15px}
  .sec-head .sic{font-size:18px}
  .sec-head .count{margin-left:auto;font-size:13px;color:var(--muted);font-weight:500}
  .sec-body{padding:0 16px 14px}
  .item{background:var(--bg);border-radius:12px;padding:12px;margin-bottom:10px;position:relative}
  .item:last-child{margin-bottom:0}
  .item .del{position:absolute;top:8px;right:8px;background:none;border:none;color:var(--muted);
    cursor:pointer;font-size:16px;padding:4px;line-height:1}
  .mv{display:inline-flex;gap:2px;margin-left:6px;vertical-align:middle}
  .mv button{background:#e2e8f0;border:none;border-radius:6px;width:24px;height:22px;cursor:pointer;
    font-size:12px;color:#334155;line-height:1;padding:0}
  .mv button:active{background:#cbd5e1}
  .mv button:disabled{opacity:.35;cursor:default}
  .tagmv{display:inline-flex;gap:2px;margin-left:4px}
  .tagmv span{cursor:pointer;opacity:.55;font-size:11px}
  .item h4{margin:0 0 6px;font-size:15px;padding-right:24px}
  .kv{display:flex;gap:6px;font-size:13px;margin-top:3px}
  .kv .k{color:var(--muted);min-width:78px}
  .kv .v{font-weight:500;flex:1}
  .kv .v.call{color:var(--teal);text-decoration:none;font-weight:600}
  .tag{display:inline-block;background:var(--teal-light);color:var(--teal-dark);
    font-size:12px;padding:3px 9px;border-radius:20px;margin:3px 4px 0 0;font-weight:600}
  .tag.concern{background:var(--danger-bg);color:var(--danger)}
  .note-txt{font-size:14px;white-space:pre-wrap;color:var(--ink)}
  .add-btn{width:100%;background:var(--teal-light);color:var(--teal-dark);border:none;
    padding:11px;border-radius:12px;font-size:14px;font-weight:600;cursor:pointer;margin-top:4px}
  .add-btn:active{background:#99f6e4}
  .none{color:var(--muted);font-size:14px;font-style:italic;padding:4px 0}
  /* Documents */
  .docs{display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
  .doc{position:relative;border-radius:10px;overflow:hidden;background:var(--bg);aspect-ratio:1;cursor:pointer}
  .doc img{width:100%;height:100%;object-fit:cover;display:block}
  .doc .dlbl{position:absolute;bottom:0;left:0;right:0;background:rgba(0,0,0,.6);color:#fff;
    font-size:10px;padding:3px 5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .doc .ddel{position:absolute;top:4px;right:4px;background:rgba(0,0,0,.55);color:#fff;border:none;
    width:22px;height:22px;border-radius:50%;font-size:13px;cursor:pointer;line-height:1}
  .doc-add{border:2px dashed var(--line);display:flex;align-items:center;justify-content:center;
    color:var(--muted);font-size:28px;aspect-ratio:1;border-radius:10px;cursor:pointer}
  /* FAB */
  .fab{position:fixed;bottom:24px;right:24px;width:58px;height:58px;border-radius:50%;
    background:var(--teal);color:#fff;border:none;font-size:28px;box-shadow:0 4px 14px rgba(13,148,136,.5);
    cursor:pointer;z-index:40;display:flex;align-items:center;justify-content:center}
  .fab:active{background:var(--teal-dark)}
  /* Modal */
  .overlay{position:fixed;inset:0;background:rgba(15,23,42,.5);z-index:100;display:none;
    align-items:flex-end;justify-content:center}
  .overlay.on{display:flex}
  @media(min-width:560px){.overlay{align-items:center}}
  .modal{background:var(--card);width:100%;max-width:520px;border-radius:20px 20px 0 0;
    max-height:90vh;overflow-y:auto;padding:20px;animation:slideup .2s ease}
  @media(min-width:560px){.modal{border-radius:20px}}
  @keyframes slideup{from{transform:translateY(30px);opacity:.5}to{transform:translateY(0);opacity:1}}
  .modal h3{margin:0 0 16px;font-size:18px}
  .field{margin-bottom:14px}
  .field label{display:block;font-size:13px;font-weight:600;color:var(--muted);margin-bottom:5px}
  .field input,.field textarea,.field select{width:100%;padding:11px;border:1px solid var(--line);
    border-radius:10px;font-size:15px;font-family:inherit;outline:none;background:#fff;
    color:var(--ink)}
  .field input::placeholder,.field textarea::placeholder{color:#94a3b8;-webkit-text-fill-color:#94a3b8;opacity:1}
  .search input{color:var(--ink);-webkit-text-fill-color:var(--ink)}
  .search input::placeholder{color:#94a3b8;-webkit-text-fill-color:#94a3b8;opacity:1}
  .field input:focus,.field textarea:focus,.field select:focus{border-color:var(--teal)}
  .field textarea{resize:vertical;min-height:70px}
  .field .hint{font-size:12px;color:var(--muted);margin-top:4px}
  .row2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
  .mbtns{display:flex;gap:10px;margin-top:18px}
  .btn{flex:1;padding:13px;border-radius:12px;font-size:15px;font-weight:600;cursor:pointer;border:none}
  .btn.primary{background:var(--teal);color:#fff}
  .btn.primary:active{background:var(--teal-dark)}
  .btn.ghost{background:var(--bg);color:var(--ink)}
  .btn.danger{background:var(--danger-bg);color:var(--danger)}
  /* Lightbox */
  .lightbox{position:fixed;inset:0;background:rgba(0,0,0,.92);z-index:200;display:none;
    align-items:center;justify-content:center;flex-direction:column}
  .lightbox.on{display:flex}
  .lightbox img{max-width:94%;max-height:80%;border-radius:8px}
  .lightbox .lbclose{position:absolute;top:16px;right:16px;background:rgba(255,255,255,.15);
    color:#fff;border:none;width:42px;height:42px;border-radius:50%;font-size:22px;cursor:pointer}
  .lightbox .lbcap{color:#fff;margin-top:14px;font-size:14px}
  /* Menu sheet */
  .menu-item{display:flex;align-items:center;gap:12px;padding:15px 8px;font-size:16px;
    cursor:pointer;border-bottom:1px solid var(--line)}
  .menu-item:last-child{border:none}
  .menu-item .mic{font-size:20px;width:24px;text-align:center}
  .toast{position:fixed;bottom:100px;left:50%;transform:translateX(-50%);background:#0f766e;
    color:#ffffff;padding:11px 22px;border-radius:24px;font-size:14px;font-weight:600;z-index:300;opacity:0;
    transition:opacity .25s;pointer-events:none;box-shadow:0 4px 14px rgba(0,0,0,.3);
    -webkit-text-fill-color:#ffffff;color-scheme:dark}
  .toast.on{opacity:1}
  .disclaimer{font-size:11px;color:var(--muted);text-align:center;padding:8px 20px 0;line-height:1.4}
  .up-wrap{background:var(--card);border-radius:var(--radius);box-shadow:var(--shadow);border:1px solid var(--line);margin-bottom:16px;overflow:hidden}
  .up-head{padding:14px 16px;font-weight:700;font-size:15px;display:flex;align-items:center;gap:8px;border-bottom:1px solid var(--line)}
  .up-grp{font-size:12px;font-weight:700;text-transform:uppercase;letter-spacing:.04em;color:var(--muted);padding:12px 16px 4px}
  .up-grp.od{color:var(--danger)}
  .up-row{display:flex;align-items:center;gap:12px;padding:11px 16px;border-top:1px solid var(--line);cursor:pointer}
  .up-row:active{background:var(--bg)}
  .up-av{width:38px;height:38px;border-radius:50%;background:var(--teal-light);color:var(--teal-dark);display:flex;align-items:center;justify-content:center;font-weight:700;font-size:15px;flex-shrink:0}
  .up-info{flex:1;min-width:0}
  .up-info .who{font-weight:600;font-size:14px}
  .up-info .what{font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .up-date{font-size:12px;font-weight:700;text-align:right;flex-shrink:0}
  .up-date.od{color:var(--danger)} .up-date.soon{color:var(--amber)} .up-date.later{color:var(--muted)}
  .up-empty{padding:22px 16px;text-align:center;color:var(--muted);font-size:14px}
  /* ============================================================
     CLEAN THEME LOCK — single source of truth (no conflicting rules)
     Light app surfaces + DARK popup with white text.
     Uses only 'color' (not -webkit-text-fill-color) to avoid traps.
     ============================================================ */

  /* App base */
  html{color-scheme:light !important;background:#f1f5f9 !important}
  body{background:#f1f5f9 !important;color:#0f172a !important}
  .wrap,#list,#detail,#upcoming{background:#f1f5f9 !important}
  header{background:#0d9488 !important}
  header h1,header .icon-btn,header h1 *{color:#ffffff !important;-webkit-text-fill-color:#ffffff !important}

  /* Cards & sections — light */
  .pcard,.phead,.section,.up-wrap{background:#ffffff !important;color:#0f172a !important}
  .pcard h3,.phead-top h2,.item h4,.note-txt,.sec-head,.kv .v,.vital .val,.up-info .who{color:#0f172a}
  .item,.vital{background:#f1f5f9 !important}
  .rel,.sec-head .count,.vital .lbl,.hint,.none,.up-grp,.up-info .what,.disclaimer,.kv .k{color:#64748b}
  .vital.allergy .val,.badge.concern,.tag.concern,.up-grp.od,.up-date.od{color:#dc2626}
  .tag,.badge.tx,.kv .v.call{color:#0f766e}
  .search input{background:#ffffff !important;color:#0f172a !important}

  /* ===== POPUP / MODAL — LIGHT background, DARK text (matches app) ===== */
  .overlay{background:rgba(15,23,42,.5) !important}
  .modal{background:#ffffff !important;color:#0f172a !important;color-scheme:light !important}
  .modal h3{color:#0f172a !important}
  .modal .field label{color:#475569 !important}
  .modal .hint,.modal .field .hint{color:#64748b !important}
  .modal .note-txt,.modal p,.modal span,.modal b{color:#0f172a !important}
  .modal input,.modal textarea,.modal select{
    background:#ffffff !important;color:#0f172a !important;border:1px solid #cbd5e1 !important;color-scheme:light !important}
  .modal input::placeholder,.modal textarea::placeholder{color:#94a3b8 !important;opacity:1}
  .modal .btn.primary{background:#0d9488 !important;color:#ffffff !important}
  .modal .btn.ghost{background:#f1f5f9 !important;color:#0f172a !important}
  .modal .btn.danger{background:#fef2f2 !important;color:#dc2626 !important}

  /* Toast confirmation pill — teal bg, white text (forced) */
  .toast{background:#0f766e !important;color:#ffffff !important;-webkit-text-fill-color:#ffffff !important;color-scheme:dark !important}

  /* Menu sheet — light to match app */
  .menu-item{background:#ffffff !important;color:#0f172a !important;border-color:#e2e8f0 !important}
  .menu-item div,.menu-item b,.menu-item span{color:#0f172a !important}
  .menu-item div div{color:#64748b !important}

  /* ============================================================
     DARK MODE — attribute-scoped overrides, higher specificity than
     the light lock above so they win when data-theme="dark".
     ============================================================ */
  html[data-theme="dark"]{background:#0f172a !important;color-scheme:dark !important}
  html[data-theme="dark"] body{background:#0f172a !important;color:#e2e8f0 !important}
  html[data-theme="dark"] .wrap,
  html[data-theme="dark"] #list,
  html[data-theme="dark"] #detail,
  html[data-theme="dark"] #upcoming{background:#0f172a !important}
  html[data-theme="dark"] header{background:#0f766e !important}
  html[data-theme="dark"] header h1,
  html[data-theme="dark"] header .icon-btn,
  html[data-theme="dark"] header h1 *{color:#ffffff !important}
  html[data-theme="dark"] .pcard,
  html[data-theme="dark"] .phead,
  html[data-theme="dark"] .section,
  html[data-theme="dark"] .up-wrap{background:#1e293b !important;color:#e2e8f0 !important;border-color:#334155 !important}
  html[data-theme="dark"] .pcard h3,
  html[data-theme="dark"] .phead-top h2,
  html[data-theme="dark"] .item h4,
  html[data-theme="dark"] .note-txt,
  html[data-theme="dark"] .sec-head,
  html[data-theme="dark"] .kv .v,
  html[data-theme="dark"] .vital .val,
  html[data-theme="dark"] .up-info .who{color:#e2e8f0 !important}
  html[data-theme="dark"] .item,
  html[data-theme="dark"] .vital{background:#0f172a !important;color:#e2e8f0 !important}
  html[data-theme="dark"] .rel,
  html[data-theme="dark"] .sec-head .count,
  html[data-theme="dark"] .vital .lbl,
  html[data-theme="dark"] .hint,
  html[data-theme="dark"] .none,
  html[data-theme="dark"] .up-grp,
  html[data-theme="dark"] .up-info .what,
  html[data-theme="dark"] .disclaimer,
  html[data-theme="dark"] .kv .k{color:#94a3b8 !important}
  html[data-theme="dark"] .search input{background:#1e293b !important;color:#e2e8f0 !important;border-color:#334155 !important}
  html[data-theme="dark"] .search input::placeholder{color:#64748b !important;-webkit-text-fill-color:#64748b !important}
  html[data-theme="dark"] .add-card{border-color:#334155 !important;color:#94a3b8 !important;background:transparent !important}
  html[data-theme="dark"] .doc{background:#0f172a !important}
  html[data-theme="dark"] .doc-add{border-color:#334155 !important;color:#94a3b8 !important}
  html[data-theme="dark"] .add-btn{background:#134e4a !important;color:#5eead4 !important}
  html[data-theme="dark"] .tag{background:#134e4a !important;color:#5eead4 !important}
  html[data-theme="dark"] .badge.tx{background:#134e4a !important;color:#5eead4 !important}
  html[data-theme="dark"] .kv .v.call{color:#5eead4 !important}
  html[data-theme="dark"] .mv button{background:#334155 !important;color:#e2e8f0 !important}
  html[data-theme="dark"] .up-row{border-color:#334155 !important}
  html[data-theme="dark"] .up-head{border-color:#334155 !important}
  html[data-theme="dark"] .badge.concern,
  html[data-theme="dark"] .tag.concern,
  html[data-theme="dark"] .up-grp.od,
  html[data-theme="dark"] .up-date.od,
  html[data-theme="dark"] .vital.allergy .val{color:#fca5a5 !important}
  html[data-theme="dark"] .modal{background:#1e293b !important;color:#e2e8f0 !important;color-scheme:dark !important}
  html[data-theme="dark"] .modal h3{color:#e2e8f0 !important}
  html[data-theme="dark"] .modal .field label{color:#94a3b8 !important}
  html[data-theme="dark"] .modal .hint,
  html[data-theme="dark"] .modal .field .hint{color:#94a3b8 !important}
  html[data-theme="dark"] .modal .note-txt,
  html[data-theme="dark"] .modal p,
  html[data-theme="dark"] .modal span,
  html[data-theme="dark"] .modal b{color:#e2e8f0 !important}
  html[data-theme="dark"] .modal input,
  html[data-theme="dark"] .modal textarea,
  html[data-theme="dark"] .modal select{background:#0f172a !important;color:#e2e8f0 !important;border:1px solid #334155 !important;color-scheme:dark !important}
  html[data-theme="dark"] .modal input::placeholder,
  html[data-theme="dark"] .modal textarea::placeholder{color:#64748b !important;-webkit-text-fill-color:#64748b !important}
  html[data-theme="dark"] .modal .btn.primary{background:#0d9488 !important;color:#ffffff !important}
  html[data-theme="dark"] .modal .btn.ghost{background:#0f172a !important;color:#e2e8f0 !important}
  html[data-theme="dark"] .modal .btn.danger{background:#450a0a !important;color:#fca5a5 !important}
  html[data-theme="dark"] .menu-item{background:#1e293b !important;color:#e2e8f0 !important;border-color:#334155 !important}
  html[data-theme="dark"] .menu-item div,
  html[data-theme="dark"] .menu-item b,
  html[data-theme="dark"] .menu-item span{color:#e2e8f0 !important}
  html[data-theme="dark"] .menu-item div div{color:#94a3b8 !important}
