/* ============================================
   Order System — Redesigned UI
   Design System: Enterprise B2B
   Font: Plus Jakarta Sans
   Version: 3.0.0
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400&display=swap');

/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
  /* Brand */
  --color-primary:       #2563EB;
  --color-primary-dark:  #1D4ED8;
  --color-primary-light: #EFF6FF;
  --color-primary-ring:  rgba(37, 99, 235, 0.25);

  /* Semantic */
  --color-success:       #10B981;
  --color-success-bg:    #ECFDF5;
  --color-warning:       #F59E0B;
  --color-warning-bg:    #FFFBEB;
  --color-danger:        #EF4444;
  --color-danger-bg:     #FEF2F2;
  --color-info:          #3B82F6;
  --color-info-bg:       #EFF6FF;

  /* Sidebar (stays dark in both modes) */
  --sidebar-bg:          #0F172A;
  --sidebar-surface:     #1E293B;
  --sidebar-border:      rgba(255,255,255,0.06);
  --sidebar-text:        #94A3B8;
  --sidebar-text-active: #F8FAFC;
  --sidebar-active-bg:   #2563EB;
  --sidebar-hover-bg:    rgba(255,255,255,0.06);
  --sidebar-width:       240px;

  /* App surfaces */
  --bg-body:    #F1F5F9;
  --bg-card:    #FFFFFF;
  --bg-hover:   #F8FAFC;
  --bg-input:   #FFFFFF;
  --bg-overlay: rgba(15, 23, 42, 0.5);

  /* Text */
  --text-primary:   #0F172A;
  --text-secondary: #475569;
  --text-muted:     #94A3B8;
  --text-inverse:   #FFFFFF;

  /* Borders */
  --border:        #E2E8F0;
  --border-focus:  #2563EB;
  --radius-sm:     6px;
  --radius:        8px;
  --radius-lg:     12px;
  --radius-xl:     16px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-md: 0 10px 15px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 20px 25px rgba(0,0,0,0.08), 0 10px 10px rgba(0,0,0,0.04);

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;

  /* Topbar */
  --topbar-height: 56px;

  /* Transitions */
  --ease-fast:   150ms ease;
  --ease-base:   200ms ease;
  --ease-slow:   300ms ease;
  --ease-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dark mode overrides (only app surface tokens; sidebar stays unchanged) */
[data-theme="dark"] {
  --bg-body:    #0F172A;
  --bg-card:    #1E293B;
  --bg-hover:   #293548;
  --bg-input:   #293548;
  --bg-overlay: rgba(0, 0, 0, 0.7);

  --text-primary:   #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted:     #64748B;

  --border:      #334155;
  --border-focus: #3B82F6;

  --color-primary-light: rgba(37, 99, 235, 0.15);
  --color-success-bg:    rgba(16, 185, 129, 0.12);
  --color-warning-bg:    rgba(245, 158, 11, 0.12);
  --color-danger-bg:     rgba(239, 68, 68, 0.12);
  --color-info-bg:       rgba(59, 130, 246, 0.12);

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow:    0 4px 6px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
  --shadow-md: 0 10px 15px rgba(0,0,0,0.3), 0 4px 6px rgba(0,0,0,0.2);
  --shadow-lg: 0 20px 25px rgba(0,0,0,0.4), 0 10px 10px rgba(0,0,0,0.3);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  transition: background-color var(--ease-base), color var(--ease-base);
}

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

/* ============================================
   APP LAYOUT (sidebar + main)
   ============================================ */
.app-layout {
  display: flex;
  min-height: 100dvh;
}

/* ============================================
   SIDEBAR  (the .nav element IS the sidebar)
   ============================================ */
.nav {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--ease-slow);
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

/* Sidebar brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--sidebar-text-active);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Sidebar nav section label */
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  padding: var(--space-5) var(--space-4) var(--space-2);
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
}

/* Nav items (buttons) */
.nav button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: calc(100% - var(--space-4));
  margin: 2px var(--space-2);
  padding: 10px var(--space-3);
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--ease-fast), color var(--ease-fast);
  white-space: nowrap;
  line-height: 1.4;
}

.nav button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity var(--ease-fast);
}

.nav button:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.nav button:hover svg {
  opacity: 1;
}

.nav button.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav button.active svg {
  opacity: 1;
}

