/* ===== Variables ===== */
:root {
  --purple: #7C3AED;
  --purple-light: #EDE9FE;
  --purple-dark: #6D28D9;
  --bg: #F9FAFB;
  --sidebar-bg: #F3F4F6;
  --white: #FFFFFF;
  --text: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --green: #059669;
  --green-bg: #D1FAE5;
  --green-text: #065F46;
  --yellow-bg: #FEF3C7;
  --yellow-text: #92400E;
  --red-bg: #FEE2E2;
  --red-text: #991B1B;
  --blue-bg: #DBEAFE;
  --blue-text: #1E40AF;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ===== App Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--purple);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-family: inherit;
  text-align: right;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
}

.nav-item.active,
.nav-subitem.active {
  background: var(--white);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-right: auto;
  background: var(--purple);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.nav-group {
  margin-top: 4px;
}

.nav-group-toggle {
  position: relative;
}

.nav-group-toggle .chevron {
  width: 14px;
  height: 14px;
  margin-right: auto;
  transition: transform 0.2s;
}

.nav-group.open .chevron {
  transform: rotate(180deg);
}

.nav-group-toggle.active-group {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
}

.nav-submenu {
  display: none;
  padding-right: 28px;
  margin-top: 2px;
}

.nav-group.open .nav-submenu {
  display: block;
}

.nav-subitem {
  display: block;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 1px;
}

.nav-subitem:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.03);
}

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.workspace {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.workspace:hover {
  background: rgba(0, 0, 0, 0.04);
}

.workspace-avatar {
  width: 32px;
  height: 32px;
  background: var(--purple-light);
  color: var(--purple);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.workspace-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.workspace-type {
  display: block;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ===== Main Wrapper ===== */
.main-wrapper {
  flex: 1;
  margin-right: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-secondary);
}

.mobile-menu-btn svg {
  width: 22px;
  height: 22px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  position: relative;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.notif-dot {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 7px;
  height: 7px;
  background: #EF4444;
  border-radius: 50%;
  border: 2px solid white;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border-radius: 8px;
  cursor: pointer;
  margin-right: 8px;
  transition: background 0.15s;
}

.user-menu:hover {
  background: var(--bg);
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.user-name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.user-email {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Content ===== */
.content {
  padding: 28px 32px 48px;
  flex: 1;
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.page-tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
}

.page-tab {
  padding: 10px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  cursor: pointer;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: inherit;
}

.page-tab:hover {
  color: var(--text);
}

.page-tab.active {
  color: var(--purple);
  border-bottom-color: var(--purple);
  font-weight: 600;
}

/* ===== Stats Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.stat-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

.stat-card.highlight {
  border-color: var(--purple-light);
  background: linear-gradient(135deg, #FAFAFA, var(--purple-light));
}

.info-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  cursor: help;
}

/* ===== Table Section ===== */
.table-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.table-toolbar-left {
  display: flex;
  gap: 8px;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.toolbar-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.toolbar-btn svg {
  width: 15px;
  height: 15px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  min-width: 220px;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: right;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 12.5px;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background: #FAFAFA;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.table-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--purple);
  cursor: pointer;
}

/* ===== Status Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-paid {
  background: var(--green-bg);
  color: var(--green-text);
}

.badge-pending {
  background: var(--yellow-bg);
  color: var(--yellow-text);
}

.badge-overdue {
  background: var(--red-bg);
  color: var(--red-text);
}

.badge-active {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.badge svg {
  width: 13px;
  height: 13px;
}

/* ===== Actions ===== */
.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.action-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.action-btn svg {
  width: 18px;
  height: 18px;
}

/* ===== Pagination ===== */
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.table-info {
  font-size: 13px;
  color: var(--text-secondary);
}

.pagination {
  display: flex;
  gap: 4px;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.page-btn:hover {
  background: var(--bg);
}

.page-btn.active {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
}

.page-btn.dots {
  border: none;
  cursor: default;
}

.page-btn.dots:hover {
  background: var(--white);
}

/* ===== Products Grid ===== */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s;
}

.product-card:hover {
  box-shadow: var(--shadow);
}

.product-sku {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.product-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}

.product-compat {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.product-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.product-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--purple);
}

.product-stock {
  font-size: 12px;
  font-weight: 600;
}

.stock-ok { color: var(--green); }
.stock-low { color: #D97706; }
.stock-out { color: #DC2626; }

/* ===== Treasury Cards ===== */
.treasury-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.treasury-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.treasury-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
}

.treasury-card.cash::before { background: var(--green); }
.treasury-card.bank::before { background: var(--purple); }
.treasury-card.credit::before { background: #F59E0B; }

.treasury-name {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.treasury-balance {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
}

.treasury-change {
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.treasury-change.up { color: var(--green); }
.treasury-change.down { color: #DC2626; }

/* ===== Dashboard Charts placeholder ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  height: 160px;
  padding-top: 10px;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.chart-bar {
  width: 100%;
  max-width: 40px;
  background: var(--purple-light);
  border-radius: 6px 6px 0 0;
  transition: height 0.3s;
  position: relative;
}

.chart-bar.active {
  background: var(--purple);
}

.chart-bar-label {
  font-size: 11px;
  color: var(--text-muted);
}

.recent-list {
  list-style: none;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.recent-item:last-child {
  border-bottom: none;
}

.recent-item-info {
  display: flex;
  flex-direction: column;
}

.recent-item-title {
  font-size: 13.5px;
  font-weight: 500;
}

.recent-item-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.recent-item-amount {
  font-size: 14px;
  font-weight: 600;
}

/* ===== Settings ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.settings-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.settings-card h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-light);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--purple-dark);
}

/* ===== Demo Banner ===== */
.demo-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(90deg, var(--purple-dark), var(--purple));
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .treasury-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-right: 0;
  }
  .mobile-menu-btn {
    display: flex;
  }
  .user-info {
    display: none;
  }
  .content {
    padding: 20px 16px 60px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-box {
    min-width: auto;
  }
}
