/* ============================================================
   StockFlow – Main Stylesheet
   ============================================================ */

/* ── Fonts & Base ─────────────────────────────────────────── */
:root {
  --sf-sidebar-width: 260px;
  --sf-sidebar-bg: #0f172a;
  --sf-sidebar-text: #94a3b8;
  --sf-sidebar-hover: rgba(255,255,255,.06);
  --sf-sidebar-active: rgba(99,102,241,.2);
  --sf-sidebar-active-text: #818cf8;
  --sf-accent: #6366f1;
  --sf-accent-dark: #4f46e5;
  --sf-navbar-height: 64px;
  --sf-border: #e2e8f0;
  --sf-bg: #f1f5f9;
  --sf-card-bg: #ffffff;
  --sf-text: #1e293b;
  --sf-text-muted: #64748b;
  --sf-radius: 12px;
  --sf-radius-sm: 8px;
  --sf-shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 20px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--sf-bg);
  color: var(--sf-text);
  font-size: .925rem;
  line-height: 1.6;
}

/* ── Layout Wrapper ───────────────────────────────────────── */
.wrapper {
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sf-sidebar-width);
  min-width: var(--sf-sidebar-width);
  background: var(--sf-sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
  transition: width .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: white;
  flex-shrink: 0;
}

.brand-text { color: #f8fafc; }

.sidebar-nav {
  flex: 1;
  padding: .5rem .75rem;
}

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: rgba(148,163,184,.5);
  padding: 1.2rem 0.5rem .4rem;
  text-transform: uppercase;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: 8px;
  color: var(--sf-sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 450;
  margin-bottom: 2px;
  transition: all .15s ease;
  position: relative;
}

.sidebar-link i {
  font-size: 1.05rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-link:hover {
  background: var(--sf-sidebar-hover);
  color: #e2e8f0;
}

.sidebar-link.active {
  background: var(--sf-sidebar-active);
  color: var(--sf-sidebar-active-text);
  font-weight: 600;
}

.sidebar-link.active i { color: var(--sf-sidebar-active-text); }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.06);
}

.btn-sidebar-toggle {
  background: none;
  border: none;
  color: var(--sf-sidebar-text);
  padding: 4px 8px;
  cursor: pointer;
}

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

.content-area {
  flex: 1;
  min-height: calc(100vh - var(--sf-navbar-height));
}

