/* ============================================================
   B2B Portal — Design System
   Premium aesthetic with Plus Jakarta Sans typography
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

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

:root {
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
  --primary: #6366f1; --primary-hover: #4f46e5; --primary-dark: #3730a3;
  --primary-light: #a5b4fc; --primary-surface: #eef2ff;
  --accent: #06b6d4; --success: #10b981; --success-surface: #ecfdf5;
  --danger: #ef4444; --danger-surface: #fef2f2;
  --warning: #f59e0b; --warning-surface: #fffbeb;
  --bg: #f8fafc; --surface: #ffffff; --surface-raised: #ffffff;
  --text: #0f172a; --text-secondary: #64748b; --text-tertiary: #94a3b8;
  --border: #e2e8f0; --border-light: #f1f5f9;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px; --radius-xl: 20px;
}

html { font-size: 15px; scroll-behavior: smooth; overflow-x: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--primary); text-decoration: none; transition: color .2s; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; display: block; }

/* ── LOGIN PAGE ──────────────────────────────────── */
.login-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
  padding: 20px; position: relative; overflow: hidden;
}
.login-wrapper::before {
  content: ''; position: absolute; width: 600px; height: 600px; border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,0.15), transparent 70%);
  top: -200px; right: -100px;
}
.login-wrapper::after {
  content: ''; position: absolute; width: 400px; height: 400px; border-radius: 50%;
  background: radial-gradient(circle, rgba(6,182,212,0.1), transparent 70%);
  bottom: -100px; left: -50px;
}
.login-card {
  background: var(--surface); border-radius: var(--radius-xl); padding: 48px 40px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-xl); position: relative; z-index: 1;
}
.login-card h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 6px; color: var(--text); }
.login-card .subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: .95rem; }
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-card .logo-img { height: 48px; width: auto; object-fit: contain; }

