@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --brand-primary: #2563eb;
  --brand-primary-hover: #1d4ed8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 0.5rem;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--surface-muted);
}

/* Legacy compatibility */
.table-fs {
  font-size: 12px;
}

.pagination {
  --bs-pagination-padding-x: 0.45rem;
  --bs-pagination-padding-y: 0.15rem;
  --bs-pagination-font-size: 12px;
  font-size: 12px;
  margin-bottom: 0;
}

.pagination .page-link {
  font-size: 12px;
  line-height: 1.25;
}

.app-main .form-label,
.app-main .input-group-text,
.app-main .form-check-label {
  font-size: 12px;
}

.app-main .form-label.mb-0 + span {
  font-size: 12px;
}

.app-main .input-group-text {
  padding: 0.2rem 0.5rem;
}

.app-main .app-page .btn:not(.btn-close):not(.btn-xs),
.app-main .modal .btn:not(.btn-close):not(.btn-xs) {
  font-size: 12px;
  padding: 0.25rem 0.5rem;
  line-height: 1.5;
}

.app-main .app-page .btn-xs,
.app-main .modal .btn-xs {
  padding: 0.15rem 0.35rem;
  font-size: 11px;
  line-height: 1.2;
}

.app-main .form-control,
.app-main .form-select,
.app-main .form-control-sm,
.app-main .form-select-sm {
  font-size: 12px;
  padding: 0.25rem 0.5rem;
  min-height: calc(1.5em + 0.5rem + 2px);
}

.app-main textarea.form-control {
  min-height: calc(4.5em + 0.5rem + 2px);
}

.app-main .form-control-color {
  min-height: 2rem;
  padding: 0.15rem;
}

.app-main .form-section h6,
.app-main .card-app > .card-header {
  font-size: 13px;
}

.app-main .modal-title {
  font-size: 0.95rem;
}

.table.table-sm,
.table.table-bordered {
  font-size: 12px;
}

.table.table-sm > :not(caption) > * > * {
  padding: 0.2rem 0.35rem;
}

.btn-xs {
  padding: 0.25rem 0.4rem;
  font-size: 0.75rem;
  line-height: 1;
  border-radius: 0.25rem;
}

