@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --primary-light: #1976D2;
  --primary-tint: #E3F2FD;
  --accent: #E64A19;
  --accent-dark: #BF360C;
  --accent-light: #FF5722;
  --white: #FFFFFF;
  --black: #1A1A2E;
  --dark: #212121;
  --gray-50: #F8F9FA;
  --gray-100: #F1F3F5;
  --gray-200: #E9ECEF;
  --gray-300: #DEE2E6;
  --gray-400: #CED4DA;
  --gray-500: #ADB5BD;
  --gray-600: #6C757D;
  --gray-700: #495057;
  --gray-800: #343A40;
  --success: #2E7D32;
  --success-light: #E8F5E9;
  --warning: #F57F17;
  --warning-light: #FFFDE7;
  --danger: #C62828;
  --danger-light: #FFEBEE;
  --info: #0277BD;
  --info-light: #E1F5FE;
  --sidebar-width: 260px;
  --header-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
  --shadow: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);
  --transition: all 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'Inter', sans-serif; background: var(--gray-50); color: var(--dark); line-height: 1.6; min-height: 100vh; overflow-x: hidden; }

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; width: 100%; }

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  position: fixed; top: 0; left: 0; height: 100vh;
  display: flex; flex-direction: column; z-index: 100;
  box-shadow: 4px 0 20px rgba(13,71,161,0.25);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-logo {
  padding: 16px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.sidebar-logo .logo-icon { font-size: 28px; }
.sidebar-logo h2 { color: var(--white); font-size: 13px; font-weight: 700; line-height: 1.3; }
.sidebar-logo p { color: rgba(255,255,255,0.7); font-size: 11px; margin-top: 2px; }

/* Tombol close di dalam drawer sidebar (khusus tablet/mobile) */
.sidebar-close-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  color: white;
  font-size: 15px;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.sidebar-close-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section-label { color: rgba(255,255,255,0.45); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; padding: 12px 20px 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; color: rgba(255,255,255,0.85);
  font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition); cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.10); color: var(--white); border-left-color: rgba(255,255,255,0.4); }
.nav-item.active { background: rgba(255,255,255,0.18); color: var(--white); border-left-color: var(--accent-light); font-weight: 600; }
.nav-item .nav-icon { font-size: 18px; min-width: 22px; text-align: center; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.12); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.sidebar-user .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { color: white; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { color: rgba(255,255,255,0.65); font-size: 11px; text-transform: capitalize; }

/* ===== HAMBURGER BUTTON ===== */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  padding: 0;
  cursor: pointer;
  color: var(--primary);
  transition: var(--transition);
  flex-shrink: 0;
  margin-right: 10px;
}
.hamburger-btn:hover {
  background: var(--primary-tint);
  border-color: var(--primary-light);
}
.hamburger-bars {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 18px;
  height: 14px;
}
.hamburger-bars span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: all 0.25s ease;
}
.hamburger-btn.active .hamburger-bars span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.hamburger-btn.active .hamburger-bars span:nth-child(2) {
  opacity: 0;
}
.hamburger-btn.active .hamburger-bars span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* ===== OVERLAY ===== */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
body.sidebar-open {
  overflow: hidden !important;
}

/* ===== TOPBAR ===== */
.topbar {
  position: fixed; top: 0; left: var(--sidebar-width); right: 0;
  height: var(--header-height); background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; z-index: 90;
  box-shadow: var(--shadow-sm);
  transition: left 0.3s ease;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-left img { height: 36px; object-fit: contain; flex-shrink: 0; }
.topbar-left > div { min-width: 0; }
.topbar-left h1, #page-title { font-size: 17px; font-weight: 700; color: var(--dark); margin: 0; line-height: 1.2; }
.topbar-left p, #page-subtitle { font-size: 12px; color: var(--gray-600); margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.btn-notif { position: relative; background: var(--gray-100); border: none; border-radius: 10px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; font-size: 18px; transition: var(--transition); flex-shrink: 0; }
.btn-notif:hover { background: var(--primary-tint); }
.notif-badge { position: absolute; top: -2px; right: -2px; background: var(--accent); color: white; font-size: 9px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  padding: 24px;
  min-height: calc(100vh - var(--header-height));
  box-sizing: border-box;
  max-width: calc(100vw - var(--sidebar-width));
  overflow-x: hidden;
  transition: margin-left 0.3s ease, max-width 0.3s ease;
}

/* ===== CARDS ===== */
.card { background: var(--white); border-radius: var(--border-radius); box-shadow: var(--shadow-sm); border: 1px solid var(--gray-200); margin-bottom: 20px; }
.card-header { padding: 18px 22px 14px; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--dark); margin: 0; }
.card-body { padding: 20px 22px; }