/* ── FORM ELEMENTS ───────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: 600; font-size: .85rem; color: var(--text); margin-bottom: 6px; letter-spacing: .02em; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: .95rem; color: var(--text); background: var(--bg);
  transition: border-color .2s, box-shadow .2s; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm); font-family: var(--font);
  font-weight: 600; font-size: .9rem; cursor: pointer; border: none;
  transition: all .2s ease; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); border-color: var(--text-tertiary); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: .82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }

/* ── STICKY HEADER ───────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 100; background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  padding: 0 32px; height: 64px; display: flex; align-items: center; justify-content: space-between;
}
.header-left { display: flex; align-items: center; gap: 24px; }
.header-brand { font-weight: 800; font-size: 1.15rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.header-brand .logo-img { height: 36px; width: auto; object-fit: contain; }
.header-nav { display: flex; gap: 4px; }
.header-nav a {
  padding: 8px 16px; border-radius: var(--radius-sm); font-weight: 500; font-size: .88rem;
  color: var(--text-secondary); transition: all .2s;
}
.header-nav a:hover, .header-nav a.active { background: var(--primary-surface); color: var(--primary); }
.header-right { display: flex; align-items: center; gap: 20px; }
.header-user { font-size: .88rem; color: var(--text-secondary); }
.header-user strong { color: var(--text); font-weight: 600; }
.header-balance {
  font-weight: 700; font-size: .9rem; padding: 6px 14px; border-radius: 20px;
}
.balance-healthy { background: var(--success-surface); color: var(--success); }
.balance-low { background: var(--danger-surface); color: var(--danger); }
.cart-toggle {
  position: relative; background: none; border: none; cursor: pointer; padding: 8px;
  color: var(--text); font-size: 1.2rem; transition: color .2s;
}
.cart-toggle:hover { color: var(--primary); }
.cart-badge {
  position: absolute; top: 0; right: 0; background: var(--danger); color: #fff;
  font-size: .65rem; font-weight: 700; width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}

/* ── PRODUCT GRID ────────────────────────────────── */
.page-container { max-width: 1280px; margin: 0 auto; padding: 32px; }
.page-title { font-size: 1.5rem; font-weight: 800; margin-bottom: 8px; }
.page-subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: .95rem; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
.product-card {
  background: var(--surface); border-radius: var(--radius-lg); overflow: hidden;
  border: 1px solid var(--border-light); box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease;
}
.product-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.product-card-img {
  width: 100%; height: 200px; object-fit: contain; background: #ffffff; padding: 12px;
}
.product-card-body { padding: 20px; }
.product-card-name { font-weight: 700; font-size: 1rem; margin-bottom: 6px; color: var(--text); }
.product-card-desc { font-size: .84rem; color: var(--text-secondary); margin-bottom: 14px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-card-footer { display: flex; align-items: center; justify-content: space-between; }
.product-card-price { font-weight: 800; font-size: 1.1rem; color: var(--primary-dark); }
.product-card-stock { font-size: .78rem; color: var(--text-tertiary); }

/* ── OFF-CANVAS CART ─────────────────────────────── */
.cart-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 200;
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s;
}
.cart-overlay.open { opacity: 1; visibility: visible; }
.cart-panel {
  position: fixed; top: 0; right: -440px; width: 420px; max-width: 90vw; height: 100vh;
  background: var(--surface); z-index: 201; display: flex; flex-direction: column;
  box-shadow: -10px 0 40px rgba(0,0,0,0.12); transition: right .35s cubic-bezier(0.4,0,0.2,1);
}
.cart-panel.open { right: 0; }
.cart-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between;
}
.cart-header h2 { font-size: 1.1rem; font-weight: 700; }
.cart-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); padding: 4px; line-height: 1; }
.cart-close:hover { color: var(--text); }
.cart-body { flex: 1; overflow-y: auto; padding: 16px 24px; }
.cart-empty { text-align: center; padding: 60px 20px; color: var(--text-tertiary); }
.cart-empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: .5; }
.cart-item {
  display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border-light);
  align-items: flex-start;
}
.cart-item-img { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg); flex-shrink: 0; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-weight: 600; font-size: .88rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item-price { font-size: .82rem; color: var(--text-secondary); }
.cart-item-controls { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.cart-item-controls button {
  width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; font-size: .85rem; display: flex; align-items: center; justify-content: center;
  transition: all .15s; color: var(--text);
}
.cart-item-controls button:hover { background: var(--primary-surface); border-color: var(--primary-light); color: var(--primary); }
.cart-item-qty { font-weight: 600; font-size: .88rem; min-width: 20px; text-align: center; }
.cart-item-remove { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 1.1rem; padding: 4px; margin-left: auto; flex-shrink: 0; }
.cart-item-remove:hover { color: var(--danger); }
.cart-footer { padding: 20px 24px; border-top: 1px solid var(--border); background: var(--bg); }
.cart-total { display: flex; justify-content: space-between; font-weight: 700; font-size: 1.05rem; margin-bottom: 16px; }

/* ── CHECKOUT MODAL ──────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface); border-radius: var(--radius-xl); padding: 36px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow-xl);
  transform: translateY(20px) scale(0.97); transition: transform .3s cubic-bezier(0.4,0,0.2,1);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 20px; }
.modal-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border-light); font-size: .92rem; }
.modal-row:last-of-type { border-bottom: none; }
.modal-row .label { color: var(--text-secondary); }
.modal-row .value { font-weight: 700; }
.modal-row .value.remaining { color: var(--success); }
.modal-row .value.insufficient { color: var(--danger); }
.modal-actions { display: flex; gap: 12px; margin-top: 24px; }
.modal-actions .btn { flex: 1; }

/* ── ORDER SUCCESS PAGE ──────────────────────────── */
.success-wrapper {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.success-card { text-align: center; background: var(--surface); padding: 60px 48px; border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); max-width: 480px; width: 100%; }
.success-icon {
  width: 80px; height: 80px; border-radius: 50%; background: var(--success-surface);
  display: flex; align-items: center; justify-content: center; margin: 0 auto 24px;
  animation: successPulse 0.6s ease-out;
}
.success-icon svg { width: 40px; height: 40px; color: var(--success); }
@keyframes successPulse { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
.success-card h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 8px; color: var(--text); }
.success-card p { color: var(--text-secondary); margin-bottom: 6px; }
.success-redirect { font-size: .85rem; color: var(--text-tertiary); margin-top: 24px; }

/* ── TABLES ──────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--surface); }
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th { background: var(--bg); padding: 12px 16px; text-align: left; font-weight: 600; color: var(--text-secondary); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border-light); color: var(--text); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(99,102,241,0.02); }
.status-badge { padding: 4px 10px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.status-completed { background: var(--success-surface); color: var(--success); }
.status-pending { background: var(--warning-surface); color: var(--warning); }

/* ── ADMIN LAYOUT ────────────────────────────────── */
.admin-layout { display: flex; min-height: calc(100vh - 64px); }
.admin-sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 24px 16px; flex-shrink: 0;
}
.admin-sidebar a {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: .88rem; color: var(--text-secondary); transition: all .2s; margin-bottom: 2px;
}
.admin-sidebar a:hover, .admin-sidebar a.active { background: var(--primary-surface); color: var(--primary); }
.admin-sidebar a .icon { font-size: 1.1rem; width: 20px; text-align: center; }
.admin-content { flex: 1; padding: 32px; max-width: 1000px; }

