/* ─── Design Tokens ────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-base:       #f0f4f8;
  --bg-surface:    #ffffff;
  --bg-surface-2:  #f8fafc;

  --border:        #e2e8f0;
  --border-dark:   #cbd5e1;

  --text-primary:  #0f172a;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;

  --primary:       #2563eb;
  --primary-light: #eff6ff;
  --primary-dark:  #1d4ed8;

  --ok:            #16a34a;
  --ok-bg:         #f0fdf4;
  --ok-border:     #bbf7d0;

  --low:           #d97706;
  --low-bg:        #fffbeb;
  --low-border:    #fde68a;

  --out:           #dc2626;
  --out-bg:        #fef2f2;
  --out-border:    #fecaca;

  --warn:          #ea580c;
  --warn-bg:       #fff7ed;
  --warn-border:   #fed7aa;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.12);

  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;

  --sidebar-w: 248px;
  --topbar-h:  60px;

  --font:  'Plus Jakarta Sans', -apple-system, sans-serif;
  --mono:  'JetBrains Mono', monospace;
}

/* ─── Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ──────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s ease;
}

.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-content {
  padding: 28px 28px 40px;
  flex: 1;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar-brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 17px;
  flex-shrink: 0;
}

.brand-text { font-size: 14px; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.brand-sub  { font-size: 10px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 8px 10px 4px;
  margin-top: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  transition: all .15s ease;
  margin-bottom: 2px;
  border-left: 2px solid transparent;
}

.sidebar-link:hover {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
  animation: sidebarActive .15s ease;
}

@keyframes sidebarActive {
  from { padding-left: 8px; }
  to   { padding-left: 12px; }
}

.sidebar-link i { font-size: 16px; width: 20px; flex-shrink: 0; }

.sidebar-badge {
  margin-left: auto;
  background: var(--out);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.sidebar-badge.warn { background: var(--low); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* ─── Topbar ──────────────────────────────────────────────── */
.topbar-title { font-size: 15px; font-weight: 700; color: var(--text-primary); flex: 1; }
.topbar-breadcrumb { font-size: 12px; color: var(--text-muted); }

.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid var(--primary-light);
}

.topbar-menu-btn {
  display: none;
  background: none; border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}

/* ─── KPI Cards ───────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: box-shadow .2s, transform .2s;
}

.kpi-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--kpi-accent, var(--primary));
  border-radius: 3px 0 0 3px;
}

.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.kpi-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  font-family: var(--mono);
  line-height: 1;
  animation: kpiIn .4s ease forwards;
}

.kpi-icon {
  position: absolute;
  right: 16px; top: 16px;
  font-size: 24px;
  opacity: .1;
  color: var(--kpi-accent, var(--primary));
}

@keyframes kpiIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Tables ──────────────────────────────────────────────── */
.table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.table-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.table-wrapper { overflow-x: auto; }

table.inv-table {
  width: 100%;
  border-collapse: collapse;
}

table.inv-table thead th {
  background: var(--bg-surface-2);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 5;
  cursor: pointer;
  user-select: none;
}

table.inv-table thead th:hover { color: var(--text-primary); }
table.inv-table thead th .sort-icon { opacity: .4; margin-left: 4px; font-size: 10px; }
table.inv-table thead th.sort-asc .sort-icon,
table.inv-table thead th.sort-desc .sort-icon { opacity: 1; color: var(--primary); }

table.inv-table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(226,232,240,.6);
  font-size: 13px;
  vertical-align: middle;
}

table.inv-table tbody tr:last-child td { border-bottom: none; }

table.inv-table tbody tr {
  animation: rowSlideIn .28s ease forwards;
  opacity: 0;
  transition: background .1s;
}

table.inv-table tbody tr:hover { background: rgba(37,99,235,.03); }
table.inv-table tbody tr:hover td:first-child { border-left: 2px solid var(--primary); }

@keyframes rowSlideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Stagger delays */
table.inv-table tbody tr:nth-child(1)  { animation-delay: .02s; }
table.inv-table tbody tr:nth-child(2)  { animation-delay: .04s; }
table.inv-table tbody tr:nth-child(3)  { animation-delay: .06s; }
table.inv-table tbody tr:nth-child(4)  { animation-delay: .08s; }
table.inv-table tbody tr:nth-child(5)  { animation-delay: .10s; }
table.inv-table tbody tr:nth-child(6)  { animation-delay: .12s; }
table.inv-table tbody tr:nth-child(7)  { animation-delay: .14s; }
table.inv-table tbody tr:nth-child(8)  { animation-delay: .16s; }
table.inv-table tbody tr:nth-child(9)  { animation-delay: .18s; }
table.inv-table tbody tr:nth-child(10) { animation-delay: .20s; }

