/* AL SAFA MART POS - Core Application Styles */

* { box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition-base), color var(--transition-base);
}

a { text-decoration: none; }
::selection { background: var(--brand-emerald-light); color: var(--brand-green-900); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-full); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--gray-700); }

/* -------------------------------------------------------------- */
/* App Shell */
/* -------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--gradient-sidebar);
  color: rgba(255,255,255,0.85);
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: width var(--transition-base), transform var(--transition-base);
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0,0,0,0.12);
}
.sidebar.collapsed { width: var(--sidebar-width-collapsed); }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 1.08rem;
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 8px;
}
.sidebar-brand .brand-icon {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  background: var(--gradient-emerald);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-weight: 800;
  color: #04261c;
  box-shadow: var(--shadow-glow-emerald);
}

.sidebar-nav { padding: 8px 12px; flex: 1; }
.sidebar-section-title {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: .1em;
  color: rgba(255,255,255,0.38); padding: 18px 12px 6px;
  white-space: nowrap; overflow: hidden;
  font-weight: 700;
}
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-md);
  color: rgba(255,255,255,0.78);
  font-weight: 500; font-size: 0.9rem;
  margin-bottom: 2px;
  white-space: nowrap;
  position: relative;
  transition: background var(--transition-fast), color var(--transition-fast), padding-left var(--transition-fast);
}
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; flex-shrink: 0; }
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; padding-left: 16px; }
.sidebar-link.active {
  background: var(--gradient-emerald);
  color: #04261c; font-weight: 700;
  box-shadow: var(--shadow-glow-emerald);
}
.sidebar-link.active::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 60%; background: #fff; border-radius: 0 4px 4px 0; opacity: 0.9;
}
.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-brand .brand-text { display: none; }

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  transition: margin-left var(--transition-base);
}
.sidebar.collapsed ~ .main-content { margin-left: var(--sidebar-width-collapsed); }

.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 1020;
}
.topbar-search {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  display: flex; align-items: center; gap: 8px;
  width: 340px; max-width: 40vw;
}
.topbar-search input { border: none; background: transparent; outline: none; width: 100%; color: var(--text-primary); font-size: 0.88rem; }
.topbar-icon-btn {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-surface-alt); border: 1px solid var(--border-color);
  color: var(--text-secondary); position: relative; cursor: pointer;
  transition: all var(--transition-fast);
}
.topbar-icon-btn:hover { background: var(--gray-200); color: var(--text-primary); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .topbar-icon-btn:hover { background: var(--gray-700); }
.topbar-badge {
  position: absolute; top: -3px; right: -3px;
  background: var(--color-danger); color: #fff;
  font-size: 0.62rem; min-width: 16px; height: 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

/* Opacity-only (no transform): a transformed ancestor becomes the containing
   block for any position:fixed descendant (e.g. Bootstrap modals live inside
   .page-content), which breaks their viewport-relative sizing. Keep this
   fade transform-free so modals always size against the real viewport. */
