/* Wall Sheet Inventory & Sales Management System - design system */

:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --success: #047857;
  --warning: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, .15);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }

.hidden { display: none !important; }

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #14b8a6);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.brand .logo svg {
  width: 20px;
  height: 20px;
}

.brand small { display: block; font-weight: 500; font-size: 11px; color: #94a3b8; }

.nav { padding: 10px 0; flex: 1; }

.nav-section-label {
  padding: 12px 18px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #64748b;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .15s;
}

.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: rgba(15, 118, 110, .25); border-left-color: var(--primary); color: #fff; }
.nav-link .ic {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: inherit;
  transition: background .18s ease, color .18s ease;
}

.nav-link .ic svg {
  width: 24px;
  height: 24px;
  display: block;
}

.nav-link:hover .ic {
  background: rgba(255, 255, 255, 0.16);
}

.nav-link.active .ic {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.35);
}

.sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 12px;
  color: #94a3b8;
}

/* ---------- Main column ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 12.5px;
}

.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px;
}

.role-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.menu-btn {
  display: none;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 17px; cursor: pointer; color: var(--text);
}

.content { padding: 22px; flex: 1; max-width: 1200px; width: 100%; margin: 0 auto; }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

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

.card-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 18px; }

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 2px solid rgba(15, 118, 110, .45);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.stat .value.neg { color: var(--danger); }
.stat .value.pos { color: var(--success); }
.stat .sub-note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.warn { border-color: var(--warning); }
.stat.danger-t { border-color: var(--danger); }

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

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

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }

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

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty-row td { text-align: center; color: var(--muted); padding: 28px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-subtle {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-subtle:hover { background: var(--border); color: var(--text); }

.btn-outline { background: transparent; color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); color: var(--primary-dark); }

.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #991b1b; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }

.field label .req { color: var(--danger); }

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

.inline-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-row .field { flex: 1; min-width: 140px; margin-bottom: 0; }

/* ---------- Chips / alerts ---------- */
.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.chip-ok { background: #dcfce7; color: var(--success); }
.chip-warn { background: #fef3c7; color: var(--warning); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.chip-muted { background: var(--surface-2); color: var(--muted); }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid transparent;
}

.alert-warn { background: #fffbeb; border-color: #fde68a; color: var(--warning); }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.alert-ok { background: #f0fdf4; border-color: #bbf7d0; color: var(--success); }

.banner-low {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.banner-low b { color: var(--warning); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 80;
}

.toast {
  background: var(--text);
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  max-width: 320px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warning); }

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

/* ---------- Login ---------- */
.auth-holder {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f172a 0%, #134e4a 100%);
  padding: 18px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  padding: 34px 32px;
}

.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #14b8a6);
  display: grid;
  place-items: center;
  color: #fff;
}

.login-brand .logo svg {
  width: 30px;
  height: 30px;
}
.login-brand h1 { margin: 0 0 4px; font-size: 20px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 13px; }

.login-card .btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }

.form-error {
  display: none;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}
.form-error.show { display: block; }

/* ---------- Misc ---------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0 0 4px; font-size: 20px; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }

.kpi-pos { color: var(--success); }
.kpi-neg { color: var(--danger); }

.pld table td, .pld table th { white-space: normal; }

.spinner {
  display: grid;
  place-items: center;
  padding: 60px;
  color: var(--muted);
}

.spinner::before {
  content: "";
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin .7s linear infinite;
  margin-right: 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.plain-link { color: var(--primary); cursor: pointer; font-weight: 600; }
.muted { color: var(--muted); }
.fs-12 { font-size: 12.5px; }

footer.credits { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }

  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 45; }

  .topbar { padding: 0 14px; height: 54px; }
  .topbar h1 { font-size: 15px; }
  .content { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .user-chip .name { display: none; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 19px; }
}
/* ---------- Print ---------- */
.print-hdr { display: none; }

@media print {
  body { background: #fff; color: #000; }
  .sidebar, .topbar, #sidebar-backdrop, #modal-root, #toast-root,
  .menu-btn, .credits, .page-head .btn, #f-refresh, #btn-print,
  .inline-row, [data-tab] { display: none !important; }
  .app, .main, .content { display: block !important; padding: 0 !important; margin: 0 !important; }
  #content { overflow: visible !important; }
  .print-hdr { display: block !important; font-weight: 700; font-size: 15px; margin-bottom: 12px; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .card-body { padding: 10px; }
  .table-wrap table { font-size: 12px; }
}

/* Product photos */
.prod-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; display: inline-block; vertical-align: middle; background: var(--surface-2); }
.prod-thumb.empty { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.prod-preview-wrap { display: block; margin-top: 6px; }
.prod-preview { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.prod-preview.empty { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.checkbox-inline { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
