/*
  ==================================================================
  نظام البيان المحاسبي ERP الاحترافي - Al-Bayan Enterprise ERP v5.0
  Design System v2 — Arabic-first, RTL-native, dark professional theme
  Covers every component class used by index.html and app.js.
  ==================================================================
*/

/* ================= DESIGN TOKENS ================= */
/*
  Tajawal, vendored. res/font and a webfont CDN both failed the same way offline - the app fell
  back to whatever Arabic face the device had, and the type hierarchy went with it.
*/
@font-face {
  font-family: 'Tajawal';
  src: url('vendor/fonts/tajawal_medium.ttf') format('truetype');
  font-weight: 400 500;
  font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('vendor/fonts/tajawal_bold.ttf') format('truetype');
  font-weight: 600 700;
  font-display: swap;
}
@font-face {
  font-family: 'Tajawal';
  src: url('vendor/fonts/tajawal_extrabold.ttf') format('truetype');
  font-weight: 800 900;
  font-display: swap;
}

:root {
  /* Surfaces. White cards on a pale blue page, the way the phone app is built. */
  --bg-primary: #eff6fb;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f5fafd;
  --bg-input: #ffffff;
  --bg-deep: #e4f2fb;

  /* Borders. The hairline does the separating; there is no elevation on a card. */
  --border-color: #dceaf3;
  --border-strong: #b9d3e2;
  --border-focus: #2b9ad9;

  /* Brand. PRIMARY carries every affirmative action. */
  --primary: #2b9ad9;
  --primary-hover: #1b7bb0;
  --primary-light: rgba(43, 154, 217, 0.12);

  --accent: #1b7bb0;
  --accent-hover: #12608f;
  --accent-light: rgba(27, 123, 176, 0.12);

  /*
    AMBER is caution that is not an error - a trial notice, a draft entry, stock running low.
    DANGER is the one colour outside the blue family, and it is spent only on something
    irreversible or a balance that has to be acted on now. If it marked every ordinary variance
    it would stop meaning anything, and the one overdue invoice would read like all the others.
  */
  --warning: #b56f0e;
  --warning-light: rgba(181, 111, 14, 0.12);
  --danger: #d64545;
  --danger-hover: #b83232;
  --danger-light: rgba(214, 69, 69, 0.12);

  /* Kept so older rules still resolve; both now sit inside the brand family. */
  --purple: #1b7bb0;
  --purple-light: rgba(27, 123, 176, 0.12);
  --success: #1b7bb0;
  --info: #2b9ad9;
  --info-light: rgba(43, 154, 217, 0.12);

  /* WhatsApp keeps its own green: it identifies the app the button hands off to. */
  --whatsapp: #25d366;
  --whatsapp-hover: #1eb85a;

  /* Text */
  --text-main: #123448;
  --text-muted: #6e8da0;
  --text-dim: #9ab2c2;

  /* Elevation, restrained - a hairline separates, a shadow only lifts what floats. */
  --shadow-sm: 0 1px 2px rgba(18, 52, 72, 0.05);
  --shadow-md: 0 6px 16px -8px rgba(18, 52, 72, 0.14);
  --shadow-lg: 0 18px 40px -18px rgba(18, 52, 72, 0.20);
  --shadow-glow: 0 0 0 4px rgba(43, 154, 217, 0.14);

  /* Geometry, matching the phone app's dimens. */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  /* Tajawal ships in vendor/fonts - no network, no CDN, no blank first paint. */
  --font-family: 'Tajawal', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, 'Courier New', monospace;

  /* Motion */
  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================= BASE & RESET ================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Tajawal', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', Arial, sans-serif;
  font-family: var(--font-family);
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

html, body {
  background-color: #eff6fb;
  background-color: var(--bg-primary);
  color: #123448;
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  min-height: 100vh;
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.6;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

::selection {
  background: #2b9ad9;
  background: var(--primary);
  color: #fff;
}

/* Tabular numerals for every amount / ID in the UI */
.metric-value,
.device-id-box,
.data-table td,
.custom-table td {
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-variant-numeric: tabular-nums;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #e4f2fb;
  background: var(--bg-deep);
}
::-webkit-scrollbar-thumb {
  background: #b9d3e2;
  background: var(--border-strong);
  border-radius: 9999px;
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: #2b9ad9;
  background: var(--primary);
}

/* Keyboard focus visibility */
:focus-visible {
  outline: 2px solid #2b9ad9;
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ================= ANIMATIONS ================= */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes ringPulse {
  0%   { box-shadow: 0 0 0 0 rgba(43, 154, 217, 0.40); }
  70%  { box-shadow: 0 0 0 18px rgba(43, 154, 217, 0); }
  100% { box-shadow: 0 0 0 0 rgba(43, 154, 217, 0); }
}
@keyframes dotPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ================= OFFLINE ICON FALLBACK ================= */
i.fa-solid, i.fa-brands, i.fa-regular {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

/* ================= SECURITY PIN LOCK OVERLAY ================= */
.pin-lock-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(43, 154, 217, 0.12), transparent 60%),
    #e4f2fb;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(43, 154, 217, 0.12), transparent 60%),
    var(--bg-deep);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pin-lock-card {
  background: linear-gradient(160deg, #ffffff 0%, #ffffff 100%);
  background: linear-gradient(160deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-radius: var(--radius-lg);
  padding: 38px 26px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 18px 40px -18px rgba(18, 52, 72, 0.20);
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.pin-lock-icon {
  width: 74px;
  height: 74px;
  background: linear-gradient(135deg, #2b9ad9 0%, #1b7bb0 100%);
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin-bottom: 20px;
  animation: ringPulse 2.4s ease-out infinite;
}
.pin-lock-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 6px;
}
.pin-lock-subtitle {
  color: #6e8da0;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 15px;
}
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 26px 0;
  direction: ltr;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #b9d3e2;
  border: 2px solid var(--border-strong);
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.pin-dot.active {
  background: #2b9ad9;
  background: var(--primary);
  border-color: #2b9ad9;
  border-color: var(--primary);
  box-shadow: 0 0 12px #2b9ad9;
  box-shadow: 0 0 12px var(--primary);
  animation: dotPop 0.18s ease-out;
}
.pin-keypad {
  display: grid;
  /* A number pad reads left to right in every locale - it is the shape of a
     calculator and a phone dialer, not a line of text. Under RTL the grid
     flowed the keys out as 3 2 1. */
  direction: ltr;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 264px;
  margin: 0 auto;
}
.keypad-btn {
  background: #ffffff;
  background: var(--bg-input);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  color: #123448;
  color: var(--text-main);
  font-size: 20px;
  font-weight: 700;
  padding: 15px;
  border-radius: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  min-height: 54px;
}
.keypad-btn:hover {
  border-color: #2b9ad9;
  border-color: var(--primary);
  color: #2b9ad9;
  color: var(--primary);
}
.keypad-btn:active {
  background: #2b9ad9;
  background: var(--primary);
  border-color: #2b9ad9;
  border-color: var(--primary);
  color: #fff;
  transform: scale(0.94);
}

/* ================= TRIAL TOP BANNER ================= */
.trial-top-bar {
  background: linear-gradient(270deg, #2b9ad9 0%, #1b7bb0 100%);
  color: #ffffff;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(18, 52, 72, 0.05);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 10px;
}
.trial-badge {
  background: rgba(255, 255, 255, 0.25);
  padding: 2px 10px;
  border-radius: 9999px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ================= HEADER ================= */
.app-header {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid #dceaf3;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: 10px 16px;
}
.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
}
.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.mobile-toggle-btn {
  display: none;
  background: #ffffff;
  background: var(--bg-input);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  color: #123448;
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  flex-shrink: 0;
}
.mobile-toggle-btn:hover {
  border-color: #2b9ad9;
  border-color: var(--primary);
  color: #2b9ad9;
  color: var(--primary);
}
.brand-logo {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #2b9ad9 0%, #1b7bb0 100%);
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(43, 154, 217, 0.14);
  box-shadow: var(--shadow-glow);
  flex-shrink: 0;
}
.brand-titles h1 {
  font-size: 1.05rem;
  font-weight: 800;
  color: #123448;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}
.brand-titles p {
  font-size: 0.72rem;
  color: #6e8da0;
  color: var(--text-muted);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ================= APP LAYOUT & SIDEBAR ================= */
.app-layout {
  display: grid;
  grid-template-columns: 272px 1fr;
  min-height: calc(100vh - 70px);
  max-width: 1400px;
  margin: 0 auto;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18, 52, 72, 0.36);
  backdrop-filter: blur(4px);
  z-index: 1040;
}
.sidebar-backdrop.open {
  display: block;
}
.sidebar {
  background: #ffffff;
  background: var(--bg-secondary);
  border-inline-end: 1px solid #dceaf3;
  border-inline-end: 1px solid var(--border-color);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1050;
}
.nav-group-title {
  font-size: 0.68rem;
  font-weight: 800;
  color: #9ab2c2;
  color: var(--text-dim);
  margin: 16px 10px 4px;
  letter-spacing: 0.4px;
}
.nav-group-title:first-child {
  margin-top: 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  color: #6e8da0;
  color: var(--text-muted);
  border-radius: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  min-height: 44px;
  position: relative;
}
.nav-item:hover {
  background: #f5fafd;
  background: var(--bg-card-hover);
  color: #123448;
  color: var(--text-main);
}
.nav-item.active {
  background: rgba(43, 154, 217, 0.12);
  background: var(--primary-light);
  color: #2b9ad9;
  color: var(--primary);
  font-weight: 800;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 9999px;
  border-radius: var(--radius-full);
  background: #2b9ad9;
  background: var(--primary);
}
.nav-item i {
  font-size: 1.05rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* ================= MAIN CONTENT ================= */
.main-content {
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}
.tab-pane {
  animation: fadeUp 0.3s ease-out;
}

/* Section headers (title bar above each screen) */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 800;
  color: #123448;
  color: var(--text-main);
}
.section-title i {
  color: #2b9ad9;
  color: var(--primary);
  font-size: 1.1rem;
}

/* ================= CARDS ================= */
.card-section {
  background: #ffffff;
  background: var(--bg-card);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(18, 52, 72, 0.05);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.card-section:hover {
  border-color: #b9d3e2;
  border-color: var(--border-strong);
}

/* ================= METRIC CARDS (dashboard KPIs) ================= */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: linear-gradient(160deg, #ffffff 0%, #ffffff 100%);
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(18, 52, 72, 0.05);
  box-shadow: var(--shadow-sm);
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.metric-card:hover {
  border-color: #2b9ad9;
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px -8px rgba(18, 52, 72, 0.14);
  box-shadow: var(--shadow-md);
}
.metric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.metric-title {
  font-size: 0.8rem;
  color: #6e8da0;
  color: var(--text-muted);
  font-weight: 600;
}
.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.metric-icon.green,
.metric-icon.emerald { background: rgba(43, 154, 217, 0.12); background: var(--primary-light); color: #2b9ad9; color: var(--primary); }
.metric-icon.red,
.metric-icon.danger  { background: rgba(214, 69, 69, 0.12); background: var(--danger-light); color: #d64545; color: var(--danger); }
.metric-icon.blue,
.metric-icon.accent  { background: rgba(27, 123, 176, 0.12); background: var(--accent-light); color: #1b7bb0; color: var(--accent); }
.metric-icon.orange,
.metric-icon.warning { background: rgba(181, 111, 14, 0.12); background: var(--warning-light); color: #b56f0e; color: var(--warning); }
.metric-icon.purple  { background: rgba(27, 123, 176, 0.12); background: var(--purple-light); color: #1b7bb0; color: var(--purple); }
.metric-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: #123448;
  color: var(--text-main);
  letter-spacing: -0.3px;
}
.metric-sub {
  font-size: 0.75rem;
  color: #9ab2c2;
  color: var(--text-dim);
}

/* ================= CHART CONTAINERS ================= */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Dashboard charts row (revenue/expense bars + expense breakdown) */
.dashboard-charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}
@media (max-width: 992px) {
  .dashboard-charts-grid {
    grid-template-columns: 1fr;
  }
}

/* ================= FORMS ================= */
.form-group {
  margin-bottom: 14px;
}
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: #6e8da0;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-input, .form-select, .form-textarea {
  background: #ffffff;
  background: var(--bg-input);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  color: #123448;
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  outline: none;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  width: 100%;
}
.form-input::placeholder {
  color: #9ab2c2;
  color: var(--text-dim);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: #2b9ad9;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(43, 154, 217, 0.12);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-select {
  cursor: pointer;
}
.form-textarea {
  min-height: 90px;
  resize: vertical;
}

/* ================= BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
  white-space: nowrap;
  min-height: 42px;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary { background: #2b9ad9; background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1b7bb0; background: var(--primary-hover); }
.btn-accent { background: #1b7bb0; background: var(--accent); color: #fff; }
.btn-accent:hover { background: #12608f; background: var(--accent-hover); }
.btn-purple { background: #1b7bb0; background: var(--purple); color: #fff; }
.btn-purple:hover { background: #12608f; background: var(--accent-hover); }
.btn-danger { background: #d64545; background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b83232; background: var(--danger-hover); }
.btn-warning { background: #b56f0e; background: var(--warning); color: #fff; }
.btn-warning:hover { background: #94590b; }
.btn-whatsapp { background: #25d366; background: var(--whatsapp); color: #fff; }
.btn-whatsapp:hover { background: #1eb85a; background: var(--whatsapp-hover); }
.btn-light { background: #fff; color: #1b7bb0; color: var(--accent); }
.btn-light:hover { background: #e4f2fb; background: var(--bg-deep); }
.btn-outline { background: transparent; border: 1px solid #dceaf3; border: 1px solid var(--border-color); color: #123448; color: var(--text-main); }
.btn-outline:hover { background: #f5fafd; background: var(--bg-card-hover); border-color: #b9d3e2; border-color: var(--border-strong); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; min-height: 34px; }

/* ================= SWITCH (toggle) ================= */
.switch-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #ffffff;
  background: var(--bg-input);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider {
  position: absolute;
  inset: 0;
  background: #b9d3e2;
  background: var(--border-strong);
  border-radius: 9999px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  inset-inline-start: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.switch input:checked + .slider {
  background: #2b9ad9;
  background: var(--primary);
}
.switch input:checked + .slider::before {
  transform: translateX(-24px);
}
.switch input:focus-visible + .slider {
  outline: 2px solid #2b9ad9;
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ================= TABLES ================= */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 14px;
  border-radius: var(--radius-md);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
}
.custom-table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  min-width: 600px;
}
.custom-table th, .custom-table td,
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid #dceaf3;
  border-bottom: 1px solid var(--border-color);
}
.custom-table th, .data-table th {
  background: #ffffff;
  background: var(--bg-input);
  color: #6e8da0;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  white-space: nowrap;
}
.custom-table tbody tr:last-child td,
.data-table tbody tr:last-child td {
  border-bottom: none;
}
.custom-table tr:hover, .data-table tr:hover {
  background: #f5fafd;
  background: var(--bg-card-hover);
}

/* ================= BADGES ================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 9999px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: rgba(43, 154, 217, 0.12); background: var(--primary-light); color: #2b9ad9; color: var(--primary); }
.badge-warning { background: rgba(181, 111, 14, 0.12); background: var(--warning-light); color: #b56f0e; color: var(--warning); }
.badge-danger { background: rgba(214, 69, 69, 0.12); background: var(--danger-light); color: #d64545; color: var(--danger); }
.badge-info { background: rgba(27, 123, 176, 0.12); background: var(--accent-light); color: #1b7bb0; color: var(--accent); }
.badge-purple { background: rgba(27, 123, 176, 0.12); background: var(--purple-light); color: #1b7bb0; color: var(--purple); }

/* ================= CHART OF ACCOUNTS TREE ================= */
.tree-item-box {
  background: #ffffff;
  background: var(--bg-secondary);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.tree-item-box:hover {
  border-color: #2b9ad9;
  border-color: var(--primary);
}
.tree-children {
  margin-inline-start: 22px;
  border-inline-start: 1px dashed #b9d3e2;
  border-inline-start: 1px dashed var(--border-strong);
  padding-inline-start: 12px;
  margin-top: 6px;
}
#chartOfAccountsTree {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ================= MODALS ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 52, 72, 0.40);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop.show {
  display: flex;
}
.modal-content {
  background: #ffffff;
  background: var(--bg-secondary);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 40px -18px rgba(18, 52, 72, 0.20);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid #dceaf3;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 1rem;
  font-weight: 800;
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid #dceaf3;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

/* ================= ACTIVATION / LICENSING ================= */
.activation-card {
  background: linear-gradient(160deg, #ffffff 0%, #ffffff 100%);
  background: linear-gradient(160deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: 0 6px 16px -8px rgba(18, 52, 72, 0.14);
  box-shadow: var(--shadow-md);
  margin-bottom: 20px;
}
.device-id-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
  background: var(--bg-input);
  border: 1px dashed #b9d3e2;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, 'Courier New', monospace;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: #2b9ad9;
  color: var(--primary);
  letter-spacing: 0.5px;
  margin: 8px 0 20px;
  direction: ltr;
}

/* ================= MOBILE BOTTOM NAV ================= */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid #dceaf3;
  border-top: 1px solid var(--border-color);
  z-index: 999;
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #6e8da0;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition);
}
.mobile-nav-btn.active {
  color: #2b9ad9;
  color: var(--primary);
}
.mobile-nav-btn i {
  font-size: 1.15rem;
}

/* ================= UTILITIES ================= */
.hide-mobile { }
@media (max-width: 992px) {
  .hide-mobile {
    display: none !important;
  }
}

/* ================= MOBILE BREAKPOINT (< 992px) ================= */
@media (max-width: 992px) {
  .mobile-toggle-btn {
    display: inline-flex;
  }
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 18px 40px -18px rgba(18, 52, 72, 0.20);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-bottom-nav {
    display: flex;
  }
  .main-content {
    padding: 14px;
    padding-bottom: 96px;
  }
  .metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 10px;
  }
  .metric-card {
    padding: 14px;
  }
  .metric-icon {
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
  }
  .metric-value {
    font-size: 1.1rem;
  }
  .brand-titles h1 {
    font-size: 0.92rem;
    max-width: 170px;
  }
  .brand-titles p {
    font-size: 0.65rem;
  }
  .header-actions {
    gap: 6px;
  }
  .card-section {
    padding: 14px;
    border-radius: 14px;
    border-radius: var(--radius-md);
  }
  .chart-container {
    height: 240px;
  }
}

/* ================= PENDING TASKS (dashboard onboarding reminders) ================= */
/* A caution, not an error: quick-added customers/suppliers with an incomplete profile.
   Uses the warning palette on purpose - danger stays reserved for destructive actions
   and overdue balances elsewhere in the app. */
/*
  A warm tint mixed as a solid colour, not amber at 12% over the page.
  A translucent brown laid over the blue ground came out olive, which reads
  as something gone wrong rather than something still to do - and the full
  -strength amber border around it made an ordinary reminder shout.
*/
.pending-tasks-card {
  background: #fdf7ec;
  border: 1px solid #f0dfbc;
  border-inline-start: 4px solid #b56f0e;
  border-inline-start: 4px solid var(--warning);
  box-shadow: none;
}
.pending-tasks-card .section-title,
.pending-tasks-card .section-title i {
  color: #b56f0e;
  color: var(--warning);
}
.pending-task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid #dceaf3;
  border-top: 1px solid var(--border-color);
}
.pending-task-row:first-child {
  border-top: none;
  padding-top: 2px;
}
.pending-task-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
}
.pending-task-detail {
  font-size: 0.82rem;
  color: #6e8da0;
  color: var(--text-muted);
}
.pending-task-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ================= PRINT (invoice / report hard copy) ================= */
@media print {
  body * {
    visibility: hidden;
  }
  .invoice-print-area, .invoice-print-area * {
    visibility: visible;
  }
  .invoice-print-area {
    display: block !important;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: #fff !important;
    color: #000 !important;
    padding: 30px;
    direction: rtl;
  }
}

/*
  ==================================================================
  READING COMFORT AT ENTERPRISE DENSITY
  ------------------------------------------------------------------
  The house system was drawn for a simple app with a handful of rows
  per screen. This one carries hundreds of invoices and thousands of
  ledger lines, and at that density the things that matter are not
  decoration: a header that stays put while you scroll a long table,
  a row you can follow across with your eye, figures that line up
  under each other, and enough air that a long session does not tire.
  ==================================================================
*/

/* Text rendering: Arabic at small sizes benefits from the extra hinting. */
html, body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-overflow-scrolling: touch;
}

/* ---- tables ---- */
.data-table,
.custom-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.86rem;
  line-height: 1.5;
}

/* The header stays while the body scrolls. On a 100-row table, a column
   you can no longer name is a column you have to scroll back up to read. */
.data-table thead th,
.custom-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e4f2fb;
  background: var(--bg-deep);
  color: #1b7bb0;
  color: var(--accent);
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.2px;
  padding: 12px 10px;
  white-space: nowrap;
  border-bottom: 1px solid #dceaf3;
  border-bottom: 1px solid var(--border-color);
}

.data-table tbody td,
.custom-table tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid #dceaf3;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

/* A quiet banding so the eye can track one record across many columns. */
.data-table tbody tr:nth-child(even),
.custom-table tbody tr:nth-child(even) {
  background: rgba(228, 242, 251, 0.38);
}

.data-table tbody tr:hover,
.custom-table tbody tr:hover {
  background: #e4f2fb;
  background: var(--bg-deep);
}

.data-table tbody tr:last-child td,
.custom-table tbody tr:last-child td {
  border-bottom: 0;
}

/*
  Every figure in a table is tabular and end-aligned. Proportional digits
  put a column of money out of register by a character or two per row,
  which is exactly the alignment an accountant reads down to spot an
  outlier.
*/
.data-table td.num,
.custom-table td.num,
.data-table td[data-num],
.metric-value,
.device-id-box {
  font-variant-numeric: tabular-nums lining;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* A long table gets its own scroller rather than stretching the page. */
.table-responsive {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: 14px;
  border-radius: var(--radius-md);
}

/* ---- the "showing N of M" line under a windowed list ---- */
.list-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 4px 2px;
  font-size: 0.8rem;
  color: #6e8da0;
  color: var(--text-muted);
}

/* ---- touch comfort ---- */
.btn,
.nav-item,
.mobile-nav-btn,
.keypad-btn {
  min-height: 44px;
}

/* ---- rhythm ---- */
.card-section + .card-section {
  margin-top: 14px;
}

.section-title {
  letter-spacing: -0.1px;
}

/* Long Arabic paragraphs read better with a measure and a looser leading. */
.card-section p,
.metric-sub {
  line-height: 1.7;
  text-wrap: pretty;
}

/* Anything that scrolls under a sticky header needs the header opaque. */
@supports (backdrop-filter: blur(2px)) {
  .data-table thead th,
  .custom-table thead th {
    backdrop-filter: saturate(1.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .data-table tbody tr,
  .custom-table tbody tr {
    transition: none;
  }
}

/*
  ------------------------------------------------------------------
  PHONE DENSITY
  ------------------------------------------------------------------
  Two things cost real screen on a phone. The trial banner repeated a
  full sentence and a button above every screen - about a sixth of the
  viewport, on every tab, all day. And the tables are eight and nine
  columns wide: at the desktop size they simply ran off the edge, so
  the first thing anyone did on any list was drag it sideways.
  ------------------------------------------------------------------
*/
@media (max-width: 700px) {
  .trial-top-bar {
    padding: 6px 12px;
    font-size: 0.72rem;
    gap: 6px;
  }
  .trial-top-bar .btn {
    padding: 4px 10px;
    font-size: 0.7rem;
    min-height: 32px;
  }
  .trial-badge {
    font-size: 0.66rem;
    padding: 1px 7px;
  }

  /* Denser cells fit two or three more columns before anything scrolls. */
  .data-table,
  .custom-table {
    font-size: 0.76rem;
  }
  .data-table thead th,
  .custom-table thead th {
    padding: 9px 6px;
    font-size: 0.68rem;
  }
  .data-table tbody td,
  .custom-table tbody td {
    padding: 9px 6px;
  }

  /* A table that still overflows says so, instead of hiding a column
     off the edge and hoping the reader thinks to drag it. */
  .table-responsive {
    position: relative;
    max-height: 62vh;
  }
  .table-responsive::after {
    content: "اسحب الجدول أفقياً لعرض بقية الأعمدة";
    display: block;
    position: sticky;
    inset-inline-start: 0;
    padding: 6px 4px 2px;
    font-size: 0.66rem;
    color: #9ab2c2;
    color: var(--text-dim);
  }

  .card-section {
    padding: 14px 12px;
  }
  .metric-value {
    font-size: 1.15rem;
  }
}

/* Wider than a phone: the hint is noise, there is nothing to drag. */
@media (min-width: 701px) {
  .table-responsive::after { content: none; }
}

/*
  ==================================================================
  THE AGREED SHELL
  ------------------------------------------------------------------
  One dominant figure, the balances that qualify it, a three-across
  grid of destinations, and the action in the middle of the bar. This
  is the shape the design was reviewed in; the sidebar and the wall of
  metric cards were the old layout wearing new colours.
  ==================================================================
*/
.hero-card {
  background: #2b9ad9;
  background: var(--primary);
  color: #fff;
  border-radius: 22px;
  padding: 22px 20px;
  margin: 10px 0 12px;
  box-shadow: 0 10px 24px -14px rgba(18, 52, 72, 0.45);
}
.hero-caption {
  font-size: 0.8rem;
  opacity: 0.92;
}
.hero-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.25;
  direction: ltr;
  text-align: right;
  font-variant-numeric: tabular-nums lining;
}
.hero-foot {
  font-size: 0.75rem;
  opacity: 0.85;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}
.stat-cell {
  background: #fff;
  background: var(--bg-card);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 12px 8px;
  text-align: center;
}
.stat-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: #123448;
  color: var(--text-main);
  direction: ltr;
  font-variant-numeric: tabular-nums lining;
}
.stat-label {
  font-size: 0.68rem;
  color: #6e8da0;
  color: var(--text-muted);
  margin-top: 2px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.module-tile {
  background: #fff;
  background: var(--bg-card);
  border: 1px solid #dceaf3;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 14px 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #123448;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  min-height: 82px;
  transition: all 0.2s ease;
}
.module-tile i,
.module-tile svg {
  color: #2b9ad9;
  color: var(--primary);
  font-size: 1.35rem;
}
.module-tile:active {
  transform: scale(0.97);
  background: #e4f2fb;
  background: var(--bg-deep);
}

/* The disc rides above the bar's top edge with a ring of page behind it. */
.shell-action {
  position: fixed;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 5px solid #eff6fb;
  border: 5px solid var(--bg-primary);
  background: #2b9ad9;
  background: var(--primary);
  color: #fff;
  font-size: 1.3rem;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  box-shadow: 0 8px 18px -8px rgba(18, 52, 72, 0.5);
  cursor: pointer;
}
.shell-action:active { transform: translateX(-50%) scale(0.94); }

@media (max-width: 900px) {
  .shell-action { display: inline-flex; }
  /* The two middle nav buttons make room for the disc. */
  .mobile-bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}

/*
  The printed page, continued.
  ------------------------------------------------------------------
  Hiding everything with visibility:hidden leaves it occupying space, so
  the document carried a second, empty page - the rest of the app, still
  laid out, just invisible. Collapsing the height of everything outside
  the print area is what makes the PDF end where the invoice ends.
*/
@media print {
  html, body {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }
  .app-header,
  .app-layout,
  .sidebar,
  .trial-top-bar,
  .mobile-bottom-nav,
  .shell-action,
  .modal-backdrop,
  .pin-lock-overlay {
    display: none !important;
  }
  .invoice-print-area {
    position: static !important;
    page-break-inside: avoid;
    padding: 16px !important;
  }
  @page {
    size: A4;
    margin: 10mm;
  }
}
