/* DMED LOR Xirurgiya — Design Tokens & Components */
:root {
  --blue: #2563EB;
  --blue-600: #1D4ED8;
  --blue-700: #1E40AF;
  --blue-50: #EFF6FF;
  --blue-100: #DBEAFE;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --line: #E2E8F0;
  --line-2: #CBD5E1;
  --ink: #0F172A;
  --ink-2: #475569;
  --ink-3: #94A3B8;
  --green: #10B981;
  --green-50: #ECFDF5;
  --green-600: #059669;
  --orange: #F59E0B;
  --orange-50: #FFFBEB;
  --red: #EF4444;
  --red-50: #FEF2F2;
  --purple: #8B5CF6;
  --purple-50: #F5F3FF;
  --grey-50: #F1F5F9;
  --r: 10px;
  --r-sm: 6px;
  --side: 250px;
  --top: 56px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--ink); }
.mut { color: var(--ink-2); }
.sm { font-size: 12px; }
.xs { font-size: 11px; }
.nw { white-space: nowrap; }
.r { text-align: right; }
.b { font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.sp { justify-content: space-between; }

/* ---------- SHELL ARCHITECTURE ---------- */
.dmed-shell { display: flex; min-height: 100vh; width: 100%; }
.dmed-sidebar {
  width: var(--side);
  flex: 0 0 var(--side);
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.sidebar-backdrop { display: none; }
.dmed-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.dmed-topbar {
  flex: 0 0 auto;
  margin: 10px 14px 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--top);
  box-shadow: var(--shadow);
}
.dmed-workspace { flex: 1 1 auto; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }

/* ---------- SIDEBAR & BRAND ---------- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  font-weight: 800;
  font-size: 17px;
  color: var(--blue);
  border-bottom: 1px solid var(--line);
}
.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--blue-50);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.logo small { display: block; font-size: 10px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; }
.nav { padding: 10px 8px; flex: 1 1 auto; overflow-y: auto; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.15s ease;
}
.nav a:hover { background: var(--grey-50); color: var(--blue); }
.nav a.on { color: var(--blue); background: var(--blue-50); font-weight: 700; }
.nav a .ico { font-size: 16px; width: 22px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--blue-100);
  color: var(--blue-700);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}
.side-foot {
  padding: 12px 16px;
  font-size: 11px;
  color: var(--ink-3);
  border-top: 1px solid var(--line);
  background: #FAFBFD;
}

/* ---------- TOPBAR ELEMENTS ---------- */
.burger {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 16px;
}
.tb-title { font-weight: 700; font-size: 14px; color: var(--ink); }
.pii-shield-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-50);
  color: var(--green-600);
  border: 1px solid #A7F3D0;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 600;
  font-size: 11px;
}
.who { margin-left: auto; text-align: right; line-height: 1.25; }
.who b { display: block; font-size: 12px; }
.who span { font-size: 11px; color: var(--ink-2); }
.lang-btn {
  background: var(--grey-50);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  font-weight: 600;
  font-size: 11px;
  cursor: pointer;
}

