/* ==========================================================================
   MyKey Solutions — Tuna Warehouse HQ
   Hand-built styles. Don't over-tidy this.
   ========================================================================== */

:root {
  --mk-purple: #3B1E8C;
  --mk-purple-hover: #2d1670;
  --mk-purple-ghost: rgba(59, 30, 140, 0.08);
  --mk-orange: #F97316;
  --mk-orange-hover: #ea580c;

  --bg: #F0F1F5;
  --sidebar-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --text-main: #1a1a2e;
  --text-secondary: #4a4a5a;
  --text-muted: #7a7a8a;
  --border: #d1d5db;
  --border-light: #e5e7eb;

  --success: #059669;
  --warning: #D97706;
  --danger: #DC2626;
  --info: #2563EB;

  --radius: 6px;
  --radius-lg: 10px;
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   LAYOUT
   -------------------------------------------------------------------------- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 252px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.sidebar-header {
  padding: 18px 16px;
  border-bottom: 2px solid var(--mk-purple);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
}

.brand-title-group h1 {
  font-size: 15px;
  font-weight: 800;
  color: var(--mk-purple);
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-title-group span {
  font-size: 10px;
  color: var(--mk-orange);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 20px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 18px 12px 5px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  text-decoration: none;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  transition: all 0.12s ease;
}

.nav-link:hover {
  background: #f3f4f6;
  color: var(--mk-purple);
}

.nav-link.active {
  background: var(--mk-purple-ghost);
  color: var(--mk-purple);
  font-weight: 700;
  border-left-color: var(--mk-orange);
}

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

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

/* Top bar */
.top-bar {
  height: 56px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 7px 12px;
  width: 320px;
}

.search-box i {
  color: var(--text-muted);
  font-size: 13px;
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  width: 100%;
  color: var(--text-main);
}

.search-box input::placeholder { color: #9ca3af; }

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.branch-selector-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s;
}

.branch-selector-btn:hover { border-color: var(--mk-purple); }

.icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.icon-btn:hover {
  color: var(--mk-purple);
  border-color: var(--mk-purple);
}

.icon-btn .badge-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
}

.user-profile-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.user-profile-trigger:hover { background: var(--bg); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--mk-purple);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.user-role {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Content */
.content-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* --------------------------------------------------------------------------
   PAGE HEADERS & BUTTONS
   -------------------------------------------------------------------------- */
.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title-group h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.4px;
}

.page-title-group p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--mk-purple);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover {
  background: var(--mk-purple-hover);
  transform: translateY(-1px);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-outline:hover {
  border-color: var(--mk-purple);
  color: var(--mk-purple);
}

/* --------------------------------------------------------------------------
   METRICS
   -------------------------------------------------------------------------- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: relative;
  transition: box-shadow 0.2s;
}

.metric-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-color, var(--mk-purple));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.metric-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metric-icon {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-color, var(--mk-purple));
  font-size: 14px;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.6px;
  line-height: 1.2;
}

.metric-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   TABLES
   -------------------------------------------------------------------------- */
.card-table-wrapper {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

.table-header-bar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.table-header-bar h3 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

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

.custom-table th {
  background: #f9fafb;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 10px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.custom-table td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  vertical-align: middle;
}

.custom-table tbody tr:last-child td { border-bottom: none; }

.custom-table tbody tr:hover { background: #f9fafb; }

/* --------------------------------------------------------------------------
   STATUS BADGES
   -------------------------------------------------------------------------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.status-badge.in-stock,
.status-badge.delivered,
.status-badge.fulfilled {
  background: #d1fae5;
  color: #065f46;
}

.status-badge.low,
.status-badge.cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.in-transit,
.status-badge.pending {
  background: #fef3c7;
  color: #92400e;
}

.status-badge.submitted {
  background: #dbeafe;
  color: #1e40af;
}

.status-badge.passed {
  background: #d1fae5;
  color: #065f46;
}

.status-badge.failed {
  background: #fee2e2;
  color: #991b1b;
}

/* --------------------------------------------------------------------------
   MODALS
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: #fff;
  width: 620px;
  max-width: 100%;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-header-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--mk-purple-ghost);
  color: var(--mk-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}

.modal-close-btn:hover {
  background: var(--bg);
  color: var(--text-main);
}

/* Wizard stepper */
.wizard-stepper {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border-light);
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e5e7eb;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-item.active .step-number {
  background: var(--mk-purple);
  color: #fff;
}

.step-item.completed .step-number {
  background: var(--mk-orange);
  color: #fff;
}

.step-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.step-item.active .step-label {
  color: var(--mk-purple);
  font-weight: 700;
}

.step-divider {
  flex: 1;
  height: 2px;
  background: #e5e7eb;
  margin: 0 10px;
  min-width: 20px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f9fafb;
}

/* --------------------------------------------------------------------------
   FORMS
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 15px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  color: var(--text-main);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  border-color: var(--mk-purple);
  box-shadow: 0 0 0 3px rgba(59, 30, 140, 0.12);
}

.form-control::placeholder { color: #9ca3af; }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* Option cards */
.option-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.option-card:hover,
.option-card.selected {
  border-color: var(--mk-purple);
  background: var(--mk-purple-ghost);
}

/* --------------------------------------------------------------------------
   DRAWERS
   -------------------------------------------------------------------------- */
.drawer-overlay {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  background: #fff;
  border-left: 1px solid var(--border-light);
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.drawer-overlay.active {
  transform: translateX(0);
}

.drawer-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* --------------------------------------------------------------------------
   NOTIFICATIONS & TOASTS
   -------------------------------------------------------------------------- */
#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-item {
  background: #fff;
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--mk-purple);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  box-shadow: 0 10px 25px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.25s ease;
  max-width: 340px;
}

.toast-item.success { border-left-color: var(--success); }
.toast-item.error   { border-left-color: var(--danger); }
.toast-item.info    { border-left-color: var(--info); }

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

/* --------------------------------------------------------------------------
   PRODUCT CARDS (grid view)
   -------------------------------------------------------------------------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.product-card {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: box-shadow 0.2s;
}

.product-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.product-card .sku {
  font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* --------------------------------------------------------------------------
   MISC / UTILS
   -------------------------------------------------------------------------- */
.section-card {
  background: var(--card-bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
}

hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 12px 0;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a1a1a1; }

/* Print */
@media print {
  .sidebar, .top-bar, .btn-primary, .btn-outline { display: none !important; }
  .content-body { padding: 0; }
  .card-table-wrapper { border: 1px solid #ccc; }
}
