/* ============================================================
   ورشة الجودة · SaaS Design System (Inspired by Linear, Stripe & Shopify)
   Ultra-Premium Commercial Business Management Platform
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Outfit:wght@400;500;600;700&display=swap');

:root {
  --font-sans: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', 'Cairo', sans-serif;
  
  /* Light Theme (Clean Alabaster / Stripe & Shopify Grade) */
  --bg: #f8f8fa;
  --surface: #ffffff;
  --surface-hover: #fafafc;
  --surface-subtle: #f1f1f5;
  --surface-muted: #e9e9f0;
  --surface-glass: rgba(255, 255, 255, 0.82);
  
  --ink: #141416;
  --ink-secondary: #4b4b53;
  --ink-muted: #747480;
  --ink-faint: #a0a0ab;
  
  /* Primary Accent: Elegant Wine / Rose-Burgundy & Gold Micro-accents */
  --primary: #18181b;
  --primary-hover: #27272a;
  
  --accent: #8b264e;
  --accent-hover: #751f41;
  --accent-subtle: #fdf2f6;
  --accent-ink: #ffffff;
  
  --gold: #c59b27;
  --gold-subtle: #fbf6ea;
  
  --line: #e6e6ed;
  --line-strong: #d2d2dc;
  --line-subtle: #f0f0f4;
  
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --ok-border: #a7f3d0;
  
  --bad: #e11d48;
  --bad-bg: #fff1f2;
  --bad-border: #fecdd3;
  
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  
  --info: #2563eb;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  
  --shadow-xs: 0 1px 2px rgba(20, 20, 22, 0.04);
  --shadow-sm: 0 1px 3px rgba(20, 20, 22, 0.06), 0 1px 2px rgba(20, 20, 22, 0.03);
  --shadow-md: 0 4px 12px rgba(20, 20, 22, 0.06), 0 1px 3px rgba(20, 20, 22, 0.03);
  --shadow-lg: 0 12px 32px rgba(20, 20, 22, 0.08), 0 2px 6px rgba(20, 20, 22, 0.04);
  --shadow-modal: 0 24px 60px rgba(10, 10, 15, 0.16), 0 6px 16px rgba(10, 10, 15, 0.08);
  
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
}

html.dark {
  /* Dark Theme (Obsidian & Titanium / Linear & Apple Pro Grade) */
  --bg: #0c0a09;
  --surface: #141210;
  --surface-hover: #1c1916;
  --surface-subtle: #1e1b17;
  --surface-muted: #28241f;
  --surface-glass: rgba(20, 18, 16, 0.85);
  
  --ink: #f8f6f2;
  --ink-secondary: #c2bbb0;
  --ink-muted: #8c8477;
  --ink-faint: #5a544b;
  
  --primary: #dfba54;
  --primary-hover: #edd17d;
  
  --accent: #dfba54;
  --accent-hover: #f3d888;
  --accent-subtle: #241e14;
  --accent-ink: #0c0a09;
  
  --gold: #dfba54;
  --gold-subtle: #241e14;
  
  --line: #26211a;
  --line-strong: #3b342b;
  --line-subtle: #1c1813;
  
  --ok: #34d399;
  --ok-bg: #062317;
  --ok-border: #064e3b;
  
  --bad: #fb7185;
  --bad-bg: #2d0f14;
  --bad-border: #881337;
  
  --warn: #fbbf24;
  --warn-bg: #2b1d06;
  --warn-border: #78350f;
  
  --info: #60a5fa;
  --info-bg: #0b1f3a;
  --info-border: #1e3a8a;
  
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.7);
  --shadow-modal: 0 24px 64px rgba(0, 0, 0, 0.85);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  direction: rtl;
  text-align: right;
  overflow-x: hidden;
  max-width: 100vw;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tabular-nums {
  font-family: var(--font-display), var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* Typography Hierarchy */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 8px; }
a { color: inherit; text-decoration: none; }

/* Linear Style Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.card-hover:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1.5px);
}

/* Linear & Stripe Style Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--line-strong);
}

.btn:active {
  transform: scale(0.985);
}

.btn.main {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.btn.main:hover {
  filter: brightness(1.15);
  box-shadow: var(--shadow-sm);
}

html.dark .btn.main {
  background: var(--accent);
  color: #0c0a09;
  border-color: var(--accent);
}

.btn.accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.btn.bad {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad-border);
}

.btn.bad:hover {
  background: var(--bad);
  color: #ffffff;
}

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

.btn.lg {
  padding: 10px 20px;
  font-size: 14.5px;
  border-radius: var(--radius-lg);
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* Form Controls */
.input, .select, textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: all 0.15s ease;
}

.input:focus, .select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(223, 186, 84, 0.18);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 5px;
}

