/* ============================================================
   GLOBAL
============================================================ */
:root {
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --mobile-nav-h: 58px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f1f5f9; }

/* ============================================================
   SIDEBAR
============================================================ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0f172a;
  color: white;
  display: flex;
  flex-direction: column;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1), width 0.28s ease;
  z-index: 50;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; font-size: 14px;
  color: #94a3b8; text-decoration: none; transition: all 0.15s;
  cursor: pointer; border: none; background: none; width: 100%;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #e2e8f0; }
.nav-item.active { background: rgba(59,130,246,0.22); color: #60a5fa; font-weight: 600; }
.nav-item .nav-icon { width: 20px; flex-shrink: 0; text-align: center; }
.nav-section {
  font-size: 10px; font-weight: 700; color: #475569; letter-spacing: 0.1em;
  padding: 14px 12px 5px; text-transform: uppercase;
}

/* Sidebar Overlay (mobile) */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 49;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}
#sidebar-overlay.show { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   TOPBAR
============================================================ */
#topbar {
  height: var(--topbar-h);
  background: white;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 30;
}

/* ============================================================
   STAT CARDS
============================================================ */
.stat-card {
  background: white; border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm); border: 1px solid #f1f5f9;
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

/* ============================================================
   STATUS BADGES
============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge-available { background: #dcfce7; color: #16a34a; }
.badge-in_use { background: #dbeafe; color: #2563eb; }
.badge-under_maintenance { background: #fef9c3; color: #ca8a04; }
.badge-disposed { background: #f1f5f9; color: #64748b; }
.badge-lost { background: #fee2e2; color: #dc2626; }
.badge-pending { background: #fef3c7; color: #d97706; }
.badge-approved { background: #d1fae5; color: #059669; }
.badge-rejected { background: #fee2e2; color: #dc2626; }
.badge-processing { background: #dbeafe; color: #2563eb; }
.badge-completed { background: #dcfce7; color: #16a34a; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
.badge-draft { background: #f1f5f9; color: #64748b; }
.badge-sent { background: #fef9c3; color: #ca8a04; }
.badge-acknowledged { background: #dcfce7; color: #16a34a; }
.badge-new { background: #ede9fe; color: #7c3aed; }
.badge-good { background: #dcfce7; color: #16a34a; }
.badge-fair { background: #fef9c3; color: #ca8a04; }
.badge-poor { background: #fee2e2; color: #dc2626; }
.badge-damaged { background: #fee2e2; color: #991b1b; }
.badge-low { background: #f0fdf4; color: #16a34a; }
.badge-normal { background: #f0f9ff; color: #0369a1; }
.badge-high { background: #fff7ed; color: #c2410c; }
.badge-urgent { background: #fef2f2; color: #dc2626; }
.badge-scheduled { background: #ede9fe; color: #7c3aed; }
.badge-in_progress { background: #dbeafe; color: #2563eb; }

/* ============================================================
   DATA TABLE
============================================================ */
.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.data-table th {
  background: #f8fafc; text-align: left; padding: 11px 14px;
  font-size: 11px; font-weight: 700; color: #64748b; letter-spacing: 0.05em;
  text-transform: uppercase; border-bottom: 2px solid #e2e8f0;
  white-space: nowrap; position: sticky; top: 0;
}
.data-table td { padding: 11px 14px; font-size: 13.5px; color: #374151; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.data-table tr:hover td { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }
.data-table td .text-xs { font-size: 11.5px; }

/* ============================================================
   FORM
============================================================ */
.form-input {
  width: 100%; padding: 9px 14px; border: 1.5px solid #d1d5db;
  border-radius: 10px; font-size: 14px; transition: border-color 0.15s, box-shadow 0.15s;
  background: white; color: #111827; line-height: 1.4;
}
.form-input:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.12); }
.form-input:disabled { background: #f9fafb; color: #9ca3af; cursor: not-allowed; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 5px; }
.form-hint { font-size: 12px; color: #9ca3af; margin-top: 4px; }
.form-group { margin-bottom: 16px; }
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ============================================================
   BUTTONS
============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 18px; border-radius: 10px; font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s; text-decoration: none;
  white-space: nowrap; flex-shrink: 0; line-height: 1;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.btn-secondary { background: #f1f5f9; color: #374151; border: 1.5px solid #e2e8f0; }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-success { background: #059669; color: white; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-warning { background: #d97706; color: white; }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-xs { padding: 4px 9px; font-size: 11.5px; border-radius: 6px; }
.btn-icon { padding: 7px; min-width: 34px; justify-content: center; aspect-ratio: 1; }
.btn-ghost { background: transparent; color: #6b7280; }
.btn-ghost:hover:not(:disabled) { background: #f3f4f6; color: #374151; }

/* ============================================================
   CARDS
============================================================ */
.card { background: white; border-radius: var(--radius-lg); border: 1px solid #e2e8f0; overflow: hidden; }
.card-header {
  padding: 14px 18px; border-bottom: 1px solid #f1f5f9;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.card-body { padding: 18px; }

/* ============================================================
   MODAL
============================================================ */
/* Mobile: full-screen modal */
@media (max-width: 640px) {
  #modal-box {
    max-width: 100% !important;
    max-height: 100% !important;
    height: 100%;
    border-radius: 0 !important;
    margin: 0;
  }
  #modal-overlay { padding: 0 !important; align-items: flex-end; }
}

/* ============================================================
   TOAST
============================================================ */
.toast {
  padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease; min-width: 280px; max-width: 380px;
}
.toast-success { background: #059669; color: white; }
.toast-error { background: #dc2626; color: white; }
.toast-warning { background: #d97706; color: white; }
.toast-info { background: #2563eb; color: white; }
@keyframes slideInRight { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(110%); } }

/* ============================================================
   PAGINATION
============================================================ */
.pagination { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.page-btn {
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
  border: 1.5px solid #e2e8f0; background: white; cursor: pointer;
  color: #374151; transition: all 0.15s; min-width: 34px; text-align: center;
}
.page-btn:hover:not(:disabled) { background: #f1f5f9; border-color: #cbd5e1; }
.page-btn.active { background: #2563eb; color: white; border-color: #2563eb; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   TIMELINE
============================================================ */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content:''; position:absolute; left:8px; top:4px; bottom:4px; width:2px; background:#e2e8f0; }
.timeline-item { position: relative; margin-bottom: 18px; }
.timeline-item::before {
  content:''; position:absolute; left:-21px; top:5px;
  width:10px; height:10px; border-radius:50%;
  background:#3b82f6; border:2px solid white; box-shadow:0 0 0 2px #3b82f6;
}

/* ============================================================
   SEARCH & FILTERS
============================================================ */
.search-box { position: relative; }
.search-box .form-input { padding-left: 38px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9ca3af; font-size: 13px; }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-select {
  padding: 8px 12px; border: 1.5px solid #d1d5db; border-radius: 9px;
  font-size: 13px; background: white; color: #374151; cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { outline: none; border-color: #3b82f6; }

/* ============================================================
   DETAIL ROWS
============================================================ */
.detail-row { display: flex; padding: 9px 0; border-bottom: 1px solid #f1f5f9; gap: 12px; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 140px; flex-shrink: 0; font-size: 12.5px; color: #6b7280; font-weight: 600; padding-top: 1px; }
.detail-value { flex: 1; font-size: 13.5px; color: #111827; min-width: 0; word-break: break-word; }

/* ============================================================
   EMPTY STATE
============================================================ */
.empty-state { text-align: center; padding: 52px 20px; color: #9ca3af; }
.empty-state i { font-size: 44px; margin-bottom: 14px; display: block; color: #d1d5db; }
.empty-state p { font-size: 15px; margin-bottom: 6px; color: #6b7280; font-weight: 500; }
.empty-state span { font-size: 13px; color: #9ca3af; }

/* ============================================================
   LOADING / SKELETON
============================================================ */
.loading { display: flex; align-items: center; justify-content: center; padding: 48px; gap: 12px; color: #94a3b8; }
.loading i { font-size: 28px; color: #3b82f6; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================
   ALERT
============================================================ */
.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; line-height: 1.5; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #14532d; border: 1px solid #bbf7d0; }

/* ============================================================
   NOTIFICATION
============================================================ */
.notif-item { padding: 12px 16px; cursor: pointer; transition: background 0.15s; }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eff6ff; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: #3b82f6; flex-shrink: 0; margin-top: 5px; }

/* ============================================================
   SCROLLBAR
============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   CHART
============================================================ */
.chart-container { position: relative; height: 240px; }

/* ============================================================
   QR / PRINT
============================================================ */
.qr-preview { text-align: center; }
.qr-preview img { max-width: 200px; margin: 0 auto; border: 2px solid #e2e8f0; padding: 8px; border-radius: 12px; }
.qr-box { display: flex; align-items: center; justify-content: center; border-radius: 8px; overflow: hidden; }

/* ============================================================
   MOBILE BOTTOM NAV
============================================================ */
#mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--mobile-nav-h);
  background: #0f172a;
  z-index: 40;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: #64748b;
  font-size: 10px; font-weight: 500; cursor: pointer;
  text-decoration: none; transition: color 0.15s; padding: 6px 4px;
  border: none; background: none;
}
.mobile-nav-item i { font-size: 18px; }
.mobile-nav-item.active { color: #60a5fa; }
.mobile-nav-item:hover { color: #94a3b8; }

/* ============================================================
   PRINT
============================================================ */
@media print {
  #sidebar, #topbar, .btn, .filter-bar, #mobile-nav,
  .pagination, #sidebar-overlay { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  #main-content { padding: 0 !important; }
}

/* ============================================================
   RESPONSIVE — TABLET (max 1024px)
============================================================ */
@media (max-width: 1024px) {
  #sidebar { width: 220px; }
  :root { --sidebar-w: 220px; }
}

/* ============================================================
   RESPONSIVE — MOBILE (max 768px)
============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  /* Sidebar: slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }

  /* App layout: remove sidebar space */
  #app { display: block !important; padding-bottom: var(--mobile-nav-h); }
  #main-content { padding: 12px !important; }

  /* Topbar */
  #topbar { padding: 0 14px; }

  /* Show mobile bottom nav */
  #mobile-nav { display: flex; }

  /* Forms: single column */
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr !important; }

  /* Filters: stack vertically */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .search-box { flex: none; }
  .filter-select { width: 100%; }

  /* Cards */
  .card-header { flex-direction: column; align-items: flex-start; }

  /* Detail rows: stack on small screens */
  .detail-label { width: 110px; font-size: 12px; }
  .detail-value { font-size: 13px; }

  /* Pagination: smaller */
  .page-btn { padding: 5px 9px; font-size: 12px; }

  /* Stat cards: 2 per row via grid in page */
  .stats-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }

  /* Toast: full width bottom */
  #toast-container {
    top: auto !important; bottom: calc(var(--mobile-nav-h) + 12px) !important;
    right: 12px !important; left: 12px !important;
  }
  .toast { min-width: unset; max-width: 100%; width: 100%; }

  /* Notification dropdown: full width */
  #notif-dropdown { right: -8px; width: calc(100vw - 24px); }

  /* Tables: horizontal scroll */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 560px; }
  .data-table th, .data-table td { padding: 9px 10px; }

  /* Modal */
  #modal-overlay { padding: 0 !important; align-items: flex-end !important; }
  #modal-box {
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Bulk print bar */
  #bulk-print-bar { flex-wrap: wrap; gap: 6px; }
}

/* ============================================================
   RESPONSIVE — SMALL MOBILE (max 480px)
============================================================ */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr !important; }
  .btn { font-size: 13px; padding: 7px 14px; }
  .btn-sm { padding: 5px 10px; font-size: 12px; }
}
