/* ============================================================
   S2Delta Inventory System — Stylesheet
   ============================================================ */

:root {
  --navy:       #1a1a2e;
  --navy-light: #16213e;
  --accent:     #e94560;
  --green:      #2ecc71;
  --yellow:     #f1c40f;
  --orange:     #e67e22;
  --red:        #e74c3c;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-300:   #d1d5db;
  --gray-500:   #6b7280;
  --gray-700:   #374151;
  --gray-900:   #111827;
  --white:      #ffffff;
  --sidebar-w:  240px;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md:  0 4px 6px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--gray-900);
  background: var(--gray-100);
  line-height: 1.5;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-brand h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.3;
}

.sidebar-brand p {
  font-size: 11px;
  color: rgba(255,255,255,.5);
  margin-top: 2px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
}

.nav-section {
  padding: 8px 18px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.35);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.75);
  font-size: 13.5px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: rgba(255,255,255,.08);
  color: var(--white);
  text-decoration: none;
}

.nav-link.active {
  background: rgba(233,69,96,.15);
  color: var(--white);
  border-left-color: var(--accent);
}

.nav-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px;
  color: rgba(255,255,255,.5);
}

.sidebar-footer a { color: rgba(255,255,255,.6); }
.sidebar-footer a:hover { color: var(--white); }

/* ── MAIN CONTENT ──────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.topbar h2 { font-size: 17px; font-weight: 600; color: var(--gray-900); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--gray-500);
}

.page-body {
  padding: 24px 28px;
  flex: 1;
}

/* ── CARDS ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

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

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--navy);
}

.stat-card.green  { border-left-color: var(--green); }
.stat-card.yellow { border-left-color: var(--yellow); }
.stat-card.red    { border-left-color: var(--red); }
.stat-card.orange { border-left-color: var(--orange); }

.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--gray-500); letter-spacing: .06em; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); margin-top: 4px; line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ── TABLES ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--gray-50);
  color: var(--gray-700);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

/* Row highlight states */
tr.row-new     { background: #fffde7 !important; }
tr.row-low     { background: #fff8e1 !important; }
tr.row-out     { background: #fce4ec !important; }
tr.row-history { background: var(--gray-100) !important; color: var(--gray-500); }

/* ── BADGES ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-green   { background: #d1fae5; color: #065f46; }
.badge-yellow  { background: #fef9c3; color: #854d0e; }
.badge-red     { background: #fee2e2; color: #991b1b; }
.badge-gray    { background: var(--gray-200); color: var(--gray-700); }
.badge-orange  { background: #ffedd5; color: #9a3412; }
.badge-navy    { background: var(--navy); color: var(--white); }
.badge-blue    { background: #dbeafe; color: #1e40af; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s, box-shadow .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { opacity: .75; }

.btn-primary  { background: var(--navy);   color: var(--white); }
.btn-accent   { background: var(--accent); color: var(--white); }
.btn-success  { background: var(--green);  color: var(--white); }
.btn-warning  { background: var(--orange); color: var(--white); }
.btn-danger   { background: var(--red);    color: var(--white); }
.btn-outline  { background: transparent; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── FORMS ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 5px; }
.form-label .required { color: var(--red); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,26,46,.1);
}

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── ALERTS / FLASH MESSAGES ───────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13.5px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--green); }
.alert-error   { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--red); }
.alert-warning { background: #fef9c3; color: #854d0e; border-left: 4px solid var(--yellow); }
.alert-info    { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }

/* ── FILTERS BAR ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--white);
  padding: 16px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar .form-group { margin-bottom: 0; min-width: 140px; }

/* ── STOCK LEVEL INDICATOR ──────────────────────────────────── */
.qty-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 3px 8px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 13px;
}

.qty-ok   { background: #d1fae5; color: #065f46; }
.qty-low  { background: #fef9c3; color: #854d0e; }
.qty-out  { background: #fee2e2; color: #991b1b; }
.qty-hist { background: var(--gray-200); color: var(--gray-500); }

/* ── CHANGE INDICATOR ───────────────────────────────────────── */
.change-pos { color: var(--green); font-weight: 600; }
.change-neg { color: var(--red);   font-weight: 600; }
.change-zero{ color: var(--gray-500); }

/* ── RECENT CHANGE PULSE (DASHBOARD) ───────────────────────── */
@keyframes recentPulse {
  0%   { box-shadow: 0 0 0 0 rgba(241,196,15,.5); }
  70%  { box-shadow: 0 0 0 6px rgba(241,196,15,0); }
  100% { box-shadow: 0 0 0 0 rgba(241,196,15,0); }
}
tr.recently-changed { animation: recentPulse 2s ease-out; }

/* ── PAGINATION ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 16px;
}

.page-link {
  padding: 5px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-size: 13px;
  color: var(--gray-700);
}

.page-link.active {
  background: var(--navy);
  color: var(--white);
  border-color: var(--navy);
}

.page-link:hover:not(.active) { background: var(--gray-100); text-decoration: none; }

/* ── LOGIN PAGE ─────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
}

.login-box {
  background: var(--white);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

.login-box h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}

.login-box p { font-size: 13px; color: var(--gray-500); margin-bottom: 24px; }

/* ── UTILITY ────────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--gray-500); }
.text-small  { font-size: 12px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.w-100 { width: 100%; }
.monospace { font-family: 'Courier New', monospace; font-size: 12px; }

/* ── SYNC LOG PRE ───────────────────────────────────────────── */
.log-output {
  background: var(--gray-900);
  color: #a8ff78;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  padding: 16px;
  border-radius: var(--radius);
  max-height: 360px;
  overflow-y: auto;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── DEBUG PANEL ────────────────────────────────────────────── */
.debug-section {
  border: 2px dashed var(--orange);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  background: #fff8f0;
}

.debug-section .debug-title {
  font-weight: 700;
  color: var(--orange);
  margin-bottom: 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── TEST RUNNER ────────────────────────────────────────────── */
.test-pass { color: var(--green); font-weight: 600; }
.test-fail { color: var(--red);   font-weight: 600; }
.test-skip { color: var(--gray-500); }

/* ── REUSABLE RESPONSIVE GRIDS ──────────────────────────────── */
/* Sidebar-form pages (SKU Manager): 2fr/1fr when a form is present, else 1 col */
.grid-2fr-1fr { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
.grid-2fr-1fr.has-side { grid-template-columns: 2fr 1fr; }

/* Even two-column pages (BC Sync pull/push cards) */
.grid-2-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

/* ── MOBILE SIDEBAR TOGGLE (hamburger) ─────────────────────── */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-900);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--gray-100); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 90;
}
.sidebar-overlay.open { display: block; }

/* ── MODAL (SKU edit, etc.) ─────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--white);
  border-radius: 12px;
  padding: 28px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-2fr-1fr.has-side { grid-template-columns: 1fr; }
  .grid-2-equal { grid-template-columns: 1fr; }

  .sidebar-toggle { display: inline-flex; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar h2 { font-size: 15px; }
  .page-body { padding: 16px; }
  .card { padding: 16px 18px; }
  .filter-bar { padding: 12px 14px; }
  .filter-bar .form-group { min-width: 100%; }
  .btn-group { width: 100%; }
  .modal-box { padding: 20px; width: 100%; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar-right span:first-child { display: none; } /* hide date, keep role badge */
  .topbar h2 { font-size: 14px; }
  .txn-group-header { flex-wrap: wrap; gap: 10px; }
}
