:root{
    --primary:#0f766e;
    --primary-dark:#115e59;
    --bg:#f4f7fb;
    --sidebar:#0f172a;
    --sidebar-2:#111827;
    --text:#111827;
    --muted:#64748b;
    --card:#ffffff;
    --border:#e5e7eb;
}
*{box-sizing:border-box}
body{font-family:"Tahoma","Arial",sans-serif;background:var(--bg);color:var(--text);margin:0;font-size:15px}
a{text-decoration:none}.app-shell{display:flex;min-height:100vh}.app-sidebar{width:285px;background:linear-gradient(180deg,var(--sidebar),var(--sidebar-2));color:#fff;position:fixed;right:0;top:0;bottom:0;z-index:1030;display:flex;flex-direction:column;padding:18px 14px;box-shadow:-12px 0 30px rgba(15,23,42,.08)}
.brand-box{display:flex;gap:12px;align-items:center;padding:10px 8px 20px;border-bottom:1px solid rgba(255,255,255,.1);margin-bottom:14px}.brand-icon{width:46px;height:46px;border-radius:16px;background:#14b8a6;display:grid;place-items:center;font-size:22px}.brand-title{font-weight:800;font-size:18px}.brand-subtitle{font-size:12px;color:#cbd5e1}.sidebar-nav{display:flex;flex-direction:column;gap:6px;overflow-y:auto;padding-left:4px}.sidebar-nav .nav-link{color:#dbeafe;border-radius:14px;padding:11px 12px;display:flex;gap:10px;align-items:center;font-weight:700}.sidebar-nav .nav-link i{width:22px;text-align:center}.sidebar-nav .nav-link:hover,.sidebar-nav .nav-link.active{background:rgba(20,184,166,.18);color:#fff}.sidebar-footer{margin-top:auto;padding-top:12px;border-top:1px solid rgba(255,255,255,.1)}
.app-main{margin-right:285px;flex:1;min-width:0}.topbar{background:#fff;border-bottom:1px solid var(--border);padding:18px 24px;position:sticky;top:0;z-index:1010}.content-wrap{padding:22px 24px}.card{border:0;border-radius:20px;box-shadow:0 10px 24px rgba(15,23,42,.06)}.card-header{background:#fff;border-bottom:1px solid var(--border);border-radius:20px 20px 0 0!important;font-weight:800}.form-control,.form-select{border-radius:12px;padding:.7rem .9rem;border-color:#d7dee8}.btn{border-radius:12px;font-weight:700}.btn-primary{background:var(--primary);border-color:var(--primary)}.btn-primary:hover{background:var(--primary-dark);border-color:var(--primary-dark)}.table{vertical-align:middle}.table th{white-space:nowrap;color:#334155;background:#f8fafc}.badge{font-size:.8rem;padding:.45em .7em;border-radius:999px}.stat-card{border-radius:22px;background:#fff;padding:20px;box-shadow:0 10px 24px rgba(15,23,42,.06);height:100%}.stat-icon{width:48px;height:48px;border-radius:16px;background:#ecfeff;color:var(--primary);display:grid;place-items:center;font-size:22px}.stat-number{font-size:30px;font-weight:900;line-height:1}.stat-label{color:var(--muted);font-weight:700}.action-bar{display:flex;gap:8px;flex-wrap:wrap}.required:after{content:" *";color:#dc2626}.login-body{min-height:100vh;display:grid;place-items:center;background:linear-gradient(135deg,#ecfeff,#eff6ff)}.login-card{width:min(430px,92vw);background:#fff;border-radius:28px;padding:30px}.login-icon{width:72px;height:72px;border-radius:24px;background:var(--primary);color:#fff;display:grid;place-items:center;margin:auto;font-size:34px}.search-result-box{border:1px solid var(--border);border-radius:18px;background:#fff;padding:18px}.quota-row{background:#f8fafc;border:1px solid #e5e7eb;border-radius:16px;padding:12px;margin-bottom:10px}.print-only{display:none}.alert-big{font-size:18px;font-weight:800;border-radius:18px;padding:18px}.table-responsive{border-radius:18px}.sidebar-backdrop{display:none}
@media(max-width:991.98px){.app-sidebar{transform:translateX(105%);transition:.22s ease}.app-sidebar.show{transform:translateX(0)}.sidebar-backdrop.show{display:block;position:fixed;inset:0;background:rgba(15,23,42,.4);z-index:1020}.app-main{margin-right:0}.topbar{padding:14px}.content-wrap{padding:14px}.table{font-size:14px}.action-bar .btn{width:100%}}
@media print{.app-sidebar,.topbar,.no-print,.sidebar-backdrop{display:none!important}.app-main{margin:0!important}.content-wrap{padding:0}.card{box-shadow:none;border:1px solid #ddd}.print-only{display:block}body{background:#fff}}

/* v7 mobile/app refinements */
.no-scroll{overflow:hidden}.app-sidebar,.app-main{transition:transform .22s ease, margin .22s ease}.sidebar-collapsed .app-sidebar{transform:translateX(105%)}.sidebar-collapsed .app-main{margin-right:0}.topbar .btn{min-height:42px}.modal-content{border:0;border-radius:22px}.modal-header,.modal-footer{border-color:#eef2f7}.modal-body{max-height:calc(100vh - 190px);overflow:auto}.public-body{background:var(--bg)}
@media(max-width:991.98px){
    body{font-size:15px;background:#f7fafc}.app-shell{display:block}.app-sidebar{width:min(86vw,320px);padding-bottom:calc(18px + env(safe-area-inset-bottom));box-shadow:-18px 0 38px rgba(15,23,42,.18)}.brand-title{font-size:17px}.sidebar-nav .nav-link{padding:13px 12px}.app-main{margin-right:0!important}.topbar{border-radius:0 0 20px 20px;box-shadow:0 8px 22px rgba(15,23,42,.06);gap:10px}.topbar h1{font-size:18px}.content-wrap{padding:14px 10px 90px}.card,.stat-card{border-radius:18px}.stat-card{padding:16px}.stat-number{font-size:24px}.btn{min-height:42px}.form-control,.form-select{min-height:44px}.modal-dialog{margin:10px}.modal-body{max-height:calc(100vh - 155px)}.action-bar{width:100%}.action-bar .btn,.action-bar form,.action-bar form .btn{width:100%}
    .responsive-table thead{display:none}.responsive-table tbody,.responsive-table tr,.responsive-table td{display:block;width:100%}.responsive-table tr{background:#fff;border:1px solid #e5e7eb;border-radius:16px;margin:10px;padding:10px;box-shadow:0 8px 18px rgba(15,23,42,.04)}.responsive-table td{border:0!important;padding:8px 4px!important;display:flex;justify-content:space-between;gap:12px;text-align:left}.responsive-table td::before{content:attr(data-label);font-weight:800;color:#475569;text-align:right}.responsive-table td[colspan]::before{content:''}.table-responsive{overflow:visible}.quota-row{padding:12px;border-radius:14px}.quota-row .col-md-1 .btn{margin-top:4px}
}
@media(min-width:992px){.sidebar-collapsed .sidebar-backdrop{display:none!important}}

/* v8: cleaner admin navigation, mobile app feeling, full-screen modals on phones */
.mobile-bottom-nav{display:none}
.setting-tile{display:flex;align-items:center;gap:14px;border:1px solid var(--border);border-radius:18px;background:#fff;padding:16px;height:100%;transition:.15s ease}.setting-tile:hover{transform:translateY(-2px);box-shadow:0 10px 22px rgba(15,23,42,.06)}.setting-tile .tile-icon{width:46px;height:46px;border-radius:16px;background:#ecfeff;color:var(--primary);display:grid;place-items:center;font-size:22px}.setting-tile .tile-title{font-weight:900;color:#0f172a}.setting-tile .tile-desc{font-size:13px;color:var(--muted)}.patient-profile-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.profile-field{border:1px solid var(--border);border-radius:14px;padding:12px;background:#fff}.profile-field .label{color:var(--muted);font-size:13px;font-weight:700}.profile-field .value{font-weight:900;margin-top:4px}.import-date-box{font-size:13px;line-height:1.6}.import-date-box strong{display:block}.modal-step-title{font-weight:900;color:#0f766e;margin-bottom:12px}.btn-floating-add{box-shadow:0 8px 18px rgba(15,118,110,.18)}
@media(max-width:991.98px){
    .mobile-bottom-nav{display:grid;grid-template-columns:repeat(4,1fr);position:fixed;left:10px;right:10px;bottom:10px;z-index:1025;background:#fff;border:1px solid #e5e7eb;border-radius:24px;box-shadow:0 14px 34px rgba(15,23,42,.16);padding:7px calc(6px + env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left));gap:4px}.mobile-bottom-nav a{display:flex;flex-direction:column;align-items:center;justify-content:center;color:#334155;font-weight:800;font-size:11px;min-height:54px;border-radius:18px}.mobile-bottom-nav a:hover{background:#ecfeff;color:#0f766e}.mobile-bottom-nav i{font-size:20px;margin-bottom:2px}.content-wrap{padding-bottom:105px}.patient-profile-grid{grid-template-columns:1fr}.modal-full-mobile .modal-dialog{margin:0;max-width:100%;height:100%}.modal-full-mobile .modal-content{min-height:100vh;border-radius:0}.modal-full-mobile .modal-body{max-height:none;overflow:visible;padding-bottom:110px}.modal-full-mobile .modal-footer{position:sticky;bottom:0;background:#fff;box-shadow:0 -8px 20px rgba(15,23,42,.06)}.modal-step{border:1px solid var(--border);border-radius:18px;padding:14px;background:#fff;margin-bottom:12px}.setting-tile{padding:14px}.topbar .text-muted{display:none}
}

/* v9: desktop layout rollback + professional responsive fixes */
html,body{min-width:0;overflow-x:hidden}.app-main{width:calc(100% - 285px)}.content-wrap{max-width:1680px;margin:0 auto;width:100%}.topbar{display:flex!important;gap:14px}.topbar>div:nth-child(2){flex:1;text-align:right;min-width:0}.topbar>div:last-child{text-align:left;white-space:nowrap}.topbar h1{font-weight:900;color:#0f172a}.row{align-items:stretch}.card,.stat-card{overflow:hidden}.card-body{line-height:1.75}.card-header{font-size:1rem;color:#0f172a}.stat-card{display:flex;flex-direction:column;justify-content:center;min-height:104px}.stat-number.fs-6{font-size:1.08rem!important;line-height:1.55;word-break:break-word}.table-responsive{width:100%;overflow-x:auto;background:#fff}.table{min-width:720px}.table-sm{min-width:520px}.table td,.table th{vertical-align:middle}.patient-summary .card-body strong{font-size:1.02rem;color:#111827}.profile-field,.card .text-muted+strong{word-break:break-word}.modal-content{box-shadow:0 18px 48px rgba(15,23,42,.18)}.btn{white-space:normal}.sidebar-nav .nav-link{min-height:44px}.sidebar-nav .nav-link.active{box-shadow:inset 4px 0 0 rgba(20,184,166,.75)}
@media(min-width:992px){
  .app-sidebar{transform:none}.sidebar-collapsed .app-sidebar{transform:translateX(105%)}.sidebar-collapsed .app-main{width:100%;margin-right:0}.content-wrap{padding:24px 28px}.topbar{padding:18px 28px}.modal-xl{max-width:min(1120px,calc(100vw - 80px))}.card-body{padding:1.1rem 1.15rem}.patient-view-grid>.col-lg-5{width:38%}.patient-view-grid>.col-lg-7{width:62%}
}
@media(max-width:991.98px){
  .app-main{width:100%;margin-right:0!important}.topbar{justify-content:flex-start!important;align-items:center!important}.topbar>div:nth-child(2){text-align:right}.topbar h1{font-size:18px!important}.content-wrap{max-width:none;padding:14px 10px 105px}.card-body{padding:14px}.row{--bs-gutter-x:.9rem;--bs-gutter-y:.9rem}.stat-card{min-height:88px}.table{min-width:0}.responsive-table{min-width:0}.responsive-table tr.collapse.show{display:block}.responsive-table tr.collapse td{display:block!important}.responsive-table tr.collapse td::before{content:''!important}.patient-view-grid{display:block}.modal-content{border-radius:20px}.brand-box{padding-bottom:14px}.sidebar-nav .nav-link{font-size:15px}.action-bar{gap:8px}.action-bar .btn{justify-content:center}.form-control,.form-select{font-size:16px}
}
@media(max-width:575.98px){
  body{font-size:14px}.topbar{padding:12px 10px}.content-wrap{padding-left:8px;padding-right:8px}.card,.stat-card{border-radius:16px}.card-header{padding:12px 14px}.stat-number{font-size:22px}.stat-label{font-size:13px}.mobile-bottom-nav{left:8px;right:8px;bottom:8px}.modal-full-mobile .modal-dialog{margin:0!important;max-width:100%!important}.modal-full-mobile .modal-content{border-radius:0!important}.patient-profile-grid{grid-template-columns:1fr!important}
}

/* v10: professional layout stability, PWA/mobile navigation, reports polish */
:root{--content-max:1740px}
body{line-height:1.65}
.app-main{overflow:hidden}.content-wrap{max-width:var(--content-max)}
.topbar{min-height:78px}.topbar h1{letter-spacing:-.2px}.page-return-bar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:14px;background:#fff;border:1px solid var(--border);border-radius:16px;padding:10px;box-shadow:0 8px 20px rgba(15,23,42,.04)}
.report-toolbar{background:#fff;border:1px solid var(--border);border-radius:22px;padding:18px;box-shadow:0 10px 24px rgba(15,23,42,.06)}
.report-title-row{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;margin:4px 0 16px}.report-title-row h2{font-weight:900;color:#0f172a}.report-actions{display:flex;gap:8px;flex-wrap:wrap}.report-kpis .stat-card{position:relative;border:1px solid #eef2f7}.report-kpis .stat-card::before{content:'';position:absolute;inset-inline-start:0;top:18px;bottom:18px;width:4px;border-radius:999px;background:var(--primary)}.report-section-card .card-header{display:flex;align-items:center;justify-content:space-between;gap:8px}.report-section-card .table{min-width:0;margin:0}.report-section-card .table td,.report-section-card .table th{white-space:normal;word-break:break-word}.report-medicine-table td:first-child,.report-medicine-table th:first-child{min-width:220px}.report-details-table{min-width:820px}.table-scroll-x{overflow-x:auto;-webkit-overflow-scrolling:touch;width:100%}.table-scroll-x .table{margin-bottom:0}.table-compact{min-width:0}.table-compact td,.table-compact th{padding:.7rem .85rem}.badge-soft{background:#ecfeff;color:#0f766e;border:1px solid #ccfbf1;border-radius:999px;padding:.4rem .65rem;font-weight:900}.app-sidebar{will-change:transform}.mobile-bottom-nav a.active{background:#ecfeff;color:#0f766e}.pwa-hint{display:none}.settings-back-hint{color:var(--muted);font-size:13px}
@media(min-width:992px){.report-filter-month{max-width:220px}.report-filter-year{max-width:220px}.report-filter-hospital{min-width:340px}.report-toolbar .btn{min-height:46px}.report-section-card{min-height:100%}.sidebar-collapsed .content-wrap{max-width:1500px}.sidebar-collapsed .app-main{overflow:visible}}
@media(max-width:991.98px){.topbar{min-height:68px}.page-return-bar{position:sticky;top:78px;z-index:1005}.report-toolbar{padding:14px;border-radius:18px}.report-actions{width:100%}.report-actions .btn{flex:1 1 140px}.report-title-row{align-items:flex-start}.report-kpis .stat-card::before{top:14px;bottom:14px}.report-section-card .card-body.p-0{overflow:hidden}.table-scroll-x{border-radius:0 0 18px 18px}.pwa-hint{display:block}.settings-back-hint{display:block}.topbar .btn#sidebarToggle{min-width:44px}.mobile-bottom-nav a{font-size:10.5px}}
@media(max-width:575.98px){.report-toolbar .row>[class*="col-"]{width:100%}.report-title-row h2{font-size:1.05rem}.report-actions .btn{width:100%;flex:auto}.table-compact td,.table-compact th{padding:.6rem .7rem}.page-return-bar .btn{width:100%}}
@media print{.report-toolbar,.report-actions,.page-return-bar,.mobile-bottom-nav{display:none!important}.report-details-table,.report-section-card .table{min-width:0!important}.report-section-card{break-inside:avoid}.content-wrap{max-width:none!important}}


/* v11: no unnecessary horizontal scrolling + restored medicine identity */
.brand-icon,.login-icon{background:linear-gradient(135deg,#0f766e,#14b8a6)!important;overflow:hidden}
.brand-icon svg,.login-icon svg{display:block;width:72%;height:72%}.login-icon svg{width:62%;height:62%}
/* Use real space before resorting to horizontal scroll. Wide tables must wrap instead of pushing the page. */
.table{width:100%;min-width:0!important;max-width:100%;table-layout:auto}
.table th,.table td{white-space:normal;overflow-wrap:anywhere;word-break:normal;vertical-align:middle}
.table-responsive,.table-scroll-x{max-width:100%;overflow-x:visible!important;-webkit-overflow-scrolling:auto}
.table-scroll-x{border-radius:0 0 18px 18px}
.report-section-card{overflow:hidden}.report-section-card .card-body{overflow:hidden}.report-section-card .table{min-width:0!important}.report-details-table{min-width:0!important}.report-medicine-table td:first-child,.report-medicine-table th:first-child{min-width:0!important;width:48%}.report-medicine-table td:nth-child(2),.report-medicine-table th:nth-child(2){width:28%;text-align:center}.report-medicine-table td:nth-child(3),.report-medicine-table th:nth-child(3){width:24%;text-align:center}.report-details-table th,.report-details-table td{font-size:14px}.nowrap-soft{white-space:nowrap}
/* In rare truly-wide tables, add .allow-horizontal-scroll explicitly. */
.allow-horizontal-scroll{overflow-x:auto!important;-webkit-overflow-scrolling:touch}.allow-horizontal-scroll .table{min-width:850px!important}
@media(max-width:991.98px){
  .table-responsive,.table-scroll-x{overflow-x:visible!important}.report-section-card .table thead{display:none}.report-section-card .table tbody,.report-section-card .table tr,.report-section-card .table td{display:block;width:100%!important}.report-section-card .table tr{background:#fff;border:1px solid #e5e7eb;border-radius:16px;margin:10px;padding:10px;box-shadow:0 8px 18px rgba(15,23,42,.04)}.report-section-card .table td{border:0!important;padding:7px 4px!important;display:flex;justify-content:space-between;gap:12px;text-align:left}.report-section-card .table td::before{content:attr(data-label);font-weight:800;color:#475569;text-align:right;min-width:90px}.report-section-card .table td[colspan]{display:block;text-align:center}.report-section-card .table td[colspan]::before{content:''}.report-details-table th,.report-details-table td{font-size:14px}
}
@media(max-width:575.98px){.report-medicine-table td:nth-child(2),.report-medicine-table td:nth-child(3){text-align:left}.topbar h1{max-width:72vw;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}}


/* v12: mobile-first table/cards cleanup
   Do not squeeze table columns on phones. Convert regular data tables into readable cards. */
:root{--mobile-card-gap:10px}
.card .table td,.card .table th,.public-card .table td,.public-card .table th{line-height:1.65}
.table td .btn,.table td button.btn{min-width:74px}
.public-body{background:var(--bg);overflow-x:hidden}.public-body .navbar{box-shadow:0 6px 18px rgba(15,23,42,.05)}.public-body main{max-width:1500px;margin-inline:auto}.public-body .public-card{border:0;border-radius:22px;box-shadow:0 10px 24px rgba(15,23,42,.06);overflow:hidden;background:#fff}.public-body .public-card .card-header{border-radius:22px 22px 0 0!important}.public-body .table{table-layout:auto}.public-body .table td,.public-body .table th{word-break:normal;overflow-wrap:anywhere}.public-body .table .btn{white-space:normal}
@media(max-width:767.98px){
  html,body{overflow-x:hidden!important}.content-wrap,.public-body main{padding-left:10px!important;padding-right:10px!important}.public-body main{padding-bottom:26px!important}.public-body .navbar .container-fluid{align-items:flex-start;gap:6px;flex-direction:column}.public-body .navbar-brand{font-size:16px}.public-body .alert{font-size:13px;border-radius:16px}.public-body .stat-card{min-height:78px;text-align:center}.public-body .stat-number{font-size:24px}.public-body .card-header{font-size:15px;line-height:1.7}.public-body h1{font-size:18px!important;line-height:1.7}.public-body .form-label{font-weight:800}.public-body .btn{min-height:44px}

  /* Generic mobile card table. JS fills data-label from the table header. */
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll){display:block;width:100%!important;border-collapse:separate!important;border-spacing:0!important;background:transparent!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) thead{display:none!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tbody{display:block;width:100%}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr{display:block;width:100%;background:#fff;border:1px solid #e5e7eb;border-radius:18px;margin:var(--mobile-card-gap) 0;padding:10px 12px;box-shadow:0 8px 18px rgba(15,23,42,.045)}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse:not(.show){display:none!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse.show{display:block!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td{display:flex!important;align-items:flex-start;justify-content:space-between;gap:14px;width:100%!important;border:0!important;border-bottom:1px dashed #e5e7eb!important;padding:8px 0!important;text-align:left!important;white-space:normal!important;word-break:normal!important;overflow-wrap:anywhere!important;min-height:34px}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td:last-child{border-bottom:0!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td::before{content:attr(data-label);flex:0 0 42%;max-width:42%;text-align:right;font-weight:900;color:#475569;line-height:1.65}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td:empty::after{content:'-';color:#94a3b8}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan]{display:block!important;text-align:center!important;border-bottom:0!important;color:#64748b;padding:18px 8px!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan]::before{content:''!important;display:none!important}
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td .btn{width:100%;margin-top:2px}.table-responsive,.table-scroll-x{overflow-x:visible!important;max-width:100%!important}

  /* Collapse/detail rows should look like a sub-card, not a squeezed table. */
  table.mobile-card-table tr.collapse td[colspan]{background:#f8fafc;border-radius:14px;padding:10px!important}.collapse table.mobile-card-table tr{box-shadow:none;background:#fff;border-radius:14px}.collapse table.mobile-card-table td::before{flex-basis:38%;max-width:38%}
}
@media(max-width:420px){
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td{display:block!important;text-align:right!important}.mobile-card-table td::before{display:block;max-width:100%!important;margin-bottom:3px}.public-body .stat-card{text-align:right}.public-body .btn{width:100%}.public-body .card-header .btn{width:auto}
}
@media print{table.mobile-card-table{display:table!important}table.mobile-card-table thead{display:table-header-group!important}table.mobile-card-table tbody{display:table-row-group!important}table.mobile-card-table tr{display:table-row!important;box-shadow:none!important;border:0!important}table.mobile-card-table td,table.mobile-card-table th{display:table-cell!important;border:1px solid #ddd!important}table.mobile-card-table td::before{content:''!important;display:none!important}}

/* v13: real mobile UX - compact lists, details inside patient page, full-screen modals on phones */
@media (max-width: 991.98px){
  html, body { overflow-x: hidden !important; }
  .content-wrap, .public-body main { max-width: 100% !important; padding-inline: 10px !important; }
  .card, .public-card, .stat-card { border-radius: 18px !important; }
  .card-header { line-height: 1.65; }

  /* All normal data tables become cards on tablet/phone. No column squeezing. */
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll),
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll){
    display:block !important;
    width:100% !important;
    border-collapse:separate !important;
    background:transparent !important;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) thead,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) thead{ display:none !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tbody,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) tbody{ display:block !important; width:100% !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) tr{
    display:block !important;
    width:100% !important;
    background:#fff !important;
    border:1px solid #e5e7eb !important;
    border-radius:18px !important;
    margin:10px 0 !important;
    padding:12px !important;
    box-shadow:0 8px 18px rgba(15,23,42,.045) !important;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse:not(.show),
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse:not(.show){ display:none !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse.show,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) tr.collapse.show{ display:block !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td{
    display:grid !important;
    grid-template-columns:minmax(92px, 40%) minmax(0, 1fr) !important;
    gap:10px !important;
    width:100% !important;
    border:0 !important;
    border-bottom:1px dashed #e5e7eb !important;
    padding:8px 0 !important;
    text-align:right !important;
    white-space:normal !important;
    word-break:normal !important;
    overflow-wrap:anywhere !important;
    align-items:start !important;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td:last-child,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td:last-child{ border-bottom:0 !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td::before,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td::before{
    content:attr(data-label);
    color:#64748b;
    font-weight:900;
    text-align:right;
    line-height:1.7;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan],
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan]{
    display:block !important;
    text-align:center !important;
    border-bottom:0 !important;
    padding:18px 8px !important;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan]::before,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td[colspan]::before{ content:'' !important; display:none !important; }
  .table-responsive, .table-scroll-x{ overflow-x: visible !important; max-width:100% !important; }
  .cell-patient strong, td[data-label="المريض"] strong{ font-size:1.02rem; line-height:1.8; }
  .action-bar{ display:grid !important; grid-template-columns:1fr 1fr; gap:8px !important; width:100%; }
  .action-bar .btn{ width:100%; min-height:42px; display:flex; align-items:center; justify-content:center; }

  /* Reports and public view should prefer readable cards, not squeezed tables. */
  .public-list-table td[data-label="عرض"] .btn,
  .patients-list-table td[data-label="إجراءات"] .btn{ width:100%; }

  /* Forms */
  .form-control, .form-select, .btn{ min-height:44px; }
  .row.g-2, .row.g-3{ --bs-gutter-y:.85rem; }
  .quota-row{ background:#f8fafc; border:1px solid #e5e7eb; border-radius:16px; padding:10px; margin-bottom:10px; }
  .quota-row > [class*="col-"]{ width:100%; }

  /* Floating windows become app-like screens on mobile. */
  .modal-full-mobile .modal-dialog,
  .modal.show .modal-dialog{
    width:100% !important;
    max-width:none !important;
    height:100dvh !important;
    margin:0 !important;
    padding:0 !important;
  }
  .modal-full-mobile .modal-content,
  .modal.show .modal-content{
    min-height:100dvh !important;
    border:0 !important;
    border-radius:0 !important;
    display:flex !important;
    flex-direction:column !important;
  }
  .modal-header{ position:sticky; top:0; z-index:3; background:#fff; border-bottom:1px solid #e5e7eb; }
  .modal-footer{ position:sticky; bottom:0; z-index:3; background:#fff; border-top:1px solid #e5e7eb; display:grid; grid-template-columns:1fr 1fr; gap:8px; }
  .modal-footer .btn{ width:100%; margin:0 !important; }
  .modal-body{ flex:1 1 auto; overflow:auto; padding:14px !important; }
  .modal-step{ padding:0 !important; }
  .modal-step-title{ font-size:1rem; margin-bottom:12px; }
  #templateSelectModal, #templateSelectPage{ min-width:0 !important; width:100% !important; }
}

@media (max-width: 480px){
  .topbar h1{ max-width:70vw; font-size:1.05rem !important; }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td{
    display:block !important;
    text-align:right !important;
  }
  table.mobile-card-table:not(.desktop-table):not(.allow-horizontal-scroll) td::before,
  table.responsive-table:not(.desktop-table):not(.allow-horizontal-scroll) td::before{
    display:block !important;
    margin-bottom:3px !important;
  }
  .action-bar{ grid-template-columns:1fr !important; }
  .public-body .card-header .btn{ width:100%; margin-top:8px; }
}

/* v14: reliable mobile modals + patient file number support */
@media (max-width: 991.98px){
  .modal-open{overflow:hidden!important;position:fixed;width:100%;inset:0 auto auto 0;}
  .modal{padding:0!important;overflow:hidden!important;}
  .modal.fade .modal-dialog{transition:none!important;}
  .modal.show .modal-dialog,
  .modal-full-mobile .modal-dialog{
    width:100vw!important;
    max-width:100vw!important;
    height:100dvh!important;
    max-height:100dvh!important;
    margin:0!important;
    transform:none!important;
  }
  .modal.show .modal-content,
  .modal-full-mobile .modal-content{
    width:100vw!important;
    height:100dvh!important;
    max-height:100dvh!important;
    min-height:100dvh!important;
    border-radius:0!important;
    display:grid!important;
    grid-template-rows:auto minmax(0,1fr) auto!important;
    overflow:hidden!important;
  }
  .modal.show .modal-header,
  .modal-full-mobile .modal-header{
    position:relative!important;
    top:auto!important;
    flex-shrink:0!important;
    padding-top:calc(14px + env(safe-area-inset-top))!important;
  }
  .modal.show .modal-body,
  .modal-full-mobile .modal-body{
    min-height:0!important;
    max-height:none!important;
    height:auto!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    -webkit-overflow-scrolling:touch!important;
    padding:14px 14px calc(24px + env(safe-area-inset-bottom))!important;
  }
  .modal.show .modal-footer,
  .modal-full-mobile .modal-footer{
    position:relative!important;
    bottom:auto!important;
    flex-shrink:0!important;
    padding-bottom:calc(12px + env(safe-area-inset-bottom))!important;
    background:#fff!important;
    box-shadow:0 -8px 20px rgba(15,23,42,.08)!important;
  }
  .modal.show .modal-body .permissions-grid,
  .modal-full-mobile .modal-body .permissions-grid{padding-bottom:20px!important;}
  .modal.show .modal-body .form-check,
  .modal-full-mobile .modal-body .form-check{min-height:38px;}
}

/* v16: partial/supplemental dispensing UI */
.quota-period-card{height:100%;}
.quota-period-card .btn{height:100%; border-radius:16px; padding:14px;}
.quota-period-card.active .btn{box-shadow:0 10px 22px rgba(15,118,110,.18);}
.dispense-items-table th,.dispense-items-table td{vertical-align:middle;}
.dispense-qty-input{min-width:110px;}