/* ===== STAT CARDS ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border-radius: var(--border-radius); padding: 20px; border: 1px solid var(--gray-200); box-shadow: var(--shadow-sm); transition: var(--transition); position: relative; overflow: hidden; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.stat-number { font-size: 30px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: 12px; font-weight: 500; color: var(--gray-600); margin-top: 6px; }
.stat-icon { font-size: 26px; position: absolute; top: 16px; right: 16px; opacity: 0.15; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 18px; border-radius: var(--border-radius-sm); font-size: 13px; font-weight: 600; border: none; transition: var(--transition); white-space: nowrap; cursor: pointer; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(21,101,192,0.35); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--accent-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(230,74,25,0.35); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-tint); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-gray { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-gray:hover { background: var(--gray-200); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 13px 28px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 100px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-primary { background: var(--primary-tint); color: var(--primary); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--gray-300);
  border-radius: var(--border-radius-sm); font-size: 14px; color: var(--dark);
  background: var(--white); transition: var(--transition); outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,0.12); }
.form-control.is-valid { border-color: var(--success); }
.form-control.is-invalid { border-color: var(--danger); }
.form-hint { font-size: 11px; color: var(--gray-600); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236C757D' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ===== CHECKBOX & RADIO ===== */
.check-group { display: flex; flex-wrap: wrap; gap: 10px; }
.check-item { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check-item input[type="checkbox"], .check-item input[type="radio"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ===== TABLE & RESPONSIVE SCROLL ===== */
.table-responsive, .table-container, .table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
  border-radius: var(--border-radius-sm);
}
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 100%; }
.table th { background: var(--gray-50); color: var(--gray-700); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; padding: 11px 14px; text-align: left; border-bottom: 2px solid var(--gray-200); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--gray-100); color: var(--dark); vertical-align: middle; }
.table tr:hover td { background: var(--gray-50); }
.table tr:last-child td { border-bottom: none; }