/* ---------- CARDS & UI CONTAINERS ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-h {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.card-h h3 { font-size: 14px; font-weight: 700; }
.card-b { padding: 14px 16px; }

/* ---------- BUTTONS & FORMS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--blue-600); }
.btn.o { background: #fff; color: var(--blue-600); border-color: var(--blue-100); }
.btn.o:hover { background: var(--blue-50); }
.btn.g { background: #fff; color: var(--ink); border-color: var(--line-2); }
.btn.g:hover { background: var(--grey-50); }
.btn.d { background: #fff; color: var(--red); border-color: #FECACA; }
.btn.d:hover { background: var(--red-50); }
.btn.success { background: var(--green); color: #fff; }
.btn.success:hover { background: var(--green-600); }
.btn.xs { padding: 4px 8px; font-size: 11px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.inp, select.inp, textarea.inp {
  width: 100%;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  background: #fff;
  outline: none;
  min-height: 36px;
}
.inp:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
textarea.inp { min-height: 75px; resize: vertical; line-height: 1.5; }
.fld { display: block; margin-bottom: 12px; }
.fl { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-weight: 500; }
.fl i { color: var(--red); font-style: normal; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- TABLES ---------- */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { background: #F8FAFC; padding: 10px 12px; text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.t tr:hover td { background: #F8FAFC; }

/* ---------- BADGES & CHIPS ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.blue { background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-100); }
.badge.green { background: var(--green-50); color: var(--green-600); border: 1px solid #A7F3D0; }
.badge.orange { background: var(--orange-50); color: var(--orange); border: 1px solid #FDE68A; }
.badge.purple { background: var(--purple-50); color: var(--purple); border: 1px solid #DDD6FE; }

/* ---------- NOTICE BANNERS ---------- */
.banner { border-radius: var(--r-sm); padding: 10px 14px; font-size: 12.5px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.banner.shield { background: #ECFDF5; border: 1px solid #A7F3D0; color: #065F46; }
.banner.info { background: var(--blue-50); border: 1px solid var(--blue-100); color: #1E40AF; }

/* ---------- 4-STAGE MEDICAL DOCUMENT VIEWER ---------- */
.doc-tabs { display: flex; border-bottom: 2px solid var(--line); gap: 4px; overflow-x: auto; margin-bottom: 14px; }
.doc-tab {
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.doc-tab:hover { color: var(--blue); }
.doc-tab.on { color: var(--blue); border-bottom-color: var(--blue); }
.doc-sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  font-family: Georgia, serif, var(--font);
  line-height: 1.6;
}
.doc-header-official {
  text-align: center;
  border-bottom: 2px solid #000;
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.doc-header-official h2 { font-size: 16px; text-transform: uppercase; margin-bottom: 4px; font-family: var(--font); }
.doc-header-official p { margin: 2px 0; font-size: 12px; }
.doc-section { margin-bottom: 16px; }
.doc-section-title { font-weight: 700; font-size: 14px; border-bottom: 1px dashed var(--line-2); padding-bottom: 4px; margin-bottom: 8px; font-family: var(--font); color: var(--blue-700); }
.doc-content-editable {
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  min-height: 40px;
  outline: none;
  transition: all 0.15s;
}
.doc-content-editable:hover { border-color: var(--line-2); background: #FAFBFD; }
.doc-content-editable:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1); }
.doc-signature-box { display: flex; justify-content: space-between; margin-top: 30px; padding-top: 16px; border-top: 1px solid var(--line-2); font-family: var(--font); font-size: 13px; }

/* ---------- ENT EXAMINATION DIAGRAM BUILDER ---------- */
.ent-diagram-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 16px; }
.ent-box { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; background: #fff; }
.ent-box-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.ent-quick-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ent-tag { background: var(--grey-50); border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; font-size: 11px; cursor: pointer; }
.ent-tag:hover { background: var(--blue-50); border-color: var(--blue-100); color: var(--blue); }

/* ---------- WARDS & BED BOARD ---------- */
.wards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.ward-card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; background: #fff; }
.ward-title { font-weight: 700; font-size: 13px; margin-bottom: 10px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.bed-slot { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 6px; font-size: 11.5px; }
.bed-slot.empty { background: var(--green-50); border-color: #A7F3D0; color: #065F46; }
.bed-slot.occupied { background: var(--blue-50); border-color: var(--blue-100); color: #1E40AF; }

/* ---------- MODAL & TOASTS ---------- */
#modal-layer { display: none; }
#modal-layer.on {
  display: flex;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 14px;
  overflow-y: auto;
}
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 680px; }
.modal.wide { max-width: 900px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 15px; }
.modal-b { padding: 16px 18px; }
.modal-f { display: flex; gap: 8px; justify-content: flex-end; padding-top: 14px; border-top: 1px solid var(--line); margin-top: 14px; }
.x-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink-3); }

#toasts { position: fixed; top: 16px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, 92vw); }
.toast { background: #fff; border-left: 4px solid var(--green); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 10px 14px; font-size: 12.5px; animation: pop 0.2s ease-out; }
.toast.err { border-color: var(--red); }
.toast.info { border-color: var(--blue); }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- MOBILE RESPONSIVE (<1024px) ---------- */
.mobile-bottom-nav { display: none; }

@media (max-width: 1023px) {
  .dmed-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 270px;
    z-index: 1050;
    transform: translateX(-105%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .dmed-sidebar.open { transform: translateX(0); box-shadow: 0 20px 50px rgba(15, 23, 42, 0.4); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 1040; }
  .sidebar-backdrop.open { display: block; }
  .burger { display: inline-flex; }
  .dmed-main { width: 100%; padding-bottom: 70px; }
  
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 62px;
    background: #fff;
    border-top: 1px solid var(--line);
    justify-content: space-around;
    align-items: center;
    z-index: 950;
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: content-box;
  }
  .mobile-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--ink-2);
    padding: 6px 0;
    min-width: 0;
    cursor: pointer;
  }
  .mobile-bottom-nav a .ico { font-size: 18px; line-height: 1; }
  .mobile-bottom-nav a.on { color: var(--blue); font-weight: 700; }

  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .dmed-topbar { margin: 6px 8px 0; padding: 6px 10px; }
  .dmed-workspace { padding: 8px; }
  .doc-sheet { padding: 14px; }
}

/* ---------- PRINT STYLESHEET (OFFICIAL A4 CLINICAL FORMS) ---------- */
@media print {
  body { background: #fff; font-size: 12pt; color: #000; }
  .dmed-sidebar, .dmed-topbar, .mobile-bottom-nav, #toasts, .btn, .doc-tabs, .banner { display: none !important; }
  .dmed-shell, .dmed-main, .dmed-workspace { padding: 0 !important; margin: 0 !important; width: 100% !important; }
  .card, .doc-sheet { border: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; }
  .doc-section { page-break-inside: avoid; }
  .page-break { page-break-after: always; }
}
