/* ===================== Stock ERP — App Theme ===================== */
/* Same component system as the sibling app this project was modeled on (cards, stat-cards,
   badge-soft, app-table, mobile card-stacking, print rules) — recolored into its own
   "modern enterprise ERP" identity: deep navy sidebar, electric-blue primary, soft cyan accent. */
:root {
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light: #3b82f6;
  --accent: #06b6d4;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #7c3aed;
  --bg: #f2f5fa;
  --surface: #ffffff;
  --text: #1a2333;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar-bg: #0b1e3d;
  --sidebar-bg-2: #123a63;
  --radius: 14px;
  --shadow-sm: 0 2px 8px rgba(11, 30, 61, 0.06);
  --shadow-md: 0 8px 24px rgba(11, 30, 61, 0.10);
  --shadow-lg: 0 16px 40px rgba(11, 30, 61, 0.16);
}

* { box-sizing: border-box; }

html { font-size: 17px; }

body {
  font-family: 'Poppins', 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4, h5 { font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.3rem; }

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 270px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: #dbe6f8;
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 1000;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  padding: 0.5rem 0.75rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 1rem;
}
.sidebar-brand i { font-size: 1.6rem; color: var(--accent); }
.sidebar-brand .sidebar-logo { max-height: 38px; max-width: 44px; object-fit: contain; border-radius: 8px; }
.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: #b9c9e3;
  padding: 0.65rem 0.9rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  transition: all 0.2s ease;
  text-decoration: none;
}
.sidebar .nav-link i { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar .nav-link:hover {
  background: rgba(255,255,255,0.10);
  color: #fff;
  transform: translateX(4px);
}
.sidebar .nav-link.active {
  background: linear-gradient(90deg, var(--accent), var(--primary-light));
  color: #fff;
  box-shadow: var(--shadow-md);
}
.sidebar-section-title {
  text-transform: uppercase;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: #7c93bc;
  padding: 1rem 0.9rem 0.35rem;
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  padding: 0.9rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-weight: 500;
}
.topbar .user-chip .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
#sidebarToggle { display: none; }
.center-chip {
  background: #eef2ff; color: var(--primary-dark);
  padding: 0.3rem 0.8rem; border-radius: 999px; font-weight: 600; font-size: 0.85rem;
}

/* ---------- Main content ---------- */
.main-content { flex: 1; min-width: 0; }
.page-wrap { padding: 1.75rem; padding-bottom: 3.2rem; animation: fadeInUp 0.45s ease; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 0.75rem; }
.page-header h1 { margin: 0; }
.page-header .text-muted { font-size: 0.95rem; }

/* ---------- Cards ---------- */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.card.hoverable:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; padding: 1.1rem 1.4rem; font-size: 1.05rem; }
.card-body { padding: 1.4rem; }