/* ─── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-ok    { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-border); }
.badge-low   { background: var(--low-bg);  color: var(--low);  border-color: var(--low-border); animation: pulseLow 2s ease-in-out infinite; }
.badge-out   { background: var(--out-bg);  color: var(--out);  border-color: var(--out-border); animation: pulseOut 2s ease-in-out infinite; }
.badge-warn  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge-in    { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-border); }
.badge-out-mv{ background: var(--low-bg);  color: var(--low);  border-color: var(--low-border); }

.badge-pending    { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.badge-progress   { background: var(--primary-light); color: var(--primary); border-color: #bfdbfe; }
.badge-resolved   { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.badge-repair     { background: #fff7ed; color: #ea580c; border-color: #fed7aa; animation: flagPop .3s cubic-bezier(0.34,1.56,0.64,1); }
.badge-admin      { background: #f3e8ff; color: #7c3aed; border-color: #ddd6fe; }
.badge-manager    { background: var(--primary-light); color: var(--primary); border-color: #bfdbfe; }
.badge-technician { background: var(--bg-surface-2); color: var(--text-secondary); border-color: var(--border); }

@keyframes pulseLow {
  0%,100% { box-shadow: 0 0 0 0 rgba(217,119,6,.25); }
  50%      { box-shadow: 0 0 0 4px rgba(217,119,6,0); }
}

@keyframes pulseOut {
  0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.25); }
  50%      { box-shadow: 0 0 0 4px rgba(220,38,38,0); }
}

@keyframes flagPop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ─── Buttons ─────────────────────────────────────────────── */
.btn-primary-inv {
  background: var(--primary);
  color: #fff !important;
  border: none;
  border-radius: var(--r-sm);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all .18s ease;
  text-decoration: none;
}

.btn-primary-inv:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(37,99,235,.3); }
.btn-primary-inv:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
  text-decoration: none;
}

.btn-ghost:hover { background: var(--bg-surface-2); border-color: var(--border-dark); color: var(--text-primary); }

.btn-icon {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
  text-decoration: none;
}

.btn-icon:hover { background: var(--bg-surface-2); color: var(--text-primary); border-color: var(--border-dark); }
.btn-icon.btn-danger:hover { background: var(--out-bg); color: var(--out); border-color: var(--out-border); }
.btn-icon.btn-success:hover { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.btn-icon.btn-warn:hover { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }

/* ─── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label-inv { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.form-label-inv span.req { color: var(--out); }

.form-control-inv {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg-surface);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
  appearance: none;
}

.form-control-inv:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-control-inv::placeholder { color: var(--text-muted); }
.form-control-inv.is-invalid { border-color: var(--out); }

.search-box {
  position: relative;
  min-width: 220px;
}

.search-box i {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

.search-box input {
  padding-left: 32px;
  height: 36px;
  font-size: 13px;
}

.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* ─── Modal ───────────────────────────────────────────────── */
.modal-inv-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-inv {
  background: var(--bg-surface);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .22s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-inv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-inv-title { font-size: 16px; font-weight: 700; }
.modal-close-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  transition: all .15s;
}
.modal-close-btn:hover { background: var(--border); color: var(--text-primary); }

.modal-inv-body { padding: 22px; }
.modal-inv-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

/* ─── Detail Drawer ───────────────────────────────────────── */
.detail-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 380px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.1);
  z-index: 150;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
}

.detail-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }

.drawer-row { display: flex; flex-direction: column; gap: 3px; margin-bottom: 16px; }
.drawer-row-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.drawer-row-value { font-size: 14px; color: var(--text-primary); font-weight: 500; }

/* ─── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.toast-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--r);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 360px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  font-size: 13px;
}

.toast-item.success { border-left-color: var(--ok); }
.toast-item.error   { border-left-color: var(--out); }
.toast-item.warning { border-left-color: var(--low); }

.toast-item i { font-size: 17px; flex-shrink: 0; margin-top: 1px; }
.toast-item.success i { color: var(--ok); }
.toast-item.error   i { color: var(--out); }
.toast-item.warning i { color: var(--low); }
.toast-item.info    i { color: var(--primary); }

.toast-close { margin-left: auto; cursor: pointer; opacity: .5; font-size: 16px; line-height: 1; flex-shrink: 0; }
.toast-close:hover { opacity: 1; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-8px); } }

/* ─── Pagination ──────────────────────────────────────────── */
.pagination-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  gap: 12px;
  flex-wrap: wrap;
}

.page-btns { display: flex; gap: 4px; }
.page-btn {
  min-width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
  padding: 0 8px;
}
.page-btn:hover { background: var(--bg-surface-2); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ─── Progress Bar ────────────────────────────────────────── */
.supply-bar { background: var(--border); border-radius: 20px; height: 6px; overflow: hidden; min-width: 80px; }
.supply-fill {
  height: 100%;
  border-radius: 20px;
  background: var(--ok);
  width: 0%;
  transition: width .8s cubic-bezier(0.4,0,0.2,1);
}

.supply-fill.low  { background: var(--low); }
.supply-fill.crit { background: var(--out); }

/* ─── Charts ──────────────────────────────────────────────── */
.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.chart-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; }

/* ─── Page Header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}

.page-title    { font-size: 20px; font-weight: 800; color: var(--text-primary); line-height: 1.2; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state i { font-size: 48px; color: var(--border-dark); margin-bottom: 14px; display: block; }
.empty-state h5 { font-size: 15px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--text-muted); }

/* ─── Utility ─────────────────────────────────────────────── */
.text-mono    { font-family: var(--mono); }
.text-muted   { color: var(--text-muted) !important; }
.text-primary-inv { color: var(--text-primary) !important; }
.fw-700 { font-weight: 700 !important; }
.fw-800 { font-weight: 800 !important; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

/* ─── Month Filter Chips ──────────────────────────────────── */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .topbar-menu-btn { display: flex; }
  .page-content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-drawer { width: 100%; }
  .modal-inv { margin: 12px; max-width: calc(100% - 24px); }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .table-card-header { flex-direction: column; align-items: flex-start; }
}