.table-clrB { background-color: #dbeafe; }
.table-clrG { background-color: #dcfce7; }
.table-clrR { background-color: #fee2e2; }
.table-clrY { background-color: #fef9c3; }

.bg-color,
.btn-color {
  background-color: var(--brand-primary) !important;
  border-color: var(--brand-primary) !important;
  color: #fff !important;
}

.bg-color:hover,
.btn-color:hover,
.btn-brand:hover {
  background-color: var(--brand-primary-hover) !important;
  border-color: var(--brand-primary-hover) !important;
  color: #fff !important;
}

.txt-color {
  color: var(--brand-primary) !important;
}

.btn-brand {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

.btn-brand:hover {
  background-color: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
  color: #fff;
}

.btn-outline-brand {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}

.btn-outline-brand:hover {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: #fff;
}

/* App layout */
.app-shell {
  min-height: 100vh;
}

.app-main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: width 0.2s ease, min-width 0.2s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

.app-sidebar .sidebar-brand img {
  max-height: 56px;
  object-fit: contain;
}

.app-sidebar.collapsed .sidebar-brand-text,
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .nav-group-label,
.app-sidebar.collapsed .sidebar-user-info,
.app-sidebar.collapsed .sidebar-footer-text {
  display: none !important;
}

.app-sidebar.collapsed .nav-link-app {
  justify-content: center;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.app-sidebar.collapsed .nav-link-app i {
  margin-right: 0 !important;
}

.nav-group-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-link-app {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.75rem;
  margin: 0.125rem 0.5rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.nav-link-app:hover {
  background: var(--surface-muted);
  color: var(--brand-primary);
}

.nav-link-app.active {
  background: rgba(var(--bs-primary-rgb), 0.1);
  color: var(--brand-primary);
  border-left-color: var(--brand-primary);
  font-weight: 600;
}

.sidebar-user {
  padding: 0.75rem;
  margin: 0.5rem;
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.sidebar-toggle {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.sidebar-toggle:hover {
  background: var(--surface-muted);
  color: var(--text);
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 1020;
}

.app-header-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.app-header-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
}

.app-header-action,
.app-header-user {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  line-height: 1.2;
}

.app-header-action {
  gap: 0.35rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.app-header-action i {
  line-height: 1;
  font-size: 0.95rem;
}

/* Page header */
.page-header {
  margin-bottom: 1.25rem;
}

.page-header__title {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--text);
}

.page-header__subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

/* Cards */
.card-app {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-sm);
}

.card-app .card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: 0.875rem 1rem;
}

.card-app .card-body {
  padding: 1rem;
}

.card-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  height: 100%;
}

.card-stat--primary {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover));
  border: none;
  color: #fff;
}

.card-stat--success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  border: none;
  color: #fff;
}

.card-stat--danger {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  border: none;
  color: #fff;
}

.card-stat--purple {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none;
  color: #fff;
}

.card-stat--amber {
  background: linear-gradient(135deg, #d97706, #b45309);
  border: none;
  color: #fff;
}

.card-stat--info {
  background: linear-gradient(135deg, #0891b2, #0e7490);
  border: none;
  color: #fff;
}

.card-stat--slate {
  background: linear-gradient(135deg, #475569, #334155);
  border: none;
  color: #fff;
}

.card-stat__label {
  font-size: 0.75rem;
  opacity: 0.92;
  margin-bottom: 0.2rem;
}

.card-stat__value {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.dash-chart {
  position: relative;
  height: 240px;
}

.dash-chart--sm {
  height: 200px;
}

.dash-table td,
.dash-table th {
  font-size: 12px;
  vertical-align: middle;
}

/* Filter bar */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

/* Tables */
.table-app {
  font-size: 12px;
}

.table-app thead th {
  background: var(--surface-muted);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
}

.table-app tbody tr:hover {
  background-color: rgba(var(--bs-primary-rgb), 0.04);
}

.table-responsive-app {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

/* Forms */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.form-control:focus,
.form-select:focus,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus {
  border-color: var(--bs-border-color);
  box-shadow: none;
  outline: 0;
}

.form-control.border-dark:focus,
.form-select.border-dark:focus {
  border-color: var(--bs-dark);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

/* Sign in */
.signin-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #2a1810 url("../images/signin-bg.png") center / cover no-repeat;
}

.signin-page::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(42, 24, 16, 0.5) 0%, rgba(20, 10, 8, 0.82) 100%);
  pointer-events: none;
  z-index: 0;
}

.signin-hero,
.signin-form-pane {
  position: relative;
  z-index: 1;
}

.signin-hero {
  color: #fff;
  padding: 2rem 1.25rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.signin-hero-content {
  max-width: 460px;
  width: 100%;
}

.signin-hero-logo {
  max-height: 64px;
  margin-bottom: 0.85rem;
}

.signin-hero-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.signin-hero-copy,
.signin-hero-list {
  display: none;
}

.signin-hero-tagline {
  opacity: 0.8;
  font-size: 0.85rem;
  margin: 0;
}

.signin-form-pane {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex: 1;
  padding: 0.75rem 1.15rem 1.75rem;
}

.signin-card {
  max-width: 420px;
  width: 100%;
}

.signin-card-inner {
  background: #fff;
  border-radius: 1.25rem;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  padding: 1.5rem 1.25rem 1.35rem;
}

.signin-input {
  position: relative;
}

.signin-input > i {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  z-index: 2;
}

.signin-input .form-control {
  padding-left: 2.4rem;
  padding-right: 2.6rem;
  border-radius: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  min-height: 2.75rem;
  box-shadow: none;
}

.signin-input .form-control:focus {
  background: #fff;
  border-color: var(--brand-primary);
  box-shadow: none;
}

.signin-input .password-toggle-btn {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: #94a3b8;
  z-index: 2;
  box-shadow: none;
}

.signin-submit {
  border-radius: 0.75rem;
  min-height: 2.75rem;
  font-weight: 600;
}

.signin-powered {
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  margin: 1rem 0 0;
}

.password-toggle-btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

@media (min-width: 992px) {
  .signin-page {
    flex-direction: row;
    background: #f4f6fb;
  }

  .signin-page::before {
    display: none;
  }

  .signin-hero {
    position: relative;
    width: 50%;
    min-height: 100vh;
    padding: 3.5rem;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    background: #2a1810 url("../images/signin-bg.png") center / cover no-repeat;
  }

  .signin-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(42, 24, 16, 0.45) 0%, rgba(20, 10, 8, 0.78) 100%);
  }

  .signin-hero-content {
    position: relative;
    z-index: 1;
  }

  .signin-hero-logo {
    max-height: 72px;
    margin-bottom: 1.75rem;
  }

  .signin-hero-title {
    font-size: 2.25rem;
    margin-bottom: 0.75rem;
  }

  .signin-hero-copy {
    display: block;
    font-size: 1rem;
    line-height: 1.6;
    opacity: 0.9;
    margin-bottom: 1.5rem;
  }

  .signin-hero-list {
    display: block;
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem;
  }

  .signin-hero-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin-bottom: 0.65rem;
    font-size: 0.95rem;
  }

  .signin-hero-list i {
    color: #f4c27a;
    margin-top: 0.15rem;
  }

  .signin-hero-tagline {
    font-size: 0.9rem;
    opacity: 0.75;
  }

  .signin-form-pane {
    width: 50%;
    min-height: 100vh;
    align-items: center;
    background: #f4f6fb;
    padding: 2rem 1rem;
  }

  .signin-card-inner {
    padding: 2rem 1.75rem;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  }

  .signin-powered {
    color: #64748b;
    margin-top: 1.5rem;
  }
}

/* Loading */
.btn.is-loading {
  pointer-events: none;
  opacity: 0.75;
}

/* Modal */
.modal-header-app {
  background: var(--text);
  color: #fff;
}

/* Scrollbar */
.app-sidebar,
.app-main,
.offcanvas-body {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.app-sidebar::-webkit-scrollbar,
.app-main::-webkit-scrollbar {
  width: 6px;
}

.app-sidebar::-webkit-scrollbar-thumb,
.app-main::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* Form stack inside cards (no row required) */
.form-stack .mb-field {
  margin-bottom: 0.75rem;
}

.form-stack .mb-field:last-child {
  margin-bottom: 0;
}

.card-app.p-3 {
  padding: 1rem;
}

.page-content-card .filter-bar {
  margin-bottom: 1rem;
}

.page-content-card .table-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.select2-container--default .select2-selection--single {
  border-radius: var(--radius) !important;
  border-color: var(--border) !important;
  min-height: 38px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 36px !important;
}

.stock-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.stock-legend-swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 2px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  flex-shrink: 0;
}

.stock-legend-swatch--expired,
.stock-expired {
  background-color: #fca5a5 !important;
}

.stock-legend-swatch--expiring,
.stock-expiring {
  background-color: #fde047 !important;
}

.stock-legend-swatch--low,
.stock-low {
  background-color: #93c5fd !important;
}

.table-hover > tbody > tr.stock-expired > *,
.table tbody tr.stock-expired > * {
  background-color: #fca5a5 !important;
  --bs-table-bg-state: #fca5a5;
  --bs-table-accent-bg: #fca5a5;
}

.table-hover > tbody > tr.stock-expired:hover > * {
  background-color: #f87171 !important;
}

.table-hover > tbody > tr.stock-expiring > *,
.table tbody tr.stock-expiring > * {
  background-color: #fde047 !important;
  --bs-table-bg-state: #fde047;
  --bs-table-accent-bg: #fde047;
}

.table-hover > tbody > tr.stock-expiring:hover > * {
  background-color: #facc15 !important;
}

.table-hover > tbody > tr.stock-low > *,
.table tbody tr.stock-low > * {
  background-color: #93c5fd !important;
  --bs-table-bg-state: #93c5fd;
  --bs-table-accent-bg: #93c5fd;
}

.table-hover > tbody > tr.stock-low:hover > * {
  background-color: #60a5fa !important;
}

.app-main .table .btn-image-icon,
.app-main .table .btn-image-icon:hover,
.app-main .table .btn-image-icon:focus,
.app-main .table .btn-image-icon:active,
.app-main .table .btn:has(.bi-image),
.app-main .table .btn:has(.bi-image):hover,
.app-main .table .btn:has(.bi-image):focus,
.app-main .table .btn:has(.bi-image):active,
.table-hover > tbody > tr:hover .btn-image-icon,
.table-hover > tbody > tr:hover .btn:has(.bi-image) {
  color: #0f172a !important;
  border-color: #1e293b !important;
  background-color: #fff !important;
  box-shadow: none !important;
}

.app-main .table .btn-image-icon:hover,
.app-main .table .btn:has(.bi-image):hover {
  background-color: #f1f5f9 !important;
}

.pos-dense .form-control,
.pos-dense .form-select {
  border-radius: 0;
}

.table-responsive,
.table-responsive-app {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.app-main .row > * {
  min-width: 0;
}

.app-main .form-control,
.app-main .form-select {
  max-width: 100%;
}

.stock-update-row .input-group-text {
  white-space: nowrap;
}

.stock-update-row .form-control {
  min-width: 0;
}

@media (max-width: 991.98px) {
  .app-header {
    padding: 0.5rem 1rem;
  }

  .app-header-action {
    min-height: 2.25rem;
    padding: 0.3rem 0.5rem;
  }

  .app-main .table thead th,
  .app-main .table tbody td {
    white-space: nowrap;
  }

  .app-main .input-group {
    flex-wrap: nowrap;
  }

  .app-main .input-group-text {
    white-space: nowrap;
  }

  .app-main .input-group > .form-control,
  .app-main .input-group > .form-select {
    min-width: 0;
  }

  .filter-bar {
    padding: 0.75rem;
  }

  .card-stat {
    padding: 0.85rem;
  }

  .card-stat__value {
    font-size: 1rem;
  }

  .dash-chart {
    height: 200px;
  }

  .dash-chart--sm {
    height: 180px;
  }

  .modal-dialog {
    margin: 0.75rem;
  }

  .pagination {
    flex-wrap: wrap;
    row-gap: 0.25rem;
  }

  .card-header.d-flex {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .app-main [style*="position: sticky"] {
    position: relative !important;
  }

  .app-main .row[style*="max-height"] {
    max-height: none !important;
    overflow: visible !important;
  }
}

@media (max-width: 575.98px) {
  .app-header-user {
    min-height: 2.25rem;
    padding: 0.2rem 0.35rem;
  }

  .form-section {
    padding: 0.75rem;
  }

  .card-app .card-body {
    padding: 0.75rem;
  }
}

@media (min-width: 992px) {
  .app-page {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    padding-top: 0.15rem;
  }

  .app-header {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .app-page .container-fluid {
    --bs-gutter-x: 0.5rem;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .app-page .container-fluid > .row {
    --bs-gutter-x: 0.5rem;
    margin-left: 0;
    margin-right: 0;
  }

  .app-page .px-3,
  .app-page .px-1 {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .app-page .pt-3 {
    padding-top: 0.35rem !important;
  }

  .app-page .mt-4 {
    margin-top: 0.75rem !important;
  }

  .app-page .mb-4 {
    margin-bottom: 0.75rem !important;
  }

  .app-page .table,
  .app-page .table-responsive,
  .app-page .table-responsive-app {
    width: 100%;
  }
}

.history-filter-accordion .accordion-button {
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
}

.history-filter-accordion .accordion-button:not(.collapsed) {
  background: var(--surface-muted);
  color: var(--text);
  box-shadow: none;
}

.history-filter-accordion .accordion-button:focus {
  box-shadow: none;
  border-color: var(--border);
}

@media (max-width: 991.98px) {
  .history-filter-accordion {
    margin-top: 0.5rem !important;
    margin-bottom: 0.5rem !important;
  }
}

@media (min-width: 992px) {
  .history-filter-accordion {
    margin-top: 0 !important;
  }

  .history-filter-accordion .accordion-item {
    border: 0;
    background: transparent;
  }

  .history-filter-accordion .accordion-collapse {
    display: block !important;
    height: auto !important;
    visibility: visible !important;
  }

  .history-filter-accordion .accordion-body {
    padding: 0 !important;
  }
}