/* ===== ALERTS ===== */
.alert { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: var(--border-radius-sm); font-size: 13px; margin-bottom: 16px; }
.alert-success { background: var(--success-light); border-left: 4px solid var(--success); color: var(--success); }
.alert-danger { background: var(--danger-light); border-left: 4px solid var(--danger); color: var(--danger); }
.alert-warning { background: var(--warning-light); border-left: 4px solid var(--warning); color: #6B4400; }
.alert-info { background: var(--info-light); border-left: 4px solid var(--info); color: var(--info); }

/* ===== MODALS ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(2px); }
.modal-overlay.active { display: flex !important; }
.modal { background: white; border-radius: var(--border-radius-lg); max-width: 580px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); transform: scale(0.95); transition: transform 0.2s; display: flex; flex-direction: column; }
.modal-overlay.active .modal { transform: scale(1); }
.modal-header { padding: 18px 22px 14px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-header h3 { font-size: 16px; font-weight: 700; margin: 0; }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--gray-200); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--gray-500); cursor: pointer; }
.modal-close:hover { color: var(--dark); }

/* ===== TABS ===== */
.tabs { display: flex; border-bottom: 2px solid var(--gray-200); margin-bottom: 20px; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn { padding: 10px 18px; background: none; border: none; font-size: 13px; font-weight: 500; color: var(--gray-600); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: var(--transition); border-radius: 8px 8px 0 0; white-space: nowrap; }
.tab-btn:hover { background: var(--gray-100); color: var(--dark); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; background: var(--primary-tint); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== STEPPER ===== */
.stepper { display: flex; align-items: center; margin-bottom: 28px; width: 100%; }
.step { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.step-num { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; background: var(--gray-200); color: var(--gray-600); flex-shrink: 0; transition: var(--transition); }
.step.active .step-num { background: var(--primary); color: white; }
.step.done .step-num { background: var(--success); color: white; }
.step-label { font-size: 12px; font-weight: 500; color: var(--gray-600); }
.step.active .step-label { color: var(--primary); font-weight: 700; }
.step-line { flex: 1; height: 2px; background: var(--gray-200); margin: 0 8px; min-width: 12px; }
.step.done + .step-line { background: var(--success); }

/* ===== PROGRESS BAR ===== */
.progress { height: 8px; background: var(--gray-200); border-radius: 100px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 100px; transition: width 0.5s ease; }

/* ===== VITAL INDICATOR ===== */
.vital-status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 100px; }
.vital-normal { background: var(--success-light); color: var(--success); }
.vital-warning { background: var(--warning-light); color: var(--warning); }
.vital-danger { background: var(--danger-light); color: var(--danger); }

/* ===== ANTRIAN STATUS ===== */
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-green { background: #4CAF50; box-shadow: 0 0 0 3px rgba(76,175,80,0.25); animation: pulse-green 2s infinite; }
.dot-yellow { background: #FFC107; box-shadow: 0 0 0 3px rgba(255,193,7,0.25); }
.dot-gray { background: var(--gray-400); }
@keyframes pulse-green { 0%,100% { box-shadow: 0 0 0 3px rgba(76,175,80,0.25); } 50% { box-shadow: 0 0 0 6px rgba(76,175,80,0.10); } }

/* ===== SEARCH BAR ===== */
.search-bar { position: relative; }
.search-bar input { padding-left: 38px; }
.search-bar .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-500); font-size: 16px; pointer-events: none; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { color: var(--gray-600); font-size: 14px; }

/* ===== LOADING ===== */
.spinner { width: 24px; height: 24px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 9999; flex-direction: column; gap: 12px; }

/* ===== TOAST ===== */
#toast-container { position: fixed; top: 80px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: var(--border-radius-sm); background: var(--dark); color: white; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); min-width: 280px; animation: slide-in 0.3s ease; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: var(--dark); }
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== EMERGENCY BANNER ===== */
.emergency-banner { background: linear-gradient(135deg, var(--danger), #8B0000); color: white; padding: 14px 24px; border-radius: var(--border-radius); display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.emergency-banner .em-text { font-size: 13px; font-weight: 500; }
.emergency-banner .em-phone { font-size: 16px; font-weight: 700; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-400); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-500); }

/* ===== ANIMATIONS ===== */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== HKI WATERMARK ===== */
#hki-watermark {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(0,0,0,.25);
  z-index: 1;
  white-space: nowrap;
  pointer-events: none;
  font-family: inherit;
}
#hki-watermark strong { color: rgba(13,71,161,.35); }

/* ==========================================================================
   RESPONSIVE DESIGN (TABLET & MOBILE)
   ========================================================================== */

/* ===== TABLET & MOBILE (<= 1024px) ===== */
@media (max-width: 1024px) {
  /* Tampilkan Tombol Hamburger & Close Drawer */
  .hamburger-btn, #hamburger-btn { display: inline-flex !important; }
  .sidebar-close-btn { display: inline-flex !important; }

  /* Sidebar menjadi drawer tersembunyi */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    max-width: 85vw !important;
    height: 100vh !important;
    z-index: 1001 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3) !important;
  }
  .sidebar.open {
    transform: translateX(0) !important;
  }

  /* Overlay sidebar */
  #sidebar-overlay {
    display: block !important;
  }

  /* Topbar memenuhi lebar layar penuh */
  .topbar {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    padding: 0 16px !important;
  }
  .topbar-left {
    gap: 8px !important;
  }
  .topbar-left img {
    height: 32px !important;
  }
  .topbar-left h1, #page-title {
    font-size: 16px !important;
  }

  /* Main Content menyesuaikan lebar penuh */
  .app-layout {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .app-layout > div {
    width: 100% !important;
    max-width: 100vw !important;
  }
  .main-content {
    margin-left: 0 !important;
    margin-top: var(--header-height) !important;
    width: 100% !important;
    max-width: 100vw !important;
    padding: 20px 16px !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
  }

  /* Stat cards di Tablet: 2 atau 3 kolom */
  .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important;
    gap: 14px !important;
  }
  [style*="grid-template-columns:repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"],
  [style*="grid-template-columns:repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  /* Modals di tablet */
  .modal {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
  }
}