.page-content { padding: 24px; animation: fadeIn 280ms ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* -------------------------------------------------------------- */
/* Cards */
/* -------------------------------------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 420ms cubic-bezier(0.4, 0, 0.2, 1) both;
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 16px 20px;
  font-weight: 600;
}
.card-body { padding: 20px; }

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 16px;
  transition: transform var(--transition-bounce), box-shadow var(--transition-base), border-color var(--transition-base);
  animation: fadeInUp 420ms cubic-bezier(0.4, 0, 0.2, 1) both;
  position: relative;
  overflow: hidden;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: transparent; }
.stat-icon {
  width: 52px; height: 52px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
  color: #fff;
  transition: transform var(--transition-bounce);
}
.stat-card:hover .stat-icon { transform: scale(1.08) rotate(-4deg); }
.stat-icon.bg-emerald { background: var(--gradient-emerald); box-shadow: 0 6px 16px -4px rgba(16,185,129,0.45); }
.stat-icon.bg-blue { background: var(--gradient-blue); box-shadow: 0 6px 16px -4px rgba(37,99,235,0.45); }
.stat-icon.bg-amber { background: var(--gradient-amber); box-shadow: 0 6px 16px -4px rgba(217,119,6,0.45); }
.stat-icon.bg-red { background: var(--gradient-red); box-shadow: 0 6px 16px -4px rgba(220,38,38,0.45); }
.stat-value { font-size: 1.55rem; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.stat-label { color: var(--text-secondary); font-size: 0.82rem; margin-bottom: 2px; font-weight: 500; }
.stat-trend { font-size: 0.78rem; font-weight: 600; }
.stat-trend.up { color: var(--color-success); }
.stat-trend.down { color: var(--color-danger); }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.row.g-3 > [class*="col-"]:nth-child(1) .stat-card, .row.g-3 > [class*="col-"]:nth-child(1) { animation-delay: 0ms; }
.row.g-3 > [class*="col-"]:nth-child(2) .stat-card, .row.g-3 > [class*="col-"]:nth-child(2) { animation-delay: 40ms; }
.row.g-3 > [class*="col-"]:nth-child(3) .stat-card, .row.g-3 > [class*="col-"]:nth-child(3) { animation-delay: 80ms; }
.row.g-3 > [class*="col-"]:nth-child(4) .stat-card, .row.g-3 > [class*="col-"]:nth-child(4) { animation-delay: 120ms; }

/* -------------------------------------------------------------- */
/* Buttons */
/* -------------------------------------------------------------- */
.btn { border-radius: var(--radius-md); font-weight: 500; padding: 8px 16px; font-size: 0.88rem; transition: all var(--transition-fast); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-primary {
  background: var(--gradient-emerald); border-color: transparent; color: #04261c; font-weight: 700;
  box-shadow: 0 4px 12px -2px rgba(16,185,129,0.4);
}
.btn-primary:hover {
  background: var(--gradient-emerald); border-color: transparent; color: #04261c;
  box-shadow: 0 6px 18px -2px rgba(16,185,129,0.55); transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-outline-primary { color: var(--brand-emerald-dark); border-color: var(--brand-emerald); }
.btn-outline-primary:hover { background: var(--gradient-emerald); border-color: transparent; color: #04261c; }
.btn-dark-soft { background: var(--gray-800); color: #fff; }

/* -------------------------------------------------------------- */
/* Tables */
/* -------------------------------------------------------------- */
.table-modern { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-modern thead th {
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em;
  font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
.table-modern tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; color: var(--text-primary); transition: background var(--transition-fast); }
.table-modern tbody tr { transition: background var(--transition-fast); }
.table-modern tbody tr:hover { background: var(--bg-surface-alt); }
.table-modern tbody tr:last-child td { border-bottom: none; }

/* -------------------------------------------------------------- */
/* Responsive editable item tables (e.g. purchase order line items) */
/* Desktop: normal table. Mobile: each row becomes a labeled card. */
/* -------------------------------------------------------------- */
@media (max-width: 768px) {
  .items-table thead { display: none; }
  .items-table, .items-table tbody, .items-table tr, .items-table td { display: block; width: 100% !important; }
  .items-table tbody tr {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin: 10px;
    padding: 6px 10px;
  }
  .items-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 2px;
    border-bottom: 1px dashed var(--border-color);
  }
  .items-table tbody td:last-child { border-bottom: none; }
  .items-table tbody td[data-label]::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-secondary);
    flex-shrink: 0;
  }
  .items-table tbody td[data-label=""]::before { content: none; }
  .items-table tbody td .form-control,
  .items-table tbody td .form-select { max-width: 60%; margin-left: auto; }
}

.badge-status { padding: 4px 10px; border-radius: var(--radius-full); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em; display: inline-flex; align-items: center; gap: 5px; }
.badge-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-status.active, .badge-status.completed, .badge-status.received, .badge-status.success { background: var(--brand-emerald-light); color: var(--brand-emerald-dark); }
.badge-status.inactive, .badge-status.cancelled, .badge-status.void { background: #fee2e2; color: #dc2626; }
.badge-status.pending, .badge-status.ordered, .badge-status.held { background: #fef3c7; color: #d97706; }
.badge-status.refunded, .badge-status.info { background: #dbeafe; color: #2563eb; }

/* -------------------------------------------------------------- */
/* Forms */
/* -------------------------------------------------------------- */
.form-control, .form-select {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  font-size: 0.88rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-emerald);
  box-shadow: 0 0 0 3px var(--brand-emerald-light);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.form-control-sm, .form-select-sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}
input[type="number"].form-control-sm::-webkit-outer-spin-button,
input[type="number"].form-control-sm::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"].form-control-sm {
  -moz-appearance: textfield;
}
.form-label { font-weight: 600; font-size: 0.82rem; margin-bottom: 6px; color: var(--text-primary); }
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus { box-shadow: 0 0 0 3px rgba(16,185,129,0.25); }

/* -------------------------------------------------------------- */
/* Auth (Login) Page */
/* -------------------------------------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  background: linear-gradient(135deg, var(--brand-green-900), var(--brand-green-700));
}
.auth-visual {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  padding: 60px; color: #fff;
  position: relative;
  overflow: hidden;
  background-image: radial-gradient(rgba(255,255,255,0.09) 1px, transparent 1px);
  background-size: 26px 26px;
}
.auth-visual::before {
  content: ''; position: absolute; inset: 0; background: var(--gradient-mesh); pointer-events: none;
}
.auth-visual::after {
  content: ''; position: absolute; width: 480px; height: 480px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.06) 0%, transparent 70%);
  top: -120px; right: -120px; pointer-events: none;
}
.auth-visual > * { position: relative; z-index: 1; }
.auth-visual h1 { font-size: 2.3rem; font-weight: 800; margin-bottom: 12px; letter-spacing: -0.02em; animation: fadeInUp 600ms ease both; }
.auth-visual p, .auth-visual > div { animation: fadeInUp 600ms ease 120ms both; }
.auth-form-wrap {
  width: 460px; max-width: 100%;
  background: var(--bg-surface);
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  box-shadow: -12px 0 40px rgba(0,0,0,0.08);
}
.auth-card { width: 100%; max-width: 360px; animation: fadeInUp 500ms cubic-bezier(0.4,0,0.2,1) 80ms both; }
.auth-logo {
  width: 56px; height: 56px; border-radius: var(--radius-md); background: var(--gradient-emerald);
  display: flex; align-items: center; justify-content: center; color: #04261c; font-weight: 800; font-size: 1.4rem;
  margin-bottom: 18px; box-shadow: var(--shadow-glow-emerald);
  animation: fadeInUp 500ms cubic-bezier(0.4,0,0.2,1) both;
}

/* -------------------------------------------------------------- */
/* Utilities */
/* -------------------------------------------------------------- */
.text-muted-soft { color: var(--text-secondary) !important; }
.shadow-soft { box-shadow: var(--shadow-md) !important; }
.rounded-xl { border-radius: var(--radius-lg) !important; }
.fw-semibold { font-weight: 600; }
.divider { border-top: 1px solid var(--border-color); }

.theme-toggle-track {
  width: 44px; height: 24px; background: var(--gray-300); border-radius: 999px;
  position: relative; cursor: pointer; transition: background var(--transition-fast);
}
[data-theme="dark"] .theme-toggle-track { background: var(--brand-emerald); }
.theme-toggle-thumb {
  width: 18px; height: 18px; background: #fff; border-radius: 50%;
  position: absolute; top: 3px; left: 3px; transition: left var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .theme-toggle-thumb { left: 23px; }

/* Toasts */
.toast-container-custom { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast-item {
  background: var(--bg-surface); border: 1px solid var(--border-color); border-left: 4px solid var(--brand-emerald);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 12px 16px; min-width: 280px;
  display: flex; align-items: flex-start; gap: 10px; animation: slideIn .25s ease;
}
.toast-item.danger { border-left-color: var(--color-danger); }
.toast-item.warning { border-left-color: var(--color-warning); }
.toast-item.info { border-left-color: var(--color-info); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Loading skeleton */
.skeleton { background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 37%, var(--gray-200) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* -------------------------------------------------------------- */
/* Modal positioning: keep dialogs clear of the docked sidebar.
   Bootstrap centers .modal-dialog within the full viewport by default;
   on desktop widths narrower than roughly 1330px a centered modal-lg
   mathematically extends left of x=264px (the sidebar's width), so the
   sidebar's own stacking context visibly overlaps the dialog there. Fix
   it at the source: on desktop, modals in the sidebar layout are only
   centered within the space to the right of the sidebar.
   app.js relocates every .modal to a direct child of <body> before init
   (see assets/js/app.js — fixes real mouse clicks landing on the
   backdrop instead of the dialog, a separate bug from this one), so this
   can no longer be scoped with a `.app-shell .modal` descendant selector;
   `body:has(.app-shell)` detects "this is a sidebar-layout page" instead.
   Standalone pages without a sidebar (login/POS) don't match and keep
   Bootstrap's normal full-width centering. */
/* -------------------------------------------------------------- */
@media (min-width: 992px) {
  body:has(.app-shell) .modal {
    left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
  }
}

/* -------------------------------------------------------------- */
/* Responsive */
/* -------------------------------------------------------------- */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-width); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content, .sidebar.collapsed ~ .main-content { margin-left: 0; }
  .topbar-search { display: none; }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1025; }
  .sidebar-backdrop.show { display: block; }
  .auth-visual { display: none; }
  .auth-form-wrap { width: 100%; }
}
@media (max-width: 576px) {
  .page-content { padding: 14px; }
}