.nav button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Logout button at bottom */
.nav .nav-spacer {
  flex: 1;
  min-height: var(--space-6);
}

.nav .nav-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: var(--space-2) var(--space-4);
}

.nav .nav-logout {
  color: #F87171;
  margin-bottom: var(--space-4);
}

.nav .nav-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #FCA5A5;
}

/* Sidebar overlay (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--ease-slow);
}

/* ============================================
   MAIN WRAPPER
   ============================================ */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ============================================
   TOPBAR
   ============================================ */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--ease-base), border-color var(--ease-base);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-user-role {
  font-size: 12px;
  font-weight: 500;
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 20px;
}

/* Hamburger (mobile) — appended to body by JS, positioned fixed */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 201;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  box-shadow: var(--shadow-sm);
  transition: background var(--ease-fast), color var(--ease-fast);
}

.mobile-menu-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: none;
}

/* Theme toggle — positioned by JS as .theme-toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: 300;
  box-shadow: var(--shadow-sm);
  transition: background var(--ease-fast), color var(--ease-fast);
  background: var(--bg-card);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ============================================
   CONTENT AREA
   ============================================ */
.content-area {
  flex: 1;
  padding: var(--space-6);
  max-width: 1360px;
  width: 100%;
}

/* Page header inside content */
.page-header {
  margin-bottom: var(--space-6);
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: stretch;
  background: var(--bg-body);
}

.login-panel-brand {
  display: none;
  flex: 1;
  background: var(--sidebar-bg);
  padding: var(--space-12);
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-panel-brand::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(37,99,235,0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(99,102,241,0.15) 0%, transparent 50%);
  pointer-events: none;
}

.login-brand-icon {
  width: 52px;
  height: 52px;
  background: var(--color-primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-8);
  position: relative;
}

.login-brand-title {
  font-size: 32px;
  font-weight: 800;
  color: white;
  line-height: 1.2;
  margin-bottom: var(--space-4);
  position: relative;
}

.login-brand-desc {
  font-size: 16px;
  color: #94A3B8;
  line-height: 1.7;
  max-width: 380px;
  position: relative;
}

.login-brand-features {
  margin-top: var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  position: relative;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: #CBD5E1;
  font-size: 14px;
  font-weight: 500;
}

.login-feature-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}

.login-panel-form {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
}

.login-container {
  width: 100%;
}

.login-logo {
  width: 44px;
  height: 44px;
  background: var(--color-primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-6);
}

.login-container h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
}

.login-container .error-message {
  font-size: 13px;
  color: var(--color-danger);
  margin-top: var(--space-2);
  min-height: 20px;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: background var(--ease-base), border-color var(--ease-base);
}

.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.mt-2 { margin-top: var(--space-5); }
.mt-1 { margin-top: var(--space-3); }
.mb-2 { margin-bottom: var(--space-5); }
.mb-1 { margin-bottom: var(--space-3); }

/* ============================================
   TAB CONTENT (page sections)
   ============================================ */
.tab-content { animation: fadeIn 150ms ease; }
.tab-content.hidden { display: none; }

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

/* ============================================
   STATS GRID
   ============================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-5) var(--space-4);
  transition: background var(--ease-base), border-color var(--ease-base), box-shadow var(--ease-fast);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-primary);
  border-radius: 2px 2px 0 0;
}

.stat-card.warning::before  { background: var(--color-warning); }
.stat-card.positive::before { background: var(--color-success); }
.stat-card.danger::before   { background: var(--color-danger); }
.stat-card.critical::before { background: #7C3AED; }

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card h3,
.stat-card h4 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.stat-card .number {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-card small {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================
   SEARCH BAR
   ============================================ */
.search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.search-bar input,
.search-bar select {
  flex: 1;
  min-width: 160px;
}

/* ============================================
   TABLES
   ============================================ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: var(--space-2);
  -webkit-overflow-scrolling: touch;
}

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

thead {
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 10px var(--space-4);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

td {
  padding: 12px var(--space-4);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--ease-fast);
}

tbody tr:hover { background: var(--bg-hover); }

.checkbox-col {
  width: 40px;
  padding-left: var(--space-4);
}

.compact-table td,
.compact-table th {
  padding: 8px var(--space-3);
}

/* Table states */
.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-10) !important;
  font-size: 14px;
}

.table-empty.text-danger {
  color: var(--color-danger);
}

.loading-state {
  text-align: center;
  padding: var(--space-10) !important;
}

