/* ============================================================
   Hospital ERP — Global Stylesheet  (responsive + PWA)
   ============================================================ */

:root {
  --primary:    #2c3e50;
  --accent:     #3498db;
  --success:    #27ae60;
  --warning:    #f39c12;
  --danger:     #e74c3c;
  --info:       #17a2b8;
  --sidebar-w:  240px;
  --topbar-h:   54px;
  --bg:         #f0f2f5;
  --card-bg:    #ffffff;
  --text:       #2d3436;
  --muted:      #636e72;
  --border:     #dfe6e9;
  --nhil-color: #e67e22;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); line-height: 1.5; }

/* ══ LAYOUT ═══════════════════════════════════════════════════ */
.erp-body { display: block; min-height: 100vh; background: var(--bg); }

.erp-sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #ecf0f1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 300;
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  -webkit-overflow-scrolling: touch;
}

.erp-main {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  padding: 24px;
  min-height: 100vh;
  box-sizing: border-box;
}

/* Overlay behind open sidebar (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 299;
  cursor: pointer;
}
.sidebar-overlay.show { display: block; }

/* Mobile top-bar */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--primary);
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  z-index: 400;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.mobile-topbar-title {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Hamburger button */
.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: #fff;
  flex-shrink: 0;
  border-radius: 6px;
  transition: background .15s;
}
.hamburger-btn:hover { background: rgba(255,255,255,.12); }
.hamburger-btn .bar {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  margin: 5px 0;
  transition: all .3s;
}
body.sidebar-open .hamburger-btn .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.sidebar-open .hamburger-btn .bar:nth-child(2) { opacity: 0; transform: scaleX(0); }
body.sidebar-open .hamburger-btn .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Sidebar close button (mobile only) */
.sidebar-close-btn {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,.6);
  cursor: pointer;
  font-size: 1.4rem;
  padding: 4px 8px;
  margin-left: auto;
  border-radius: 4px;
  transition: color .15s;
}
.sidebar-close-btn:hover { color: #fff; }

/* ══ SIDEBAR ══════════════════════════════════════════════════ */
.sidebar-brand {
  padding: 18px 16px;
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.brand-icon { font-size: 1.5rem; }
.sidebar-nav { list-style: none; padding: 8px 0; flex: 1; }
.sidebar-nav li a {
  display: block;
  padding: 9px 20px;
  color: #b2bec3;
  text-decoration: none;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
  font-size: .875rem;
}
.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-left-color: var(--accent);
}
.nav-section {
  padding: 12px 20px 4px;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
}
.nav-highlight        { background: rgba(52,152,219,.18) !important; color: #74c7ec !important; }
.nav-highlight-orange { background: rgba(230,126,34,.15) !important; color: #f0a96e !important; }
.nav-highlight-red    { background: rgba(231,76,60,.15)  !important; color: #f1a9a0 !important; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .8rem;
  flex-shrink: 0;
}

/* ══ PAGE HEADER ══════════════════════════════════════════════ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h2 { font-size: 1.4rem; color: var(--primary); }

/* ══ KPI CARDS ════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border-left: 4px solid;
}
.kpi-card.blue   { border-color: var(--accent);    }
.kpi-card.green  { border-color: var(--success);   }
.kpi-card.orange { border-color: var(--nhil-color); }
.kpi-card.teal   { border-color: var(--info);      }
.kpi-card.yellow { border-color: var(--warning);   }
.kpi-card.purple { border-color: #9b59b6;          }
.kpi-card.red    { border-color: var(--danger);    }
.kpi-icon  { font-size: 1.8rem; flex-shrink: 0; }
.kpi-value { font-size: 1.35rem; font-weight: 700; color: var(--primary); }
.kpi-label { font-size: .78rem; color: var(--muted); }
.kpi-sub   { font-size: .72rem; color: var(--success); }

/* ══ DASHBOARD ════════════════════════════════════════════════ */
.dashboard-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: var(--card-bg); border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.06); overflow: hidden; }
.panel-header { background: var(--primary); color: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.panel-body { padding: 16px; }

/* ══ CARDS ════════════════════════════════════════════════════ */
.card        { background: var(--card-bg); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.08); margin-bottom: 16px; overflow: visible; }
.card-header { background: #f8f9fa; border-bottom: 1px solid var(--border); padding: 12px 16px; font-weight: 600; }
.card-body   { padding: 16px; }

/* ══ TABLES ═══════════════════════════════════════════════════ */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { background: var(--primary); color: #fff; font-weight: 600; white-space: nowrap; }
.table-sm th, .table-sm td { padding: 6px 10px; }
.table-hover tbody tr:hover { background: #f5f6fa; }
.table-bordered th, .table-bordered td { border: 1px solid var(--border); }
.thead-dark th { background: var(--primary); color: #fff; }

/* ══ FORMS ════════════════════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color .15s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52,152,219,.12); }
.form-control-sm { padding: 5px 8px; font-size: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 14px; }
.form-row .form-group { flex: 1; min-width: 200px; }

/* col-md-* helpers */
.col-md-1  { flex: 0 0 calc(8.33%  - 14px); min-width:80px;  }
.col-md-2  { flex: 0 0 calc(16.66% - 14px); min-width:100px; }
.col-md-3  { flex: 0 0 calc(25%    - 14px); min-width:140px; }
.col-md-4  { flex: 0 0 calc(33.33% - 14px); min-width:160px; }
.col-md-5  { flex: 0 0 calc(41.66% - 14px); min-width:180px; }
.col-md-6  { flex: 0 0 calc(50%    - 14px); min-width:200px; }
.col-md-7  { flex: 0 0 calc(58.33% - 14px); min-width:220px; }
.col-md-8  { flex: 0 0 calc(66.66% - 14px); min-width:240px; }
.col-md-9  { flex: 0 0 calc(75%    - 14px); min-width:260px; }
.col-md-10 { flex: 0 0 calc(83.33% - 14px); min-width:280px; }
.col-md-11 { flex: 0 0 calc(91.66% - 14px); min-width:300px; }
.col-md-12 { flex: 0 0 100%; min-width:0; }

/* ══ BUTTONS ══════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { opacity: .87; }
.btn-primary      { background: var(--accent);   color: #fff; }
.btn-success      { background: var(--success);  color: #fff; }
.btn-danger       { background: var(--danger);   color: #fff; }
.btn-secondary    { background: #6c757d;         color: #fff; }
.btn-warning      { background: var(--warning);  color: #fff; }
.btn-info         { background: var(--info);     color: #fff; }
.btn-sm           { padding: 5px 10px; font-size: 12px; }
.btn-xs           { padding: 3px 8px;  font-size: 11px; }
.btn-lg           { padding: 11px 22px; font-size: 15px; }
.btn-block        { display: flex; width: 100%; }
.btn-outline-primary { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-outline-primary:hover { background: var(--accent); color: #fff; }

/* ══ BADGES ═══════════════════════════════════════════════════ */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-primary   { background: var(--accent);   color: #fff; }
.badge-success   { background: var(--success);  color: #fff; }
.badge-danger    { background: var(--danger);   color: #fff; }
.badge-warning   { background: var(--warning);  color: #fff; }
.badge-info      { background: var(--info);     color: #fff; }
.badge-secondary { background: #6c757d;         color: #fff; }

/* ══ ALERTS ═══════════════════════════════════════════════════ */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger  { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* ══ NHIL ═════════════════════════════════════════════════════ */
.nhil-banner { background:#fff8e1;border:1px solid #f39c12;border-left:4px solid var(--nhil-color);padding:10px 16px;border-radius:6px;margin-bottom:20px;color:#7f4f00;font-size:.9rem; }
.nhil-note { color:var(--muted);font-size:.8rem; }
.totals-grid { display:grid;grid-template-columns:auto auto;width:360px;margin-left:auto;gap:4px 16px; }
.totals-label { font-size:.9rem;text-align:right;padding:4px 0;color:var(--muted); }
.totals-value { font-size:.9rem;text-align:right;padding:4px 0;font-weight:600; }
.totals-label.nhil-line, .totals-value.nhil-line { color:var(--nhil-color);font-size:.85rem; }
.totals-label.grand, .totals-value.grand { font-size:1.1rem;color:var(--primary);border-top:2px solid var(--primary);padding-top:8px; }

/* ══ LOGIN ════════════════════════════════════════════════════ */
.login-body { display:flex;align-items:center;justify-content:center;min-height:100vh;background:linear-gradient(135deg,#2c3e50 0%,#3498db 100%);padding:20px; }
.login-card { background:#fff;border-radius:12px;padding:36px 32px;width:100%;max-width:380px;box-shadow:0 20px 60px rgba(0,0,0,.3); }
.login-logo     { font-size:3rem;text-align:center; }
.login-title    { font-size:1.3rem;font-weight:700;color:var(--primary);text-align:center;margin:8px 0 4px; }
.login-subtitle { text-align:center;color:var(--muted);margin-bottom:24px; }

/* ══ TABS ═════════════════════════════════════════════════════ */
.tab-nav { display:flex;flex-wrap:wrap;gap:0;border-bottom:2px solid var(--border);overflow-x:auto;-webkit-overflow-scrolling:touch; }
.tab-btn { padding:10px 16px;border:none;background:transparent;cursor:pointer;font-size:13px;font-weight:500;color:var(--muted);border-bottom:3px solid transparent;margin-bottom:-2px;white-space:nowrap;transition:color .15s; }
.tab-btn.active { color:var(--accent);border-bottom-color:var(--accent); }
.tab-btn:hover  { color:var(--primary);background:#f8f9fa; }

/* ══ MODALS ═══════════════════════════════════════════════════ */
.modal-overlay { position:fixed;inset:0;background:rgba(0,0,0,.52);z-index:1000;display:none;align-items:center;justify-content:center;padding:12px; }
.modal-overlay.show { display:flex; }
.modal-box { background:#fff;border-radius:10px;padding:24px;box-shadow:0 20px 60px rgba(0,0,0,.3);width:680px;max-width:100%;max-height:92vh;overflow-y:auto; }
.modal-header { font-size:1.05rem;font-weight:700;margin-bottom:16px;color:var(--primary);display:flex;justify-content:space-between;align-items:center; }
.modal-close { background:none;border:none;font-size:1.5rem;cursor:pointer;color:var(--muted); }
.modal-close:hover { color:var(--danger); }

/* ══ UTILITIES ════════════════════════════════════════════════ */
.mt-1{margin-top:4px}    .mt-2{margin-top:8px}
.mt-3{margin-top:16px}   .mt-4{margin-top:24px}
.mb-0{margin-bottom:0}   .mb-3{margin-bottom:16px}  .mb-4{margin-bottom:24px}
.p-0{padding:0}          .p-3{padding:16px}          .p-4{padding:24px}
.py-4{padding-top:24px;padding-bottom:24px}
.d-flex{display:flex}    .d-none{display:none}
.flex-wrap{flex-wrap:wrap}   .gap-2{gap:8px}
.text-muted{color:var(--muted)}   .text-right{text-align:right}
.text-center{text-align:center}   .text-warning{color:var(--nhil-color)!important}
.small{font-size:.8rem}   .fw-bold{font-weight:700}
.col-6{width:50%;float:left;padding:0 8px}   .row{display:flex;flex-wrap:wrap;margin:0 -8px}
.justify-content-between{justify-content:space-between}
.align-items-center{align-items:center}
.overflow-auto{overflow:auto}   .w-100{width:100%}

/* ══ NETWORK STATUS INDICATOR ═════════════════════════════════ */
.net-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  cursor: default;
  transition: background .3s, color .3s;
  border: 1px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.net-indicator.net-online  { background:#d4edda; color:#155724; border-color:#c3e6cb; }
.net-indicator.net-offline { background:#f8d7da; color:#721c24; border-color:#f5c6cb; }
.net-indicator.net-syncing { background:#fff3cd; color:#856404; border-color:#ffeeba; }
.net-indicator.net-synced  { background:#d4edda; color:#155724; border-color:#c3e6cb; }
.net-indicator.net-error   { background:#f8d7da; color:#721c24; border-color:#f5c6cb; }

.net-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  animation: netpulse 2.5s infinite;
}
.net-indicator.net-offline .net-dot,
.net-indicator.net-error   .net-dot { animation: netpulse .65s infinite; }
.net-indicator.net-syncing .net-dot { animation: netspin 1s linear infinite; }

@keyframes netpulse { 0%,100%{opacity:1} 50%{opacity:.2} }
@keyframes netspin  { to{transform:rotate(360deg)} }

/* Pending sync badge */
.sync-badge {
  display: none;
  background: #e74c3c;
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: .66rem;
  font-weight: 700;
  margin-left: 5px;
  vertical-align: middle;
}

/* ══ RESPONSIVE: TABLET ≤992px ════════════════════════════════ */
@media (max-width: 992px) {
  :root { --sidebar-w: 220px; }
  .dashboard-panels { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .totals-grid { width: 100%; }
}

/* ══ RESPONSIVE: MOBILE ≤768px ════════════════════════════════ */
@media (max-width: 768px) {

  /* Show mobile topbar */
  .mobile-topbar { display: flex; }

  /* Sidebar slides off-screen */
  .erp-sidebar { transform: translateX(-100%); top: 0; }
  body.sidebar-open .erp-sidebar { transform: translateX(0); }

  /* Close × inside sidebar */
  .sidebar-close-btn { display: block; }
  .sidebar-brand { padding: 14px 12px; }

  /* Main full-width, pushed below topbar */
  .erp-main {
    margin-left: 0;
    width: 100%;
    padding: 14px;
    padding-top: calc(var(--topbar-h) + 14px);
  }

  /* KPI 2-col */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 14px 12px; }
  .kpi-icon { font-size: 1.5rem; }
  .kpi-value { font-size: 1.15rem; }

  /* Page header stacks */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
  .page-header h2 { font-size: 1.2rem; }
  .page-header .d-flex { width: 100%; flex-wrap: wrap; gap: 6px; }
  .page-header .btn { flex: 1; justify-content: center; min-width: 130px; }

  /* Forms: single column */
  .form-row { gap: 10px; }
  .form-row .form-group,
  .col-md-1,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,
  .col-md-7,.col-md-8,.col-md-9,.col-md-10,.col-md-11 {
    flex: 0 0 100%;
    min-width: 0;
    width: 100%;
  }

  /* Tables scroll */
  .card { border-radius: 6px; overflow: visible; }
  .card-body        { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card-body.p-0, .table-responsive, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap .table,
  .table-responsive .table,
  .card-body .table  { min-width: 540px; }
  .table th, .table td { padding: 7px 8px; white-space: nowrap; }
  .table-sm { font-size: 12px; }
  .card-body { padding: 12px; }
  .card-header { padding: 10px 12px; }

  /* Modals full-screen */
  .modal-box { width: 100% !important; max-height: 94vh; padding: 16px; border-radius: 8px; }
  .modal-overlay { padding: 8px; }

  /* Buttons */
  .btn-lg { padding: 10px 18px; font-size: 14px; }
  .totals-grid { width: 100%; }
  .dashboard-panels { grid-template-columns: 1fr; gap: 14px; }
}

/* ══ RESPONSIVE: SMALL MOBILE ≤480px ═════════════════════════ */
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-card { padding: 12px 10px; gap: 10px; }
  .kpi-icon { font-size: 1.3rem; }
  .kpi-value { font-size: 1rem; }
  .erp-main { padding: 10px; padding-top: calc(var(--topbar-h) + 10px); }
  .login-card { padding: 28px 20px; }
  .badge { font-size: .66rem; padding: 2px 6px; }
  .btn-xs { font-size: 10px; padding: 2px 6px; }
}

/* ══ PRINT ════════════════════════════════════════════════════ */
@media print {
  .erp-sidebar, .mobile-topbar, .sidebar-overlay,
  .no-print, #offline-banner, nav { display: none !important; }
  .erp-main { margin-left: 0 !important; padding: 0 !important; }
  .erp-body { display: block; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .table th { background: #444 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
