/* ======================================================
   LAYOUT.CSS — CLEAN GLOBAL BASE
   Version: 20260518-clean1
   Dublikatlar təmizləndi, mobil overflow qoruması əlavə edildi.
====================================================== */

/* ======================================================
   GLOBAL BASE
====================================================== */

:root{
  --bg:#f3f4f6;
  --card:#ffffff;
  --line:#d1d5db;
  --text:#111827;
  --muted:#6b7280;
  --primary:#2563eb;
  --primary-soft:#e8f0ff;
  --danger:#ef4444;
}

html,
body{
  margin:0;
  padding:0;
  width:100%;
  max-width:100%;
  overflow-x:hidden;
}

html{
  box-sizing:border-box;
}

*,
*::before,
*::after{
  box-sizing:inherit;
}

body{
  min-height:100vh;
  background:var(--bg);
  color:var(--text);
  font-family:Arial, Helvetica, sans-serif;
  font-size:14px;
}

body.menu-open{
  overflow:hidden;
}

/* ======================================================
   MODULE ROOTS
====================================================== */

#doctors,
#preparats,
#recipes,
#reports,
#tnplan,
#dailyplan,
#tnvisit,
#dualwork,
#tndashboard,
#mbgroupadmin,
#catalogadmin,
#users,
#audit{
  width:100%;
  max-width:100%;
  min-width:0;
  padding:0 8px 8px;
  overflow-x:hidden;
}

#doctors:focus{
  outline:none;
}

/* ======================================================
   GLOBAL UTILITIES
====================================================== */

#doctors *{
  user-select:none !important;
}

.autolist,
.autolist *{
  user-select:auto !important;
  pointer-events:auto !important;
}

.autolist{
  position:absolute;
  top:100%;
  left:0;
  width:100%;
  max-width:100%;
  background:#fff;
  border:1px solid #e4e6eb;
  border-radius:8px;
  max-height:240px;
  overflow:auto;
  z-index:99999;
  box-shadow:0 8px 24px rgba(0,0,0,.12);
}

.recipes-wrap,
.recipe-card{
  overflow:visible !important;
}

.recipe-form{
  position:relative;
  z-index:10;
}

/* ======================================================
   HEADER
====================================================== */

.top-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:6px 10px;
  background:#fff;
  border-bottom:1px solid #e5e7eb;
  position:sticky;
  top:0;
  z-index:200;
  max-width:100%;
}

.top-header-left{
  display:flex;
  align-items:center;
  gap:10px;
  min-width:0;
  flex:1;
  justify-content:flex-start;
}

.app-title{
  min-width:0;
  font-size:16px;
  font-weight:700;
  color:#1f2937;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  text-align:left;
}

.auth-panel{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
  justify-content:flex-end;
  min-width:0;
}

.auth-user{
  min-width:0;
  max-width:220px;
  color:#374151;
  font-size:14px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.auth-role{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:4px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:600;
  background:#eef2ff;
  color:#4f46e5;
  white-space:nowrap;
}

.auth-role.admin{
  background:#fee2e2;
  color:#ef4444;
}

/* ======================================================
   GLOBAL MODULE SCOPE
====================================================== */

#globalModuleScope{
  display:flex;
  align-items:center;
  margin-right:12px;
  min-width:0;
}

#globalModuleScope:empty{
  display:none;
}

.global-scope-box{
  display:flex;
  flex-direction:column;
  gap:4px;
  min-width:180px;
  max-width:100%;
}

.global-scope-box label{
  font-size:12px;
  line-height:1;
  color:#4b5563;
  margin:0;
}

.global-scope-box select,
.global-scope-box input{
  height:36px;
  min-width:180px;
  max-width:100%;
  padding:0 12px;
  border:1px solid #cfd8e3;
  border-radius:12px;
  background:#fff;
  font-size:14px;
  outline:none;
}

.global-scope-box.compact{
  min-width:auto;
}

.global-scope-box.compact label{
  display:none;
}

.global-scope-box.compact select,
.global-scope-box.compact input{
  min-width:170px;
}

/* ======================================================
   FORMS / BUTTONS
====================================================== */

button{
  border:1px solid #cfd6df;
  background:#fff;
  color:#111827;
  border-radius:12px;
  padding:8px 12px;
  font-size:14px;
  cursor:pointer;
  transition:.18s ease;
}

button:hover{
  background:#f8fafc;
}

button:disabled{
  opacity:.6;
  cursor:not-allowed;
}