.empty-state {
  text-align: center;
  padding: var(--space-10);
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================
   BADGES / STATUS
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
  white-space: nowrap;
}

/* Order status badges */
.badge.draft        { background: #F1F5F9; color: #475569; }
.badge.confirmed    { background: #EFF6FF; color: #1D4ED8; }
.badge.processing   { background: #FFF7ED; color: #C2410C; }
.badge.fulfilled    { background: #F0FDF4; color: #15803D; }
.badge.paid         { background: #ECFDF5; color: #047857; }
.badge.expired      { background: #FEF2F2; color: #B91C1C; }
.badge.cancelled    { background: #F1F5F9; color: #64748B; }
.badge.pending      { background: #FFF7ED; color: #C2410C; }
.badge.failed       { background: #FEF2F2; color: #B91C1C; }
.badge.completed    { background: #ECFDF5; color: #047857; }
.badge.refunded     { background: #F5F3FF; color: #6D28D9; }

/* Active/inactive */
.badge.active   { background: #ECFDF5; color: #047857; }
.badge.inactive { background: #FEF2F2; color: #B91C1C; }

/* Role badges */
.badge.role-admin   { background: #F5F3FF; color: #6D28D9; }
.badge.role-manager { background: #EFF6FF; color: #1D4ED8; }
.badge.role-operator { background: #F0FDF4; color: #15803D; }
.badge.role-viewer  { background: #F8FAFC; color: #475569; }

/* Status-prefixed */
.badge.status-draft      { background: #F1F5F9; color: #475569; }
.badge.status-confirmed  { background: #EFF6FF; color: #1D4ED8; }
.badge.status-processing { background: #FFF7ED; color: #C2410C; }
.badge.status-fulfilled  { background: #F0FDF4; color: #15803D; }
.badge.status-paid       { background: #ECFDF5; color: #047857; }
.badge.status-expired    { background: #FEF2F2; color: #B91C1C; }
.badge.status-cancelled  { background: #F1F5F9; color: #64748B; }

[data-theme="dark"] .badge.draft        { background: rgba(71,85,105,0.2); color: #94A3B8; }
[data-theme="dark"] .badge.confirmed,
[data-theme="dark"] .badge.status-confirmed   { background: rgba(37,99,235,0.15); color: #93C5FD; }
[data-theme="dark"] .badge.processing,
[data-theme="dark"] .badge.status-processing  { background: rgba(249,115,22,0.15); color: #FDBA74; }
[data-theme="dark"] .badge.fulfilled,
[data-theme="dark"] .badge.status-fulfilled   { background: rgba(22,163,74,0.15); color: #86EFAC; }
[data-theme="dark"] .badge.paid,
[data-theme="dark"] .badge.status-paid        { background: rgba(16,185,129,0.15); color: #6EE7B7; }
[data-theme="dark"] .badge.expired,
[data-theme="dark"] .badge.status-expired     { background: rgba(239,68,68,0.15); color: #FCA5A5; }
[data-theme="dark"] .badge.cancelled,
[data-theme="dark"] .badge.status-cancelled   { background: rgba(71,85,105,0.15); color: #94A3B8; }
[data-theme="dark"] .badge.active   { background: rgba(16,185,129,0.15); color: #6EE7B7; }
[data-theme="dark"] .badge.inactive { background: rgba(239,68,68,0.15); color: #FCA5A5; }
[data-theme="dark"] .badge.role-admin   { background: rgba(139,92,246,0.15); color: #C4B5FD; }
[data-theme="dark"] .badge.role-manager { background: rgba(37,99,235,0.15); color: #93C5FD; }
[data-theme="dark"] .badge.role-operator { background: rgba(22,163,74,0.15); color: #86EFAC; }
[data-theme="dark"] .badge.role-viewer  { background: rgba(71,85,105,0.15); color: #94A3B8; }

.scope-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  background: var(--color-primary-light);
  color: var(--color-primary);
  margin: 2px;
}

/* ============================================
   BUTTONS
   ============================================ */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 18px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--ease-fast), color var(--ease-fast),
              border-color var(--ease-fast), box-shadow var(--ease-fast),
              opacity var(--ease-fast);
  white-space: nowrap;
  text-decoration: none;
  background: var(--color-primary);
  color: white;
}

button:hover {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 8px rgba(37,99,235,0.3);
}

button:active { transform: translateY(1px); }

button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Secondary */
button.secondary,
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

button.secondary:hover,
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
  box-shadow: none;
}

/* Ghost */
button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

button.ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: none;
}

/* Danger */
.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: transparent;
}

.btn-danger:hover {
  background: #DC2626;
  box-shadow: 0 4px 8px rgba(239,68,68,0.3);
}

/* Success */
.btn-success {
  background: var(--color-success);
  color: white;
  border-color: transparent;
}

.btn-success:hover {
  background: #059669;
  box-shadow: 0 4px 8px rgba(16,185,129,0.3);
}

/* Small */
.btn-sm,
button.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.form-group:last-child { margin-bottom: 0; }

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

label.required::after {
  content: ' *';
  color: var(--color-danger);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--ease-fast), box-shadow var(--ease-fast), background var(--ease-base);
  line-height: 1.5;
  min-height: 42px;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 36px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: unset;
  accent-color: var(--color-primary);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: unset;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.scope-checkboxes {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Form tabs (order creation sub-tabs) */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-5);
}

.tab {
  padding: 8px var(--space-4);
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  bottom: -2px;
  border-bottom: 2px solid transparent;
  transition: color var(--ease-fast), border-color var(--ease-fast);
  box-shadow: none;
}

.tab:hover {
  color: var(--text-primary);
  background: transparent;
  box-shadow: none;
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: transparent;
  font-weight: 600;
  box-shadow: none;
}

/* ============================================
   COPY INPUT
   ============================================ */
.copy-input-group {
  display: flex;
  gap: var(--space-2);
}

.copy-input-group input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-hover);
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: var(--space-4);
  border-left: 3px solid;
  line-height: 1.5;
}

.alert-warning {
  background: var(--color-warning-bg);
  color: #92400E;
  border-color: var(--color-warning);
}

.alert-danger {
  background: var(--color-danger-bg);
  color: #991B1B;
  border-color: var(--color-danger);
}

.alert-success {
  background: var(--color-success-bg);
  color: #065F46;
  border-color: var(--color-success);
}

.alert-info {
  background: var(--color-info-bg);
  color: #1E40AF;
  border-color: var(--color-info);
}

[data-theme="dark"] .alert-warning { color: #FCD34D; }
[data-theme="dark"] .alert-danger  { color: #FCA5A5; }
[data-theme="dark"] .alert-success { color: #6EE7B7; }
[data-theme="dark"] .alert-info    { color: #93C5FD; }

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: overlayIn var(--ease-base);
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  display: flex;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn var(--ease-spring);
}

.modal-lg {
  max-width: 760px;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease-fast), color var(--ease-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: none;
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-hover);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ============================================
   PAGINATION
   ============================================ */
.pagination-container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-4);
  padding: var(--space-3) 0;
}

.pagination-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination-info select {
  width: auto;
  min-height: unset;
  padding: 5px 30px 5px 10px;
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pagination button {
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

.pagination button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  box-shadow: none;
}

.pagination button:disabled {
  opacity: 0.35;
}

.page-numbers {
  display: flex;
  gap: var(--space-1);
}

.page-number {
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius);
  font-size: 13px;
}

.page-number.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
  font-weight: 700;
}

/* ============================================
   BATCH OPERATIONS
   ============================================ */
.batch-operations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-primary-light);
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}

.batch-info {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
}

.batch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.batch-actions select {
  min-height: unset;
  padding: 5px 30px 5px 10px;
  font-size: 13px;
  width: auto;
}

/* ============================================
   REPORTS
   ============================================ */
.report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  margin-bottom: var(--space-5);
  padding: var(--space-4);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 140px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group input,
.filter-group select {
  min-height: 38px;
}

.report-section { }
.report-section h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.chart-container {
  position: relative;
  height: 300px;
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.chart-container.large { height: 400px; }
.chart-container.half  { flex: 1; min-width: 280px; }

.chart-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.conversion-stats {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.conversion-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.conversion-item:last-child { border-bottom: none; }

/* ============================================
   ORDER DETAIL (JS-generated content)
   ============================================ */
.order-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.order-number {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.order-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.detail-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-5);
  overflow-x: auto;
}

.detail-tab {
  padding: 8px var(--space-4);
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  position: relative;
  bottom: -2px;
  border-bottom: 2px solid transparent;
  transition: color var(--ease-fast), border-color var(--ease-fast);
  box-shadow: none;
}

.detail-tab:hover {
  color: var(--text-primary);
  background: transparent;
  box-shadow: none;
}

.detail-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
  background: transparent;
  box-shadow: none;
}

.detail-card {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}

.detail-item {}
.detail-item .label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.detail-item .value,
.detail-item div:not(.label) {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.info-card {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

.info-card.full-width { grid-column: 1 / -1; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-3);
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.info-row:last-child { border-bottom: none; }
.info-row.total {
  font-weight: 700;
  font-size: 15px;
  padding-top: var(--space-3);
  margin-top: var(--space-1);
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.items-table,
.payments-table {
  width: 100%;
}

.product-info { }
.product-name { font-weight: 600; font-size: 14px; }
.product-sku  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.item-qty, .item-price, .item-total { font-variant-numeric: tabular-nums; }

.product-stats {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.stat { font-size: 13px; color: var(--text-secondary); }
.stat-value { font-weight: 700; color: var(--text-primary); }
.stat-label { color: var(--text-muted); margin-left: 4px; }

.payment-link a {
  font-size: 13px;
  word-break: break-all;
}

/* ============================================
   TIMELINE (order history)
   ============================================ */
.timeline {
  position: relative;
  padding-left: var(--space-6);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: var(--space-4);
}

.timeline-marker {
  position: absolute;
  left: calc(-1 * var(--space-6) + 4px);
  top: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg-card);
  z-index: 1;
}

.timeline-item:first-child .timeline-marker {
  background: var(--color-primary);
}

.timeline-content {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.timeline-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.timeline-user {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.timeline-notes {
  font-size: 13px;
  color: var(--text-primary);
}

/* ============================================
   CUSTOMER DETAIL
   ============================================ */
.customer-detail { }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================
   PRODUCT SUMMARY
   ============================================ */
.product-summary-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.product-summary-empty {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: var(--space-5);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  pointer-events: none;
  max-width: 480px;
  width: calc(100% - var(--space-8));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  width: 100%;
  animation: toastIn var(--ease-spring);
  font-size: 14px;
}

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

.toast.success { border-left: 3px solid var(--color-success); }
.toast.error   { border-left: 3px solid var(--color-danger); }
.toast.warning { border-left: 3px solid var(--color-warning); }
.toast.info    { border-left: 3px solid var(--color-info); }

.toast-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-content { flex: 1; }
.toast-title { font-weight: 700; color: var(--text-primary); margin-bottom: 2px; }
.toast-message { color: var(--text-secondary); font-size: 13px; }
.toast-close {
  background: transparent;
  border: none;
  padding: 0;
  width: 22px;
  height: 22px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: none;
  border-radius: var(--radius-sm);
}
.toast-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  box-shadow: none;
}

/* ============================================
   SPINNER
   ============================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

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

/* ============================================
   ORDER LINK
   ============================================ */
.order-link {
  color: var(--color-primary);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}

.order-link:hover { text-decoration: underline; }

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden        { display: none !important; }
.flex          { display: flex; }
.gap-2         { gap: var(--space-2); }
.gap-3         { gap: var(--space-3); }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.text-muted    { color: var(--text-muted); }
.text-danger   { color: var(--color-danger); }
.font-mono     { font-family: var(--font-mono); }
.notes-text    { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.detail-content { font-size: 14px; }

/* ============================================
   RESPONSIVE — TABLET (< 1024px)
   ============================================ */
@media (max-width: 1023px) {
  .nav {
    transform: translateX(-100%);
  }

  .nav.active {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }

  .nav.active + .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* SMALL MOBILE (< 640px) */
@media (max-width: 639px) {
  :root {
    --topbar-height: 52px;
  }

  .content-area {
    padding: var(--space-4);
  }

  .card {
    padding: var(--space-4);
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    max-height: 95vh;
    border-radius: var(--radius-lg);
  }

  .topbar {
    padding: 0 var(--space-4) 0 56px;
  }

  .pagination-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .batch-operations {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-container { height: 240px; }
  .chart-container.large { height: 280px; }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
}

/* ============================================
   DESKTOP — show login split panel (≥ 768px)
   ============================================ */
@media (min-width: 768px) {
  .login-panel-brand {
    display: flex;
    max-width: 480px;
  }

  .login-panel-form {
    padding: var(--space-12) var(--space-10);
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