/* ===== TABLET PORTRAIT & MOBILE LANDSCAPE (<= 900px) ===== */
@media (max-width: 900px) {
  /* Override inline 2-kolom & 3-kolom grid menjadi stack responsif */
  .grid-2,
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ===== MOBILE PHONES (<= 768px) ===== */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px !important;
  }
  .topbar-left h1, #page-title {
    font-size: 15px !important;
  }
  .topbar-left p, #page-subtitle {
    display: none !important;
  }

  .main-content {
    padding: 14px 12px !important;
  }

  /* Stat Grid pada Mobile: 2 kolom compact */
  .stat-grid,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }
  .stat-card {
    padding: 14px 12px !important;
  }
  .stat-number {
    font-size: 22px !important;
  }
  .stat-label {
    font-size: 11px !important;
  }
  .stat-icon {
    font-size: 20px !important;
    top: 10px !important;
    right: 10px !important;
  }

  /* Form input & rows pada mobile */
  .form-row,
  .form-row-3,
  .form-grid-2,
  .form-grid-3,
  .form-grid-5 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Cards pada mobile */
  .card {
    margin-bottom: 14px !important;
  }
  .card-header {
    padding: 14px 16px !important;
  }
  .card-body {
    padding: 14px 16px !important;
  }

  /* Antrian grid & item */
  .antrian-grid {
    grid-template-columns: 1fr !important;
  }

  /* Modals pada mobile */
  .modal-overlay {
    padding: 10px !important;
  }
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 94vh !important;
    border-radius: var(--border-radius) !important;
    margin: auto !important;
  }
  .modal-header {
    padding: 14px 16px !important;
  }
  .modal-body {
    padding: 14px 16px !important;
    max-height: calc(94vh - 120px) !important;
  }
  .modal-footer {
    padding: 12px 16px !important;
    flex-direction: column-reverse !important;
    gap: 8px !important;
  }
  .modal-footer .btn {
    width: 100% !important;
    text-align: center !important;
    justify-content: center !important;
  }

  /* Table styling pada mobile */
  .table th, .table td {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Resep obat baris stack */
  .resep-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    background: var(--gray-50);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    margin-bottom: 10px !important;
  }
  .resep-row .m-obat-nama {
    grid-column: 1 / -1;
  }
  .resep-row button {
    grid-column: 1 / -1;
    width: 100%;
  }

  /* Stepper mobile */
  .step-label { display: none !important; }
  .stepper, #step-bar { justify-content: center !important; }
  .step-num { width: 28px !important; height: 28px !important; font-size: 11px !important; }
  .step-line { margin: 0 4px !important; min-width: 8px !important; }

  /* Login & Register Wrapper Mobile */
  .login-wrapper {
    grid-template-columns: 1fr !important;
    max-width: 480px !important;
    width: 100% !important;
    border-radius: 20px !important;
  }
  .login-left {
    padding: 24px 20px 20px !important;
    text-align: center !important;
    align-items: center !important;
  }
  .login-left .logo-wrap img {
    height: 56px !important;
  }
  .login-left h1 {
    font-size: 18px !important;
  }
  .login-left p {
    font-size: 12px !important;
  }
  .login-left .features {
    display: none !important;
  }
  .login-right {
    padding: 24px 20px !important;
  }
}

/* ===== SMALL PHONES (<= 480px) ===== */
@media (max-width: 480px) {
  .topbar-left img {
    display: none !important;
  }
  .topbar-right {
    gap: 6px !important;
  }
  .topbar-right .btn {
    padding: 6px 10px !important;
    font-size: 11px !important;
  }
  .btn-notif {
    width: 34px !important;
    height: 34px !important;
    font-size: 15px !important;
  }
  .stat-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  .stat-number {
    font-size: 20px !important;
  }
}

/* ===== RESPONSIVE UTILITIES ===== */
.btn-show-mobile { display: none !important; }
@media (max-width: 640px) {
  .btn-hide-mobile { display: none !important; }
  .btn-show-mobile { display: inline !important; }
  .chart-wrap { height: 180px !important; }
}