input,
select,
textarea{
  max-width:100%;
  font-family:inherit;
}

input,
select{
  height:38px;
  border:1px solid #cfd6df;
  border-radius:12px;
  padding:0 12px;
  background:#fff;
  color:#111827;
  font-size:14px;
}

textarea{
  border:1px solid #cfd6df;
  border-radius:12px;
  padding:10px 12px;
  background:#fff;
  color:#111827;
  font-size:14px;
}

input:focus,
select:focus,
textarea:focus{
  outline:none;
  border-color:#93c5fd;
  box-shadow:0 0 0 3px rgba(37,99,235,.12);
}

/* ======================================================
   HAMBURGER BUTTON
====================================================== */

.hamburger-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:42px;
  height:42px;
  padding:0;
  border-radius:12px;
  border:1px solid #dbe3ef;
  background:#fff;
  font-size:22px;
  line-height:1;
  flex-shrink:0;
  margin:0;
}

.hamburger-btn:hover{
  background:#f3f6fb;
}

/* ======================================================
   OVERLAY + DRAWER MENU
====================================================== */

.tabs-overlay{
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.35);
  opacity:0;
  visibility:hidden;
  transition:.22s ease;
  z-index:998;
}

.tabs-overlay.open,
.tabs-overlay.show{
  opacity:1;
  visibility:visible;
  pointer-events:auto;
}

.tabs{
  margin:0;
}

.tabs-drawer{
  position:fixed;
  top:0;
  left:0;
  width:290px;
  max-width:86vw;
  height:100vh;
  height:100dvh;
  background:#fff;
  box-shadow:0 12px 40px rgba(15,23,42,.18);
  transform:translateX(-100%);
  transition:.25s ease;
  z-index:999;
  padding:16px 14px 24px;
  overflow-y:auto;
  overflow-x:hidden;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.tabs-drawer.open,
.tabs-drawer.show{
  transform:translateX(0);
}

.tabs-drawer .tab{
  width:100%;
  max-width:100%;
  text-align:left;
  padding:12px 14px;
  border-radius:12px;
  border:1px solid #d6dde7;
  background:#fff;
  font-size:14px;
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
}

.tabs-drawer .tab:hover{
  background:#f8fafc;
}

.tabs-drawer .tab.active{
  background:var(--primary-soft);
  color:var(--primary);
  border-color:#9bbcff;
  font-weight:700;
}

/* ======================================================
   TABLE / COMMON CONTENT
====================================================== */

table{
  width:100%;
  border-collapse:collapse;
  background:#fff;
  border-radius:14px;
  overflow:hidden;
}

thead{
  background:#f8fafc;
}

th{
  padding:10px 10px;
  font-size:12px;
  font-weight:700;
  text-transform:uppercase;
  color:#64748b;
  border-bottom:1px solid #e5e7eb;
  text-align:left;
}

td{
  padding:10px 10px;
  border-bottom:1px solid #eef2f7;
  color:#111827;
  font-size:14px;
}

tbody tr:hover{
  background:#f8fbff;
}

tr.active{
  background:#eaf1ff !important;
}

tr.archived{
  background:#f3f4f6 !important;
  color:#9ca3af;
}

tr.archived.active{
  background:#dbeafe !important;
  color:#374151;
}

td button{
  border:none;
  background:transparent;
  font-size:15px;
  padding:0 4px;
}

/* ======================================================
   PAGER
====================================================== */

#docPager{
  margin-top:4px;
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
}

/* ======================================================
   TEZLIK LAYOUT
====================================================== */

.tezlik-layout{
  display:flex;
  gap:40px;
  min-width:0;
}

.tezlik-filters{
  width:260px;
  min-width:0;
}

.tezlik-filters select{
  width:100%;
  margin-bottom:12px;
  height:36px;
  border-radius:8px;
}

.tezlik-list{
  flex:1;
  min-width:0;
}

.tezlik-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding:12px 0;
  border-bottom:1px solid #e5e7eb;
  min-width:0;
}

.tezlik-name{
  min-width:0;
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
}

.tezlik-ixt{
  color:#64748b;
  font-weight:400;
}

/* ======================================================
   QUOTA BUTTONS
====================================================== */

.quota-pill-group{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  min-width:0;
}

.quota-pill{
  padding:2px 6px;
  font-size:10.5px;
  border-radius:8px;
  border:1px solid #d1d5db;
  background:#fff;
  cursor:pointer;
}