/* ── ADMIN STAT CARDS ────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 32px; }
.stat-card { background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow-sm); }
.stat-card .stat-label { font-size: .8rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); }

/* ── ADMIN FORMS ─────────────────────────────────── */
.admin-form-card {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius-lg);
  padding: 32px; box-shadow: var(--shadow-sm); max-width: 560px;
}
.admin-form-card h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border-light); }

/* ── ALERTS ──────────────────────────────────────── */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); margin-bottom: 20px; font-size: .88rem; font-weight: 500; }
.alert-success { background: var(--success-surface); color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: var(--danger-surface); color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: var(--primary-surface); color: var(--primary-dark); border: 1px solid var(--primary-light); }

/* ── TOAST NOTIFICATIONS ─────────────────────────── */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; box-shadow: var(--shadow-lg); font-size: .88rem; font-weight: 500;
  display: flex; align-items: center; gap: 10px; min-width: 280px;
  animation: toastIn .35s ease-out;
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastInMobile { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }

/* ── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 768px) {
  .site-header { padding: 0 12px; }
  .header-left { gap: 10px; }
  .header-right { gap: 10px; }
  .header-brand span { display: none; }
  .header-user { display: none; }
  .header-nav { display: none; }
  .page-container { padding: 20px 12px; }
  .product-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  
  /* Slide in cart perfectly on mobile from off-screen */
  .cart-panel { right: -100%; width: 100%; max-width: 100vw; }
  .cart-panel.open { right: 0; }
  
  .admin-layout { flex-direction: column; }
  .admin-sidebar { 
    display: flex !important; 
    width: 100% !important; 
    flex-direction: row; 
    overflow-x: auto; 
    padding: 10px; 
    border-right: none; 
    border-bottom: 1px solid var(--border); 
  }
  .admin-sidebar a { margin-bottom: 0; white-space: nowrap; flex: 0 0 auto; }
  .admin-content { padding: 20px 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 32px 24px; }
}

@media (max-width: 480px) {
  .product-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  
  /* Make toast notifications completely visible on small screens */
  .toast-container {
    top: auto;
    bottom: 20px;
    left: 16px;
    right: 16px;
  }
  .toast {
    min-width: 0;
    width: 100%;
    animation: toastInMobile .35s ease-out;
    box-shadow: var(--shadow-xl);
  }
  
  .btn-sm { padding: 6px 12px; font-size: 0.78rem; }
}
