:root{
    --bg: #eef1f4;
    --card: #ffffff;
    --ink: #17202b;
    --ink-soft: #6b7686;
    --line: #e7ebf0;
    --teal: #33d6c0;
    --teal-deep: #14a893;
    --teal-soft: rgba(51,214,192,.14);
    --purple: #8b7cf6;
    --purple-deep: #6c56f0;
    --purple-soft: rgba(139,124,246,.14);
    --amber: #f2a93b;
    --radius: 26px;
    --radius-sm: 16px;
    --shadow: 0 1px 2px rgba(23,32,43,.04), 0 12px 30px -14px rgba(23,32,43,.12);
    --font-display: 'Numa Display', 'Manrope', 'Segoe UI', sans-serif;
    --font-body: 'Manrope', 'Segoe UI', sans-serif;
    --font-mono: 'Roboto Mono', 'Courier New', monospace;
  }

  @font-face {
    font-family: 'Manrope';
    src: local('Manrope');
  }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
  }

  body::before{
    content:"";
    position: fixed;
    inset: 0;
    background:
      radial-gradient(1200px 600px at 15% -10%, rgba(51,214,192,.08), transparent 60%),
      radial-gradient(900px 500px at 100% 0%, rgba(139,124,246,.08), transparent 55%);
    pointer-events: none;
    z-index: 0;
  }

  .shell{
    position: relative;
    z-index: 1;
    max-width: 1320px;
    margin: 0 auto;
    padding: 28px 45px 80px;
  }

  /* ---------- TOP BAR ---------- */
  .topbar{
    display:flex;
    align-items:center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 14px;
  }
  .brand{
    display:flex;
    align-items:center;
    gap: 12px;
  }
  .brand-mark{
    width: 40px; height: 40px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--teal), var(--purple));
    position: relative;
    display:flex; align-items:center; justify-content:center;
    box-shadow: 0 6px 16px -6px rgba(108,86,240,.55);
  }
  .brand-mark svg{ width: 18px; height: 18px; }
  @keyframes pulseDot{
    0%,100%{ transform: scale(1); opacity: 1; }
    50%{ transform: scale(1.5); opacity: .55; }
  }
  .brand-text h1{
    font-size: 19px;
    margin: 0;
    letter-spacing: .2px;
    font-weight: 800;
  }
  .brand-text p{
    margin: 0;
    font-size: 12.5px;
    color: var(--ink-soft);
    font-family: var(--font-mono);
  }
  .top-status{
    display:flex;
    align-items:center;
    gap: 18px;
    font-size: 13px;
    color: var(--ink-soft);
  }
  .live-chip{
    display:flex; align-items:center; gap:7px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 14px;
    box-shadow: var(--shadow);
    font-weight: 700;
    color: var(--teal-deep);
    font-family: var(--font-mono);
    font-size: 12px;
  }
  .live-chip .d{
    width:7px;height:7px;border-radius:50%;
    background: var(--teal);
    animation: pulseDot 1.6s ease-in-out infinite;
  }
  #clock{ font-family: var(--font-mono); }

  /* ---------- GRID ---------- */
  .grid{
    display:grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "profile evolution evolution"
      "glucose bp hr"
      "oxi airways body"
      "meds diag body";
    gap: 22px;
  }
  @media (max-width: 980px){
    .shell{ padding-left: 20px; padding-right: 20px; }
    .grid{
      grid-template-columns: 1fr;
      grid-template-areas:
        "profile"
        "evolution"
        "glucose"
        "bp"
        "hr"
        "oxi"
        "airways"
        "body"
        "meds"
        "diag";
    }
  }

  /* ---------- MOBILE: show notice only ---------- */
  .mobile-notice{
    display: none;
  }
  @media (max-width: 600px){
    .shell{ display: none; }
    .mobile-notice{
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 16px;
      min-height: 100vh;
      padding: 32px;
      text-align: center;
      color: var(--ink-soft);
      font-weight: 700;
      font-size: 16px;
    }
    .mobile-notice svg{ width: 48px; height: 48px; color: var(--ink-soft); }
  }

  .card{
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    position: relative;
    border: 1px solid rgba(23,32,43,.03);
    min-width: 0;
    overflow: hidden;
  }
  .chart-wrap canvas,
  .modal-chart canvas{
    display: block;
    width: 100% !important;
    height: 100% !important;
  }
  .card-head{
    display:flex;
    justify-content: space-between;
    align-items:flex-start;
    margin-bottom: 6px;
  }
  .eyebrow{
    font-size: 12.5px;
    color: var(--ink-soft);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-family: var(--font-mono);
  }
  .metric-value{
    font-size: 34px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 2px 0 14px;
  }
  .metric-value .unit{
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-soft);
    margin-left: 4px;
  }
  .dots{
    display:flex; align-items:center; justify-content:center;
    color: #9aa4b2;
    cursor:pointer;
    padding: 4px;
  }
  .dots svg{ width:20px; height:20px; stroke: currentColor; display:block; }
  .dots:hover{ color: var(--ink-soft); }
  .dots span{ display:none; }
  .btn{
    border:none;
    cursor:pointer;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 13.5px;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-radius: 12px;
    padding: 12px 18px;
    background: var(--teal-deep);
    color: #fff;
    transition: transform .15s ease, filter .15s ease;
    width: 100%;
  }
  .btn:hover{ filter: brightness(1.06); transform: translateY(-1px); }
  .btn:active{ transform: translateY(0); }
  .btn-ghost{
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
    width: auto;
    text-transform: uppercase;
    letter-spacing: .03em;
    font-weight: 700;
    font-size: 13.5px;
  }

  /* ---------- PROFILE ---------- */
  .card-profile{ grid-area: profile; }
  .profile-top{
    display:flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
  }
  .avatar{
    width: 68px; height: 68px;
    border-radius: 50%;
    background: #4A90D9;
    display:flex; align-items:center; justify-content:center;
    flex-shrink:0;
    overflow: hidden;
    border: 1px solid var(--line);
    cursor: pointer;
  }
  .avatar svg{ width: 60%; height: 60%; }
  .profile-name{
    font-size: 12.5px; color: var(--ink-soft); font-weight:700;
    text-transform: uppercase; letter-spacing:.05em; font-family: var(--font-mono);
  }
  .profile-name-value{
    font-size: 21px; font-weight: 800; outline:none;
    border-bottom: 1px dashed transparent;
  }
  .profile-name-value:focus{ border-bottom-color: var(--purple); }
  .field-grid{
    display:grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px 14px;
    margin-bottom: 14px;
  }
  .field label{
    display:block;
    font-size: 11.5px;
    color: var(--ink-soft);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 5px;
    font-family: var(--font-mono);
  }
  .field .val{
    font-size: 18px;
    font-weight: 800;
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px;
    outline: none;
    min-height: 26px;
    cursor: text;
  }
  .field .val:focus{ border-bottom-color: var(--purple); }
  .field.wide{ grid-column: span 3; }
  select.val{
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    width: 100%;
    font-family: var(--font-body);
    cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%236b7686' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 2px center;
    background-size: 14px;
    padding-right: 18px;
  }
  select.val.small{ background-size: 12px; padding-right: 16px; }
  .field .val.small{ font-size: 15px; font-weight: 700; }
  .hint{ font-size: 11px; color: #b7bfc9; margin-top: 8px; font-style: italic;}

  /* ---------- EVOLUTION ---------- */
  .card-evolution{ grid-area: evolution; display:flex; flex-direction:column; }
  .evo-value{
    font-size: 30px; font-weight: 800; margin: 2px 0 12px;
  }
  .chart-wrap{ position: relative; height: 170px; }
  .chart-wrap.small{ height: 110px; }
  .card-evolution .btn{ margin-top: 14px; }

  /* ---------- VITALS ---------- */
  .card-vital{ display:flex; flex-direction: column; }
  .card-vital .chart-wrap{ margin: 8px 0 14px; }
  .trend{
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-mono);
  }
  .trend.up{ color: #d1663f; }
  .trend.down{ color: var(--teal-deep); }
  .trend.flat{ color: var(--ink-soft); }

  .glucose{ grid-area: glucose; }
  .bp{ grid-area: bp; }
  .hr{ grid-area: hr; }
  .oxi{ grid-area: oxi; display:flex; flex-direction:column; box-sizing:border-box; overflow:hidden; }
  .airways{ grid-area: airways; display:flex; flex-direction:column; box-sizing:border-box; overflow:hidden; }
  .meds{ grid-area: meds; display:flex; flex-direction:column; box-sizing:border-box; overflow:hidden; }
  .diag{ grid-area: diag; display:flex; flex-direction:column; box-sizing:border-box; overflow:hidden; }

  /* ---------- ICON ROW CARDS (oxi/airways/diag) ---------- */
  .icon-card-body{
    display:flex;
    align-items:center;
    gap: 20px;
    margin-top: 8px;
    min-width: 0;
    flex: 1;
    min-height: 0;
  }
  .icon-badge{
    width: 168px; height: 168px;
    flex-shrink:0;
    display:flex; align-items:center; justify-content:center;
  }
  .icon-badge svg{ width: 100%; height: 100%; }
  .icon-readout{ display:flex; flex-direction:column; gap: 4px; min-width: 0; overflow-wrap: break-word; }
  .icon-readout .big{
    font-size: 30px; font-weight: 800;
  }
  .icon-readout .big .unit{ font-size: 14px; color: var(--ink-soft); font-weight:700; margin-left:3px; }
  .status-pill{
    display:inline-flex; align-items:center; gap:6px;
    font-size: 13px; font-weight: 800;
    padding: 6px 12px;
    border-radius: 999px;
    width: fit-content;
  }
  .status-pill.ok{ background: var(--teal-soft); color: var(--teal-deep); }
  .status-pill.warn{ background: var(--purple-soft); color: var(--purple-deep); }
  .status-pill.alert{ background: rgba(242,169,59,.16); color: #a86616; }
  .status-pill .d{ width:6px; height:6px; border-radius:50%; background: currentColor; }

  /* ---------- MEDS ---------- */
  .vials{
    display:flex;
    justify-content: space-around;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    margin: 14px 0 6px;
  }
  .vial-col{ display:flex; flex-direction:column; align-items:center; gap:10px; height: 100%; }
  .vial{
    width: 38px;
    flex: 1;
    min-height: 0;
    border-radius: 19px;
    border: 2.5px solid #dfe4ea;
    position: relative;
    overflow: hidden;
    background: #fbfcfd;
  }
  .vial-fill{
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(180deg, var(--purple), var(--purple-deep));
    border-radius: 0 0 15px 15px;
    transition: height 1.2s cubic-bezier(.4,0,.2,1);
  }
  .vial.teal .vial-fill{ background: linear-gradient(180deg, var(--teal), var(--teal-deep)); }
  .vial-label{ font-size: 12px; font-family: var(--font-mono); color: var(--ink-soft); font-weight:700; }

  /* ---------- BODY MAP ---------- */
  .card-body{ grid-area: body; display:flex; flex-direction:column; align-items:center; justify-content:center; overflow: visible; }
  .body-wrap{
    position: relative;
    width: min(100%, 230px);
    aspect-ratio: 345.08 / 805.16;
    margin: 0 auto;
    cursor: crosshair;
  }
  .body-wrap svg{ display:block; width: 100%; height: 100%; }
  .marker{
    position:absolute;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: var(--purple);
    border: 3px solid #fff;
    box-shadow: 0 0 0 4px var(--purple-soft), 0 4px 10px -2px rgba(108,86,240,.5);
    transform: translate(-50%,-50%);
    cursor: pointer;
    animation: pulseDot 2.2s ease-in-out infinite;
  }
  .marker.teal{ background: var(--teal); box-shadow: 0 0 0 4px var(--teal-soft), 0 4px 10px -2px rgba(20,168,147,.5); }
  .add-marker-btn{
    position: absolute;
    top: 18px; right: 18px;
    width: 34px; height: 34px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-soft);
    font-size: 18px;
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    box-shadow: var(--shadow);
  }
  .add-marker-btn:hover{ color: var(--purple-deep); border-color: var(--purple); }
  .body-hint{
    font-size: 11.5px; color: var(--ink-soft); text-align:center; margin-top: 10px;
  }
  .toast{
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -16px);
    background: var(--ink);
    color: #fff;
    padding: 12px 20px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 14px 32px -10px rgba(0,0,0,.45);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
  }
  .toast.show{
    opacity: 1;
    transform: translate(-50%, 0);
  }
  .toast svg{ flex-shrink: 0; }

  .tooltip{
    position: absolute;
    background: var(--ink);
    color: #fff;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 12.5px;
    width: 160px;
    z-index: 20;
    pointer-events: none;
    box-shadow: 0 10px 24px -8px rgba(0,0,0,.4);
    opacity: 0;
    transition: opacity .15s ease;
  }
  .tooltip.show{ opacity: 1; pointer-events: auto; }
  .tooltip .del-btn{
    display:inline-block;
    margin-top: 8px;
    background: rgba(255,255,255,.15);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-body);
  }
  .tooltip .del-btn:hover{ background: rgba(255,255,255,.28); }
  .tooltip b{ display:block; margin-bottom: 3px; font-size: 12.5px; }

  /* ---------- MODAL ---------- */
  .modal-backdrop{
    position: fixed; inset: 0;
    background: rgba(15,20,28,.55);
    backdrop-filter: blur(3px);
    display:none;
    align-items:center; justify-content:center;
    z-index: 100;
    padding: 24px;
  }
  .modal-backdrop.open{ display:flex; }
  .modal{
    background: #fff;
    border-radius: 24px;
    max-width: 640px;
    width: 100%;
    padding: 28px;
    box-shadow: 0 30px 80px -20px rgba(0,0,0,.4);
    max-height: 86vh;
    overflow-y: auto;
  }
  .modal-head{
    display:flex; justify-content: space-between; align-items:flex-start;
    margin-bottom: 6px;
  }
  .modal-close{
    border:none; background: var(--bg); width: 32px; height:32px; border-radius:50%;
    cursor:pointer; font-size:16px; color: var(--ink-soft);
  }
  .modal .metric-value{ margin-bottom: 4px; }
  .modal-chart{ height: 260px; margin: 18px 0; }
  .modal-table{ width:100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
  .modal-table th{ text-align:left; color: var(--ink-soft); font-weight:700; padding: 6px 8px; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size:11.5px; text-transform:uppercase;}
  .modal-table td{ padding: 7px 8px; border-bottom: 1px solid var(--line); font-weight:600; }

  /* small popover for adding a marker */
  .marker-form{
    position:absolute;
    background:#fff;
    border-radius: 16px;
    box-shadow: 0 20px 48px -14px rgba(0,0,0,.35);
    padding: 14px;
    width: 220px;
    z-index: 30;
    display:none;
  }
  .marker-form.open{ display:block; }
  .marker-form input{
    width:100%; padding: 9px 10px; border-radius: 10px; border:1px solid var(--line);
    font-family: var(--font-body); font-size: 13px; margin-bottom: 8px; outline:none;
  }
  .marker-form input:focus{ border-color: var(--purple); }
  .marker-form-actions{ display:flex; gap:8px; }
  .marker-form-actions button{
    flex:1; padding: 8px; border-radius: 9px; border:none; font-weight:700; font-size:12.5px; cursor:pointer;
    text-transform: uppercase; letter-spacing: .03em;
  }
  .mf-save{ background: var(--teal-deep); color:#fff; }
  .mf-cancel{ background: var(--bg); color: var(--ink-soft); }

  footer{
    text-align:center;
    margin-top: 46px;
    color: var(--ink-soft);
    font-size: 12.5px;
    font-family: var(--font-mono);
  }
  footer a{ color: var(--purple-deep); text-decoration:none; font-weight:700; }

  @media (prefers-reduced-motion: reduce){
    .marker, .live-chip .d{ animation: none; }
  }