.quota-pill.active{
  background:#1f7a7a;
  color:#fff;
  border-color:#1f7a7a;
}

/* ======================================================
   MOBILE RECIPE CARDS
====================================================== */

.recipe-card-item{
  background:#fff;
  border-radius:14px;
  padding:14px;
  border:1px solid #eef0f3;
  box-shadow:0 2px 8px rgba(0,0,0,.05);
}

.recipe-card-name{
  font-weight:600;
  font-size:15px;
}

.recipe-card-hospital{
  font-size:13px;
  color:#6b7280;
}

.recipe-card-owner{
  font-size:12px;
  color:#9aa3b2;
}

/* ======================================================
   SAVE INDICATOR
====================================================== */

.save-indicator{
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size:12px;
  opacity:0;
  transition:.25s;
}

.save-indicator.visible{
  opacity:1;
}

.save-dot{
  width:8px;
  height:8px;
  border-radius:50%;
}

.save-dot.saving{
  background:#2563eb;
}

.save-dot.saved{
  background:#16a34a;
}

.save-dot.error{
  background:#ef4444;
}

.save-dot.dirty{
  background:#f59e0b;
}

/* ======================================================
   TOAST
====================================================== */

.toast-container{
  position:fixed;
  top:20px;
  right:20px;
  display:flex;
  flex-direction:column;
  gap:10px;
  z-index:99999;
  max-width:calc(100vw - 40px);
}

.toast{
  min-width:220px;
  max-width:100%;
  padding:10px 14px;
  border-radius:12px;
  font-size:13px;
  color:#fff;
  box-shadow:0 8px 24px rgba(0,0,0,.12);
  opacity:0;
  transform:translateY(-10px);
  transition:.25s;
}

.toast.show{
  opacity:1;
  transform:translateY(0);
}

.toast.success{
  background:#16a34a;
}

.toast.error{
  background:#ef4444;
}

.toast.info{
  background:#2563eb;
}

.toast.warn{
  background:#f59e0b;
}

/* ======================================================
   GENERIC MODALS
   Qeyd: doctorModal və loginModal xüsusi dizaynları
   ayrı CSS fayllarında idarə olunur.
====================================================== */

.modal{
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.55);
  display:flex;
  align-items:center;
  justify-content:center;
  opacity:0;
  pointer-events:none;
  transition:.2s ease;
  z-index:9999;
}

.modal.show{
  opacity:1;
  pointer-events:auto;
}

.modal-box{
  width:88%;
  max-width:380px;
  background:#fff;
  border-radius:20px;
  box-shadow:0 25px 80px rgba(0,0,0,.25);
  overflow:hidden;
  border:1px solid #e5e7eb;
  transform:translateY(10px);
  transition:.2s ease;
}

.modal.show .modal-box{
  transform:translateY(0);
}

.modal-section{
  padding:10px 12px;
  border-bottom:1px solid #f1f3f7;
}

.modal-section:last-of-type{
  border-bottom:none;
}

.section-title{
  font-size:11px;
  margin-bottom:8px;
  letter-spacing:.05em;
  font-weight:600;
  color:#64748b;
  text-transform:uppercase;
}

.field-row{
  margin-bottom:8px;
}

.modal-actions{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  gap:12px;
  padding:10px 16px;
}

.modal-box h3{
  padding:10px 16px;
  margin:0;
  border-bottom:1px solid #eef2f7;
  font-size:16px;
}

.select-grid{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto auto auto;
  gap:6px;
  align-items:center;
}

.select-grid button{
  width:32px;
  height:32px;
  border-radius:8px;
  font-size:12px;
}

.select-row select{
  flex:1;
  height:36px;
  padding:0 12px;
  border-radius:12px;
}

.select-actions button{
  width:36px;
  height:36px;
  padding:0;
  border-radius:12px;
  display:flex;
  align-items:center;
  justify-content:center;
}

/* ======================================================
   RECIPE VIEW MODAL
====================================================== */

#recipeViewModal{
  display:flex;
  align-items:center;
  justify-content:center;
}

.recipe-box{
  width:92%;
  max-width:540px;
  background:#ffffff;
  border-radius:22px;
  box-shadow:0 30px 90px rgba(0,0,0,.28);
  border:1px solid #e5e7eb;
  overflow:hidden;
  padding:0;
}

.recipe-box h3{
  margin:0;
  padding:14px 20px;
  font-size:17px;
  font-weight:600;
  border-bottom:1px solid #eef2f7;
}