/* ── Top Navbar ───────────────────────────────────────────── */
.top-navbar {
  height: var(--sf-navbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--sf-border);
  position: sticky;
  top: 0;
  z-index: 900;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

.page-title { color: var(--sf-text); }

/* ── Notification bell ────────────────────────────────────── */
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  background: #ef4444;
  color: #fff;
  border-radius: 8px;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.notif-menu { max-height: 360px; overflow-y: auto; }
.notif-list .notif-item { padding: .75rem 1rem; border-bottom: 1px solid var(--sf-border); }
.notif-list .notif-item:last-child { border-bottom: none; }
.notif-list .notif-item.unread { background: #f0f4ff; }

/* ── KPI Cards ────────────────────────────────────────────── */
.kpi-card {
  background: #fff;
  border-radius: var(--sf-radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--sf-shadow);
  height: 100%;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 0 var(--sf-radius) 0 80px;
  opacity: .08;
}

.kpi-primary::before  { background: #6366f1; }
.kpi-warning::before  { background: #f59e0b; }
.kpi-info::before     { background: #0ea5e9; }
.kpi-success::before  { background: #10b981; }
.kpi-danger::before   { background: #ef4444; }

.kpi-icon {
  font-size: 1.4rem;
  margin-bottom: .75rem;
}

.kpi-primary .kpi-icon  { color: #6366f1; }
.kpi-warning .kpi-icon  { color: #f59e0b; }
.kpi-info .kpi-icon     { color: #0ea5e9; }
.kpi-success .kpi-icon  { color: #10b981; }
.kpi-danger .kpi-icon   { color: #ef4444; }

.kpi-sub {
  font-size: .78rem;
  margin-top: .15rem;
  font-weight: 600;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--sf-text);
  line-height: 1.1;
}

.kpi-label {
  font-size: .8rem;
  color: var(--sf-text-muted);
  margin-top: .25rem;
  font-weight: 500;
}

.kpi-link {
  font-size: .75rem;
  text-decoration: none;
  margin-top: .75rem;
  display: inline-block;
  color: var(--sf-accent);
}

/* ── Avatar ───────────────────────────────────────────────── */
.avatar-sm {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.product-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .875rem;
  font-weight: 700;
  flex-shrink: 0;
}

.product-avatar-lg {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: white;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
}

/* ── Search dropdown ──────────────────────────────────────── */
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 2000;
  border-radius: 10px;
  max-height: 260px;
  overflow-y: auto;
}

.search-result-item {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--sf-border);
  cursor: pointer;
  transition: background .1s;
  text-decoration: none;
  color: var(--sf-text);
  display: block;
}

.search-result-item:hover { background: #f8fafc; }
.search-result-item:last-child { border-bottom: none; }

/* ── Tables ───────────────────────────────────────────────── */
.table { font-size: .875rem; }
.table th { font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--sf-text-muted); }
.table > :not(caption) > * > * { padding: .85rem .75rem; }

/* ── Cards ────────────────────────────────────────────────── */
.card { border-radius: var(--sf-radius); }
.card-header { font-size: .875rem; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn { font-weight: 500; border-radius: var(--sf-radius-sm); }
.btn-ghost { background: transparent; border: none; }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-xs { padding: .2rem .5rem; font-size: .72rem; border-radius: 5px; }

/* ── Form controls ────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: var(--sf-radius-sm);
  border-color: var(--sf-border);
  font-size: .875rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--sf-accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

/* ── Badges ───────────────────────────────────────────────── */
.badge { font-weight: 600; border-radius: 6px; }
.fs-xs { font-size: .65rem; }
.text-xs { font-size: .75rem; }

/* ── Auth pages ───────────────────────────────────────────── */
.auth-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-container {
  width: 100%;
  max-width: 420px;
}

.auth-card { width: 100%; }

.auth-logo-icon {
  width: 72px;
  height: 72px;
  background: rgba(99,102,241,.15);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(99,102,241,.3);
}

.auth-logo h1 { color: #f8fafc; }
.auth-logo p  { color: #94a3b8; }

/* ── Portal layout ────────────────────────────────────────── */
.portal-body { background: #f8fafc; }

.portal-navbar {
  background: #ffffff;
  border-bottom: 1px solid var(--sf-border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.portal-navbar .navbar-brand { color: var(--sf-text); }
.portal-navbar .nav-link { color: var(--sf-text-muted); font-weight: 500; }
.portal-navbar .nav-link:hover,
.portal-navbar .nav-link.active { color: var(--sf-accent); }

.portal-footer { background: #ffffff; border-top: 1px solid var(--sf-border); }

/* ── Portal order creation ────────────────────────────────── */
.product-pick-btn {
  border-radius: var(--sf-radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.product-pick-btn:hover {
  border-color: var(--sf-accent) !important;
  box-shadow: 0 0 0 2px rgba(99,102,241,.1);
}
.product-pick-btn.active {
  border-color: var(--sf-accent) !important;
  background: rgba(99,102,241,.05) !important;
  box-shadow: 0 0 0 2px rgba(99,102,241,.18);
}

/* ── Nav pills portal ─────────────────────────────────────── */
.nav-pills .nav-link { color: var(--sf-text-muted); font-weight: 500; }
.nav-pills .nav-link.active { background: var(--sf-accent); }

/* ── Utility ──────────────────────────────────────────────── */
code { background: #f1f5f9; padding: .15em .4em; border-radius: 5px; font-size: .82em; color: #e11d48; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    z-index: 1050;
    transition: left .25s ease;
  }

  .sidebar.open { left: 0; }

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

  .sidebar-overlay.show { display: block; }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kpi-card, .card { animation: fadeUp .35s ease both; }

/* ── Print ────────────────────────────────────────────────── */
@media print {
  .sidebar, .top-navbar, .btn, nav { display: none !important; }
  body { background: white; }
}