/* Stat cards */
.stat-card {
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.25s ease;
}
.stat-card:hover { transform: translateY(-5px) scale(1.01); }
.stat-card .stat-icon { font-size: 2rem; opacity: 0.85; }
.stat-card .stat-value { font-size: 2.1rem; font-weight: 700; animation: popIn 0.5s ease; }
.stat-card .stat-label { font-size: 0.95rem; opacity: 0.9; }
.stat-card.grad-1 { background: linear-gradient(135deg, #1d4ed8, #3b82f6); }
.stat-card.grad-2 { background: linear-gradient(135deg, #0891b2, #22d3ee); }
.stat-card.grad-3 { background: linear-gradient(135deg, #16a34a, #4ade80); }
.stat-card.grad-4 { background: linear-gradient(135deg, #d97706, #fbbf24); }
.stat-card.grad-5 { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.stat-card.grad-6 { background: linear-gradient(135deg, #db2777, #f472b6); }

/* ---------- Forms ---------- */
label.form-label { font-weight: 500; font-size: 0.95rem; margin-bottom: 0.35rem; }
.form-control, .form-select {
  border-radius: 10px;
  border: 1.5px solid var(--border);
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.15);
}
.form-section-title {
  font-weight: 600;
  color: var(--primary);
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
  margin: 1.75rem 0 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.form-section-title:first-child { margin-top: 0; }

/* ---------- Buttons ---------- */
.btn { border-radius: 10px; font-weight: 500; padding: 0.55rem 1.2rem; transition: all 0.2s ease; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); border: none; }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn-success { background: linear-gradient(135deg, #16a34a, #4ade80); border: none; }
.btn-danger { background: linear-gradient(135deg, #dc2626, #f87171); border: none; }
.btn-outline-secondary { border-radius: 10px; }
.fab-add {
  border-radius: 999px;
  padding: 0.65rem 1.4rem;
  box-shadow: var(--shadow-md);
}

/* ---------- Tables ---------- */
.table-card { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); background: var(--surface); }
table.app-table { margin-bottom: 0; }
table.app-table thead th {
  background: #eaf0fb;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: none;
  padding: 0.9rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.app-table tbody td { padding: 0.85rem 1rem; vertical-align: middle; font-size: 0.98rem; }
table.app-table tbody tr { transition: background 0.15s ease; }
table.app-table tbody tr:hover { background: #f4f7fd; }
.thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; box-shadow: var(--shadow-sm); }

.badge-soft { padding: 0.4em 0.8em; border-radius: 999px; font-weight: 500; font-size: 0.82rem; white-space: nowrap; }
.badge-soft.active, .badge-soft.approved, .badge-soft.completed, .badge-soft.received, .badge-soft.paid, .badge-soft.in_stock { background: #dcfce7; color: #166534; }
.badge-soft.inactive, .badge-soft.rejected, .badge-soft.cancelled, .badge-soft.damaged { background: #fee2e2; color: #991b1b; }
.badge-soft.draft { background: #f1f5f9; color: #475569; }
.badge-soft.pending, .badge-soft.pending_approval, .badge-soft.submitted { background: #fef3c7; color: #92400e; }
.badge-soft.dispatched, .badge-soft.in_transit, .badge-soft.intransit, .badge-soft.transferred, .badge-soft.issued { background: #ede9fe; color: #5b21b6; }
.badge-soft.low_stock { background: #ffedd5; color: #9a3412; }
.badge-soft.out_of_stock, .badge-soft.zero_stock { background: #fee2e2; color: #991b1b; }

/* ---------- Line-item editor (multi-row Stock Inward/Outward/Transfer forms) ---------- */
.line-items-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.line-items-table th { background: #eaf0fb; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.6rem 0.6rem; text-align: left; }
.line-items-table td { padding: 0.4rem 0.5rem; vertical-align: middle; }
.line-items-table td .form-control, .line-items-table td .form-select { padding: 0.45rem 0.6rem; font-size: 0.92rem; }
.line-items-table tfoot td { font-weight: 700; padding-top: 0.6rem; }
.line-item-remove { color: var(--danger); cursor: pointer; border: none; background: none; font-size: 1.1rem; }

/* ---------- Approval timeline ---------- */
.approval-timeline { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.approval-timeline .step {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
  background: #f1f5f9; color: var(--text-muted);
}
.approval-timeline .step.done { background: #dcfce7; color: #166534; }
.approval-timeline .step.current { background: #dbeafe; color: #1e40af; }
.approval-timeline .step.rejected { background: #fee2e2; color: #991b1b; }
.approval-timeline .sep { color: var(--border); font-size: 1.1rem; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0b1e3d 0%, #1d4ed8 55%, #06b6d4 100%);
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  animation: popIn 0.5s ease;
}
.login-card .brand-icon {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; margin: 0 auto 1rem;
}
.login-card .login-logo { display: block; max-width: 180px; max-height: 100px; margin: 0 auto 1rem; object-fit: contain; border-radius: 14px; }

/* ---------- Site footer credit ---------- */
.site-footer-credit {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; font-size: 0.85rem; color: #111827; font-weight: 600;
  background: #fff; border-top: 1px solid var(--border, #e2e8f0);
}

/* ---------- Misc ---------- */
.doc-chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--bg); padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.88rem; }
.section-icon { color: var(--primary); }
.invoice-box, .receipt-box { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 2rem; max-width: 800px; margin: 1.5rem auto; }
.invoice-box hr, .receipt-box hr { border-top: 2px dashed var(--border); }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state i { font-size: 2.6rem; color: var(--border); display: block; margin-bottom: 0.75rem; }

/* ---------- Animations ---------- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(14px);} to { opacity: 1; transform: translateY(0);} }
@keyframes popIn { from { opacity: 0; transform: scale(0.92);} to { opacity: 1; transform: scale(1);} }

/* ---------- Responsive ---------- */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 30, 61, 0.5);
  z-index: 1045;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.show { display: block; opacity: 1; }

@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    width: 82vw;
    max-width: 300px;
    z-index: 1050;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  #sidebarToggle { display: inline-flex; align-items: center; justify-content: center; }
  body.sidebar-open { overflow: hidden; }
}

@media (max-width: 768px) {
  html { font-size: 15px; }
  .topbar { padding: 0.65rem 0.9rem; }
  .topbar .d-flex.gap-3 { gap: 0.6rem !important; }
  .topbar > .d-flex:last-child { gap: 0.5rem !important; }
  .topbar .user-chip { padding: 0.25rem; background: transparent; }
  .topbar .user-chip > span { display: none; }
  .topbar .user-chip .avatar { width: 32px; height: 32px; }
  .topbar > .d-flex:last-child > .badge-soft { display: none; }
  .topbar .btn-sm { padding: 0.4rem 0.6rem; }

  .page-wrap { padding: 1rem 0.85rem 3.6rem; }
  .page-header { margin-bottom: 1rem; gap: 0.6rem; }
  .page-header h1 { font-size: 1.4rem; }
  .page-header > div { width: 100%; }
  .page-header > .btn { width: 100%; justify-content: center; }
  .page-header > .d-flex { width: 100%; flex-wrap: wrap; }
  .page-header > .d-flex > .btn { flex: 1 1 auto; justify-content: center; }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.15rem; }

  .card-body { padding: 1rem; }
  .card-header { padding: 0.9rem 1rem; font-size: 1rem; }
  .card.hoverable:hover { transform: none; }

  .stat-card { padding: 1rem 1.05rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  .stat-card .stat-icon { font-size: 1.5rem; }
  .stat-card .stat-label { font-size: 0.8rem; }
  .stat-card:hover { transform: none; }

  .table-responsive { -webkit-overflow-scrolling: touch; }
  table.app-table thead th { padding: 0.65rem 0.7rem; font-size: 0.76rem; white-space: nowrap; }
  table.app-table tbody td { padding: 0.65rem 0.7rem; font-size: 0.88rem; }
  table.app-table td.no-print { min-width: 118px; white-space: normal; }
  table.app-table td .btn-sm { padding: 0.35rem 0.5rem; }

  .form-section-title { margin: 1.4rem 0 0.9rem; font-size: 0.98rem; }
  .form-control, .form-select { font-size: 16px; }

  .invoice-box, .receipt-box { padding: 1.1rem; margin: 1rem auto; }

  .btn { padding: 0.5rem 0.95rem; }
  .fab-add { padding: 0.55rem 1rem; }

  .site-footer-credit { font-size: 0.7rem; padding: 7px 10px; }
}

/* ---------- Mobile: report filters + card-style tables ---------- */
.filter-toggle { display: none; }

@media (max-width: 767.98px) {
  .filter-toggle { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
  .filters-collapsible.is-collapsed { display: none; }
  form[method="get"] .col-auto { flex: 1 1 46%; }
  form[method="get"] .col-auto .form-control,
  form[method="get"] .col-auto .form-select { width: 100%; }
  form[method="get"] .form-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.15rem; }

  table.app-table.cards-mobile thead { display: none; }
  table.app-table.cards-mobile,
  table.app-table.cards-mobile tbody,
  table.app-table.cards-mobile tr,
  table.app-table.cards-mobile td { display: block; width: 100%; }
  table.app-table.cards-mobile tr {
    margin-bottom: 0.9rem;
    padding: 0.35rem 0.95rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  table.app-table.cards-mobile tbody tr:hover { background: var(--surface); }
  table.app-table.cards-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    text-align: right;
    white-space: normal;
    padding: 0.55rem 0 !important;
    border: none;
    border-bottom: 1px dashed var(--border);
    font-size: 0.9rem;
    min-width: 0;
  }
  table.app-table.cards-mobile td:last-child { border-bottom: none; }
  table.app-table.cards-mobile td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    color: var(--text-muted);
  }
  table.app-table.cards-mobile td.no-print { flex-wrap: wrap; justify-content: flex-end; }
  table.app-table.cards-mobile tr:has(td[colspan]) { border: none; box-shadow: none; background: transparent; }
  table.app-table.cards-mobile td[colspan] { justify-content: center; text-align: center; border-bottom: none; }
  table.app-table.cards-mobile td[colspan]::before { content: none; }
}

@media (max-width: 480px) {
  .topbar h5 { display: none !important; }
  .row.g-3, .row.g-2 { --bs-gutter-x: 0.65rem; }
}

@media print {
  .sidebar, .topbar, .sidebar-backdrop, .no-print { display: none !important; }
  .page-wrap { padding: 0; }
}

/* Hide the up/down spinner on every number input, app-wide. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