#recipeViewContent{
  padding:18px 20px;
  font-size:14px;
}

#recipeViewContent p{
  margin:6px 0;
}

#recipeViewModal table{
  width:100%;
  border-collapse:collapse;
  margin-top:14px;
}

#recipeViewModal th{
  background:#f8fafc;
  padding:8px 10px;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.05em;
  border-bottom:1px solid #e5e7eb;
  color:#64748b;
}

#recipeViewModal td{
  padding:8px 10px;
  border-bottom:1px solid #f1f5f9;
}

.recipe-box .modal-actions{
  padding:12px 20px;
  display:flex;
  justify-content:flex-end;
  border-top:1px solid #eef2f7;
  background:#fafbff;
}

/* ======================================================
   MISC
====================================================== */

.icon-btn{
  width:28px;
  height:28px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:8px;
  background:#f1f5ff;
  border:1px solid #e5e7eb;
  font-size:13px;
  transition:.15s ease;
}

.icon-btn:hover{
  background:#dbeafe;
  transform:translateY(-1px);
}

.icon-btn.danger{
  background:#fff0f0;
}

.icon-btn.danger:hover{
  background:#ffe5e5;
}

.icon-btn.view{
  background:#e8f1ff;
  border:none;
  padding:6px 8px;
  border-radius:6px;
  cursor:pointer;
}

.icon-btn.view:hover{
  background:#d6e6ff;
}

.prep-actions-head{
  width:120px;
  text-align:left;
  padding-left:12px;
}

.prep-actions{
  width:120px;
  text-align:left;
  padding-left:12px;
  white-space:nowrap;
}

.prep-actions button{
  margin-right:8px;
  padding:4px 6px;
}

.badge{
  padding:4px 8px;
  border-radius:12px;
  font-size:12px;
  background:#eee;
}

.badge.green{
  background:#d8f5e2;
  color:#1e7d3e;
}

.badge.red{
  background:#ffdede;
  color:#b50000;
}

.admin-badge{
  background:#ffe3b3;
  color:#8a5500;
}

#docTableWrap{
  max-width:100%;
}

#docTableWrap td{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

#reports .pagination{
  padding:10px 0;
}

.report-filters{
  background:#ffffff;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid #e5e7eb;
  margin-bottom:14px;
  box-shadow:0 4px 12px rgba(0,0,0,.04);
}

.filters-bar{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  align-items:center;
  margin-bottom:16px;
  padding-bottom:10px;
  border-bottom:1px solid #e5e7eb;
  min-width:0;
}

/* ======================================================
   LOGIN LOCK MODE
====================================================== */

body.locked-app #doctors,
body.locked-app #preparats,
body.locked-app #recipes,
body.locked-app #reports,
body.locked-app #users,
body.locked-app #audit,
body.locked-app #tnplan,
body.locked-app #dailyplan,
body.locked-app #tnvisit,
body.locked-app #dualwork,
body.locked-app #tndashboard,
body.locked-app #mbgroupadmin,
body.locked-app #catalogadmin{
  display:none !important;
}

/* ======================================================
   RESPONSIVE
====================================================== */

@media (max-width: 992px){
  .tezlik-layout{
    flex-direction:column;
    gap:20px;
  }

  .tezlik-filters{
    width:100%;
  }
}

@media (max-width: 900px){
  #docTableWrap,
  .recipes-wrap{
    max-width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
  }
}

@media (max-width: 768px){
  .autolist{
    position:fixed;
    left:0;
    right:0;
    bottom:0;
    top:40%;
    width:auto;
    max-width:none;
    border-radius:20px 20px 0 0;
    box-shadow:0 -10px 40px rgba(0,0,0,.2);
    max-height:60vh;
  }

  .mobile-select-bar{
    display:flex;
    gap:8px;
    margin-bottom:10px;
  }

  .mobile-select-bar button{
    flex:1;
  }
}