/* Linear-Style Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge.neutral {
  background: var(--surface-subtle);
  color: var(--ink-secondary);
  border: 1px solid var(--line);
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid var(--ok-border);
}

.badge.bad {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid var(--bad-border);
}

.badge.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.badge.accent {
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid rgba(223, 186, 84, 0.35);
}

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

.sidebar {
  width: 250px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--line);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
  transition: all 0.12s ease;
  user-select: none;
  cursor: pointer;
}

.nav-link:hover {
  background: var(--surface-subtle);
  color: var(--ink);
}

.nav-link.active {
  background: var(--surface-subtle);
  color: var(--accent);
  font-weight: 700;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.topbar {
  height: 56px;
  background: var(--surface-glass);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

#main-view {
  flex: 1;
  padding: 24px 28px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* Command Palette Overlay */
.cmd-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.65);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  animation: fadeIn 0.15s ease;
}

.cmd-palette {
  width: min(92vw, 560px);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  animation: scaleUp 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.cmd-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--ink);
  font-family: inherit;
}

.cmd-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.12s ease;
}

.cmd-item:hover, .cmd-item.active {
  background: var(--surface-subtle);
  color: var(--accent);
}

/* High-Density Data Tables */
.table-container {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 13px;
}

thead th {
  background: var(--surface-subtle);
  color: var(--ink-muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-subtle);
  color: var(--ink);
}

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

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

/* KPI Metric Cards (Shopify & Stripe Style) */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: 6px;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Modal Overlay & Dialog */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: scaleUp 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes scaleUp {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 600;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideUp 0.18s ease;
}

#toast.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid var(--ok-border);
}

#toast.bad {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid var(--bad-border);
}

/* Mobile Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58px;
  background: var(--surface-glass);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 50;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px;
}

.mobile-nav-btn.active {
  color: var(--accent);
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  #main-view { padding: 16px 14px 75px; }
  .topbar { padding: 0 16px; }
}

/* Filter Chips & Category Tabs (Dark & Light Mode Compatible) */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.chip:hover {
  background: var(--surface-muted);
  border-color: var(--line-strong);
}

.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.cat-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 16px;
  scrollbar-width: thin;
}

.cat-tab {
  white-space: nowrap;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  background: var(--surface);
  color: var(--ink-secondary);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cat-tab:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.cat-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Utilities */
.hide { display: none !important; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

/* ============================================================
   A4 Commercial Invoice Sheet Styles (.invoice-sheet)
   ============================================================ */
.invoice-sheet {
  background: #ffffff;
  color: #141416;
  border: 1px solid #d2d2dc;
  border-radius: 10px;
  padding: 28px 32px;
  font-family: 'Cairo', sans-serif;
  direction: rtl;
  text-align: right;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #8b264e;
  padding-bottom: 16px;
  margin-bottom: 18px;
  gap: 16px;
}

.inv-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.inv-logo {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #c59b27;
}

.inv-title-box {
  text-align: left;
}

.inv-badge {
  display: inline-block;
  background: #8b264e;
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 6px;
}

.inv-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.inv-meta-box {
  background: #f8f8fa;
  border: 1px solid #e6e6ed;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: #141416;
}

.inv-meta-title {
  font-weight: 800;
  color: #8b264e;
  margin-bottom: 6px;
  font-size: 12px;
  border-bottom: 1px dashed #d2d2dc;
  padding-bottom: 4px;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
  font-size: 12.5px;
}

.inv-table thead th {
  background: #18181b !important;
  color: #ffffff !important;
  padding: 9px 12px;
  font-weight: 700;
  border: 1px solid #18181b;
}

.inv-table tbody td {
  padding: 9px 12px;
  border: 1px solid #e6e6ed;
  color: #141416 !important;
  background: #ffffff !important;
}

.inv-footer-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: start;
}

.inv-tafqeet-box {
  background: #fbf6ea;
  border: 1px solid #e6d3a3;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
  color: #141416;
}

.inv-totals-box {
  background: #f8f8fa;
  border: 1px solid #d2d2dc;
  border-radius: 8px;
  padding: 12px 16px;
  color: #141416;
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px dashed #e6e6ed;
}

.inv-total-row.grand {
  font-size: 16px;
  font-weight: 900;
  color: #8b264e;
  border-bottom: 2px solid #8b264e;
  padding: 8px 0;
}

.inv-stamp-box {
  border: 1px dashed #a0a0ab;
  border-radius: 8px;
  padding: 12px;
  min-height: 92px;
  text-align: center;
}

.inv-legal-footer {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid #e6e6ed;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #747480;
}

/* Print exact rules for A4 Invoice */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .sidebar, .topbar, .mobile-nav, .btn, .no-print, #toast, .cmd-palette-overlay {
    display: none !important;
  }
  body.printing-invoice-modal #app-view,
  body.printing-invoice-modal #login-view {
    display: none !important;
  }
  #invoice-modal-view {
    position: static !important;
    background: #ffffff !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    display: block !important;
  }
  #invoice-modal-view .modal-panel {
    max-width: 100% !important;
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: #ffffff !important;
  }
  .invoice-sheet {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: 100% !important;
  }
  #main-view {
    padding: 0 !important;
    max-width: 100% !important;
  }
}
