:root {
  --bg: #f0f2f5; --card: #ffffff; --text: #1c1e21; --muted: #65676b; --line: #e4e6eb;
  --hover: #f2f3f5; --primary: #4f46e5; --primary-2: #06b6d4; --primary-soft: #eef2ff;
  --danger: #e11d48; --danger-soft: #ffe4e6; --warn: #d97706; --warn-soft: #fef3c7;
  --ok: #059669; --ok-soft: #d1fae5; --shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
}
[data-theme="dark"] {
  --bg: #0f1117; --card: #1a1d27; --text: #e7e9ee; --muted: #9aa0ac; --line: #2a2e3b;
  --hover: #232734; --primary-soft: #1e1b4b; --danger-soft: #3b0d1a; --warn-soft: #3a2a07; --ok-soft: #062e22;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); transition: background .3s, color .3s; }
button { font: inherit; cursor: pointer; border: none; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* Navbar */
.navbar { position: sticky; top: 0; z-index: 50; height: 60px; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.logo { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 4px 14px rgba(79,70,229,.4); }
.brand-text { background: linear-gradient(90deg, var(--primary), var(--primary-2)); -webkit-background-clip: text; color: transparent; }
.search { position: relative; flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; background: var(--hover); border-radius: 999px; padding: 8px 14px; }
.search input { border: none; background: transparent; outline: none; width: 100%; }
.search-results { position: absolute; top: 46px; left: 0; right: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: none; }
.search-results.open { display: block; }
.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--hover); color: var(--text); font-size: 16px; transition: transform .15s, background .2s; }
.icon-btn:hover { transform: scale(1.08); background: var(--line); }
.doc-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: var(--hover); font-weight: 600; font-size: 14px; }