@media (max-width: 600px){
  #doctors,
  #preparats,
  #recipes,
  #reports,
  #tnplan,
  #dailyplan,
  #tnvisit,
  #dualwork,
  #tndashboard,
  #mbgroupadmin,
  #catalogadmin,
  #users,
  #audit{
    padding-left:6px;
    padding-right:6px;
  }

  .top-header{
    flex-direction:column;
    align-items:flex-start;
    gap:8px;
    overflow:hidden;
  }

  .top-header-left{
    width:100%;
  }

  .app-title{
    max-width:calc(100vw - 76px);
  }

  .auth-panel{
    width:100%;
    justify-content:space-between;
    flex-wrap:wrap;
  }

  .auth-user{
    max-width:100%;
  }

  #globalModuleScope{
    width:100%;
    margin-right:0;
  }

  .global-scope-box,
  .global-scope-box.compact{
    width:100%;
    min-width:0;
  }

  .global-scope-box select,
  .global-scope-box input,
  .global-scope-box.compact select,
  .global-scope-box.compact input{
    width:100%;
    min-width:0;
  }

  .modal{
    align-items:flex-end;
  }

  .modal-box{
    width:calc(100vw - 20px);
    max-width:calc(100vw - 20px);
  }

  .modal-actions{
    flex-direction:column-reverse;
  }

  .modal-actions button{
    width:100%;
  }

  input,
  select{
    font-size:16px;
  }

  .toast-container{
    left:12px;
    right:12px;
    top:12px;
    max-width:none;
  }

  .toast{
    min-width:0;
    width:100%;
  }

  .select-grid{
    grid-template-columns:minmax(0,1fr) 32px 32px 32px;
  }
}

@media (max-width: 380px){
  .hamburger-btn{
    width:38px;
    height:38px;
  }

  .tabs-drawer{
    width:280px;
    max-width:88vw;
    padding-left:12px;
    padding-right:12px;
  }

  .modal-box{
    width:calc(100vw - 12px);
    max-width:calc(100vw - 12px);
  }
}


/* ======================================================
   MOBILE HEADER — ADMIN + LOGOUT SAME ROW
   Version: 20260523-mobile-header-authline1
   Məqsəd: mobil versiyada ADMIN MODE və Çıxış MediTrack sətrinə qalxsın
====================================================== */

@media (max-width: 820px) {
  #topHeader.top-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-areas:
      "brand actions"
      "scope scope" !important;
    align-items: center !important;
    gap: 8px 10px !important;
    padding: 12px 14px 10px !important;
  }

  #topHeader .top-header-left {
    grid-area: brand !important;
    min-width: 0 !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
  }

  #topHeader .app-title {
    min-width: 0 !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /*
   * auth-panel-i vizual wrapper kimi ləğv edirik ki,
   * içindəki elementləri topHeader gridinə yerləşdirə bilək.
   */
  #topHeader .auth-panel {
    display: contents !important;
  }

  /*
   * TN/Admin seçimi ayrıca ikinci sətirdə tam en qalır.
   */
  #topHeader #globalModuleScope {
    grid-area: scope !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
  }

  #topHeader #globalModuleScope .global-scope-box,
  #topHeader #globalModuleScope select,
  #topHeader #globalModuleScope input {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /*
   * authInfo scope seçimi olanda onsuz da gizlənir;
   * mobil header-də boş yer yeməsin.
   */
  #topHeader #authInfo {
    display: none !important;
  }

  /*
   * ADMIN MODE və Çıxış MediTrack sətrinin sağına çıxır.
   */
  #topHeader #adminBadge,
  #topHeader #unlockBadge,
  #topHeader #btnLogout,
  #topHeader #btnLogin {
    grid-area: actions !important;
    align-self: center !important;
    justify-self: end !important;
  }

  #topHeader #btnLogout,
  #topHeader #btnLogin {
    position: relative !important;
    z-index: 3 !important;
    min-height: 40px !important;
    padding: 0 14px !important;
    white-space: nowrap !important;
  }

  #topHeader #adminBadge {
    position: relative !important;
    z-index: 2 !important;
    margin-right: 78px !important;
    white-space: nowrap !important;
  }

  #topHeader #unlockBadge {
    position: relative !important;
    z-index: 1 !important;
    margin-right: 180px !important;
    white-space: nowrap !important;
  }
}

@media (max-width: 420px) {
  #topHeader.top-header {
    padding-left: 10px !important;
    padding-right: 10px !important;
    gap: 7px 8px !important;
  }

  #topHeader .top-header-left {
    gap: 9px !important;
  }

  #topHeader #adminBadge {
    margin-right: 70px !important;
    font-size: 11px !important;
    padding-left: 9px !important;
    padding-right: 9px !important;
  }

  #topHeader #btnLogout,
  #topHeader #btnLogin {
    min-height: 38px !important;
    padding: 0 12px !important;
    font-size: 14px !important;
  }
}