/* ===================== Reset & Base ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #EFF6FF;
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --text: #0F172A;
  --text-2: #64748B;
  --border: #E2E8F0;
  --success: #16A34A;
  --success-bg: #DCFCE7;
  --danger: #DC2626;
  --danger-bg: #FEE2E2;
  --warning: #D97706;
  --warning-bg: #FEF3C7;
  --info: #0891B2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 4px 12px rgba(15,23,42,.06);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.10);
}

html, body {
  height: 100%;
  font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ===================== Layout ===================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 40;
  transition: transform .25s ease;
}

.main {
  flex: 1;
  margin-right: 260px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 68px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.page-title { font-size: 20px; font-weight: 600; }

.topbar-user {
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 14px;
}

.menu-toggle {
  display: none;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 18px;
}
.menu-toggle:hover { background: var(--bg); }

.content { padding: 24px; flex: 1; }

/* ===================== Sidebar ===================== */
.sidebar-brand {
  height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 17px;
  color: var(--primary);
}
.sidebar-brand i { font-size: 22px; }

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14.5px;
  font-weight: 500;
  transition: all .15s;
}
.nav-link i { width: 20px; text-align: center; font-size: 15px; }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 16px 12px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 8px;
}
.user-info i { font-size: 28px; color: var(--text-2); }
.user-info strong { display: block; font-size: 14px; font-weight: 600; }
.user-info small { color: var(--text-2); font-size: 12px; }

.btn-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}
.btn-logout:hover { background: var(--danger-bg); }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 35;
}

/* ===================== Cards ===================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h3 { font-size: 16px; font-weight: 600; }

.card-body { padding: 20px; }

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.red    { background: var(--danger-bg);    color: var(--danger); }
.stat-icon.green  { background: var(--success-bg);   color: var(--success); }
.stat-icon.amber  { background: var(--warning-bg);   color: var(--warning); }
.stat-icon.cyan   { background: #CFFAFE;             color: var(--info); }

.stat-info { min-width: 0; }
.stat-label { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn i { font-size: 13px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-size: 14px;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn.primary:hover { background: var(--primary-light); color: var(--primary); }

/* ===================== Tables ===================== */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  padding: 12px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg);
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.table tbody tr:hover { background: #FAFBFC; }
.table tbody tr:last-child td { border-bottom: none; }

.table-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-2);
}
.table-empty i { font-size: 32px; opacity: .3; display: block; margin-bottom: 12px; }

.actions { display: flex; gap: 4px; }

/* ===================== Badges ===================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--primary-light); color: var(--primary); }
.badge-muted   { background: #F1F5F9; color: var(--text-2); }

/* ===================== Forms ===================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.form-label .req { color: var(--danger); }

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control::placeholder { color: #94A3B8; }
textarea.form-control { min-height: 90px; resize: vertical; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-error {
  font-size: 13px;
  color: var(--danger);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===================== Filter bar ===================== */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search-box i {
  position: absolute;
  right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  font-size: 14px;
}
.search-box input { padding-right: 40px; }

/* ===================== Page head ===================== */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h2 { font-size: 18px; font-weight: 600; }
.page-head .subtitle { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
  overflow: hidden;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 20px; color: var(--text-2); font-size: 14.5px; line-height: 1.7; }

.modal-foot {
  padding: 14px 20px;
  background: var(--bg);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

/* ===================== Toast ===================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-right: 4px solid var(--success);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
  max-width: 380px;
  font-size: 14px;
  font-weight: 500;
  animation: toastIn .25s ease;
}
.toast.error { border-right-color: var(--danger); }
.toast i { font-size: 18px; }
.toast.success i { color: var(--success); }
.toast.error i { color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: none; }
}
.toast.hide { opacity: 0; transform: translateX(-20px); transition: all .25s; }

/* ===================== Invoice builder ===================== */
.invoice-builder { display: grid; gap: 20px; }

.items-table { width: 100%; border-collapse: collapse; }
.items-table th, .items-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 13.5px;
}
.items-table th { background: var(--bg); font-weight: 600; color: var(--text-2); font-size: 13px; }
.items-table input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  background: var(--card);
}
.items-table input:focus { outline: none; border-color: var(--primary); }

.totals-box {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-right: auto;
  max-width: 340px;
  width: 100%;
}
.total-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 14px;
}
.total-row.grand {
  border-top: 2px solid var(--border);
  margin-top: 6px;
  padding-top: 12px;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

/* ===================== Login page ===================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #EFF6FF 0%, #F8FAFC 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-brand .logo {
  width: 64px; height: 64px;
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 16px;
}
.login-brand h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-brand p { color: var(--text-2); font-size: 14px; }
.login-card .form-group { margin-bottom: 16px; }
.login-btn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===================== Dashboard grid ===================== */
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.dash-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.list-item:last-child { border-bottom: none; }
.list-item-main { min-width: 0; }
.list-item-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.list-item-sub { font-size: 12.5px; color: var(--text-2); }
.list-item-amount { font-weight: 700; font-size: 14px; white-space: nowrap; }

/* ===================== Customer detail ===================== */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.detail-item label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
.detail-item .value { font-weight: 600; font-size: 15px; }

/* ===================== Responsive ===================== */
@media (max-width: 1024px) {
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .main { margin-right: 0; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .topbar-user span { display: none; }
  .page-title { font-size: 17px; }

  .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .stat-value { font-size: 18px; }
  .stat-icon { width: 44px; height: 44px; font-size: 17px; }

  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn { justify-content: center; }

  .login-card { padding: 28px 22px; }

  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
  .table th, .table td { padding: 10px 12px; font-size: 13px; }
  .card-body { padding: 14px; }
  .card-header { padding: 14px 16px; }
  .stat-card { padding: 14px; gap: 12px; }
}