/* Avatars */
.avatar { border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; overflow: hidden; background-size: cover; background-position: center; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.md { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 120px; height: 120px; font-size: 42px; border: 5px solid var(--card); box-shadow: var(--shadow); }

/* Cards & generic */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.btn { padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; transition: filter .2s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary), #6366f1); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: var(--hover); color: var(--text); }
.btn-ghost:hover { background: var(--line); }
.muted { color: var(--muted); font-size: 13px; }
h3.section { font-size: 18px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.link { color: var(--primary); font-size: 13px; font-weight: 600; background: none; }

/* Home */
.home { max-width: 1100px; margin: 20px auto; display: grid; grid-template-columns: 320px 1fr; gap: 20px; padding: 0 16px; }
.patient-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; transition: background .2s; }
.patient-row:hover { background: var(--hover); }
.patient-row b { display: block; font-size: 14px; }
.hero { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; padding: 24px; border-radius: var(--radius); margin-bottom: 16px; }
.hero h1 { font-size: 26px; margin-bottom: 4px; }
.stats { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.stat { background: rgba(255,255,255,.18); padding: 10px 14px; border-radius: 10px; backdrop-filter: blur(6px); }
.stat b { font-size: 20px; display: block; }

/* Profile */
.cover { height: 150px; border-radius: 0 0 var(--radius) var(--radius); position: relative; max-width: 1100px; margin: 0 auto; background-size: cover; background-position: center; }
.profile-head { max-width: 1100px; margin: 0 auto; background: var(--card); box-shadow: var(--shadow); border-radius: 0 0 var(--radius) var(--radius); padding: 0 32px; }
.profile-top { display: flex; align-items: flex-end; gap: 20px; margin-top: -50px; padding-bottom: 16px; position: relative; flex-wrap: wrap; }
.profile-top .info { flex: 1; padding-bottom: 8px; min-width: 240px; }
.profile-top h1 { font-size: 28px; font-weight: 800; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.tabs { display: flex; gap: 4px; border-top: 1px solid var(--line); }
.tab { padding: 14px 16px; font-weight: 600; color: var(--muted); background: none; border-bottom: 3px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover:not(.active) { background: var(--hover); border-radius: 8px 8px 0 0; }
.profile-body { max-width: 1100px; margin: 16px auto; display: grid; grid-template-columns: 380px 1fr; gap: 16px; padding: 0 0 40px; }
.side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 76px; align-self: start; }
.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.list li .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--hover); flex-shrink: 0; }
.list li .x { margin-left: auto; background: none; color: var(--muted); opacity: 0; transition: opacity .2s; }
.list li:hover .x { opacity: 1; }
.allergy { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; margin: 0 6px 6px 0; }
.sev-severe { background: var(--danger-soft); color: var(--danger); }
.sev-moderate { background: var(--warn-soft); color: var(--warn); }
.sev-mild { background: var(--ok-soft); color: var(--ok); }
.alert-banner { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.vitals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vital { background: var(--hover); border-radius: 10px; padding: 10px; }
.vital b { display: block; font-size: 16px; }

/* Composer */
.feed { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.composer-top { display: flex; gap: 10px; align-items: center; }
.composer-input { flex: 1; text-align: left; background: var(--hover); color: var(--muted); padding: 11px 16px; border-radius: 999px; font-size: 15px; }
.composer-input:hover { background: var(--line); }
.composer-actions { display: flex; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; }
.composer-actions button { flex: 1; background: none; color: var(--muted); font-weight: 600; padding: 8px; border-radius: 8px; font-size: 14px; }
.composer-actions button:hover { background: var(--hover); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 13px; font-weight: 600; color: var(--muted); }
.chip.active { background: var(--primary); color: #fff; }

/* Post */
.post { padding: 0; overflow: hidden; }
.post-head { display: flex; gap: 10px; align-items: center; padding: 14px 16px 6px; }
.post-head b { font-size: 15px; }
.post-head .menu { margin-left: auto; background: none; color: var(--muted); font-size: 18px; width: 34px; height: 34px; border-radius: 50%; }
.post-head .menu:hover { background: var(--hover); }
.post-body { padding: 6px 16px 12px; font-size: 15px; line-height: 1.5; }
.dx { display: inline-block; margin: 6px 0; padding: 4px 10px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 14px; }
.kv { font-size: 14px; margin-top: 4px; }
.kv span { color: var(--muted); font-weight: 600; }
.vit-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.vit-row span { background: var(--hover); padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.photo-grid { display: grid; gap: 2px; }
.photo-grid.n1 { grid-template-columns: 1fr; }
.photo-grid.n2 { grid-template-columns: 1fr 1fr; }
.photo-grid.n3, .photo-grid.n4 { grid-template-columns: 1fr 1fr; }
.photo-grid img { width: 100%; height: 260px; object-fit: cover; cursor: zoom-in; display: block; transition: filter .2s; }
.photo-grid.n1 img { height: 400px; }
.photo-grid img:hover { filter: brightness(.9); }
.docs { display: flex; flex-direction: column; gap: 8px; padding: 10px 16px; }
.doc { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); transition: background .2s, transform .15s; cursor: pointer; }
.doc:hover { background: var(--hover); transform: translateX(2px); }
.doc .dic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; }
.doc b { font-size: 14px; display: block; }
.t-lab .dic { background: #e0f2fe; } .t-referral .dic { background: #fef3c7; } .t-prescription .dic { background: #dcfce7; } .t-photo .dic { background: #fce7f3; }
[data-theme="dark"] .doc .dic { background: var(--hover); }
.rx-card { margin: 10px 16px; border-radius: 12px; border: 1px dashed var(--ok); background: var(--ok-soft); padding: 12px 14px; }
.rx-card h4 { font-size: 14px; color: var(--ok); margin-bottom: 6px; display: flex; justify-content: space-between; }
.rx-card table { width: 100%; font-size: 13px; border-collapse: collapse; }
.rx-card td, .rx-card th { text-align: left; padding: 4px 6px; }
.rx-card th { color: var(--muted); font-weight: 600; }
.post-stats { display: flex; justify-content: space-between; padding: 8px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.post-actions { display: flex; border-top: 1px solid var(--line); margin: 0 16px; }
.post-actions button { flex: 1; background: none; color: var(--muted); padding: 8px; font-weight: 600; border-radius: 8px; margin: 4px 0; }
.post-actions button:hover { background: var(--hover); }
.comments { padding: 8px 16px 14px; display: flex; flex-direction: column; gap: 8px; }
.comment { display: flex; gap: 8px; }
.bubble { background: var(--hover); padding: 8px 12px; border-radius: 16px; font-size: 14px; }
.bubble b { font-size: 13px; display: block; }
.comment-input { flex: 1; background: var(--hover); border: none; border-radius: 999px; padding: 9px 14px; outline: none; }

/* Media grid tab */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.media-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; transition: transform .2s; }
.media-grid img:hover { transform: scale(1.03); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10,12,20,.55); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal-card { background: var(--card); width: 100%; max-width: 620px; max-height: 90vh; overflow: auto; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.modal-head { padding: 16px; border-bottom: 1px solid var(--line); text-align: center; font-weight: 700; font-size: 18px; position: relative; }
.modal-head .close { position: absolute; right: 12px; top: 10px; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); outline: none; transition: border .2s, box-shadow .2s; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.upload-zone { border: 2px dashed var(--line); border-radius: 12px; padding: 14px; }
.upload-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pending span { background: var(--hover); padding: 5px 10px; border-radius: 999px; font-size: 12px; }
.rx-line { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.rx-line input { padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }

/* Lightbox & toast */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 200; display: grid; place-items: center; cursor: zoom-out; animation: fade .2s; }
.lightbox img, .lightbox iframe { max-width: 92vw; max-height: 90vh; border-radius: 8px; }
.lightbox iframe { width: 80vw; height: 88vh; background: #fff; border: none; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px); background: #111827; color: #fff; padding: 12px 20px; border-radius: 10px; font-weight: 600; z-index: 300; transition: transform .3s; }
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .home, .profile-body { grid-template-columns: 1fr; padding: 0 10px; }
  .side { position: static; }
  .cover { height: 200px; border-radius: 0; }
  .profile-top { flex-direction: column; align-items: center; text-align: center; margin-top: -70px; }
  .avatar.xl { width: 140px; height: 140px; }
  .tags { justify-content: center; }
  .brand-text, .doc-chip span:last-child { display: none; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; }
}
