:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f9fbfb;
  --ink: #102020;
  --muted: #64706f;
  --line: #dce4e3;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --primary-soft: #e5f3f1;
  --success: #15803d;
  --success-soft: #eaf7ee;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --info: #0b68a8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 14px 34px rgba(16, 32, 32, .08);
  --z-nav: 20;
  --z-backdrop: 35;
  --z-drawer: 40;
  font-family: Tahoma, "Noto Sans Arabic", "IBM Plex Sans Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
  min-height: 100svh;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid rgba(15, 118, 110, .28); outline-offset: 3px; }

.eyebrow {
  color: var(--primary);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 6px;
}
.muted, .hint { color: var(--muted); line-height: 1.7; }

.login-page {
  display: grid;
  min-height: 100svh;
  padding: 20px;
  place-items: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 430px;
  padding: 26px;
  width: 100%;
}
.login-card h1 { font-size: 2rem; margin: 0; }
.login-current {
  background: var(--primary-soft);
  border: 1px solid rgba(15, 118, 110, .18);
  border-radius: var(--radius);
  color: var(--primary-dark);
  display: grid;
  gap: 4px;
  padding: 12px;
}
.login-current span, .login-current small {
  color: var(--muted);
  font-weight: 800;
}
.login-current strong { font-size: 1.08rem; }

.app-frame {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100svh;
}
.sidebar {
  background: #0d2d2a;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100svh;
  padding: 18px;
  position: sticky;
  right: 0;
  top: 0;
}
.brand-block {
  align-items: center;
  display: flex;
  gap: 12px;
}
.brand-mark {
  align-items: center;
  background: var(--primary);
  border-radius: 12px;
  display: inline-flex;
  font-size: 1.2rem;
  font-weight: 900;
  height: 44px;
  justify-content: center;
  width: 44px;
}
.brand-block strong, .brand-block small, .sidebar-user strong, .sidebar-user span { display: block; }
.brand-block small, .sidebar-user span { color: rgba(255,255,255,.68); margin-top: 3px; }
.side-nav {
  display: grid;
  gap: 8px;
}
.nav-item {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: inherit;
  display: flex;
  gap: 10px;
  font-weight: 850;
  min-height: 46px;
  padding: 12px 14px;
  position: relative;
  text-align: start;
}
.side-nav .nav-item { color: rgba(255,255,255,.78); }
.nav-item.active {
  background: var(--surface);
  color: var(--primary-dark);
}
.side-nav .nav-item.active { background: rgba(255,255,255,.12); color: white; }
.side-nav .nav-item.active::before {
  background: #7dd3c7;
  border-radius: 999px;
  content: "";
  height: 56%;
  inset-inline-start: 6px;
  position: absolute;
  width: 3px;
}
.nav-emphasis {
  background: var(--primary) !important;
  color: white !important;
}
.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.14);
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 16px;
}

.app-shell {
  margin-inline: auto;
  max-width: min(1380px, calc(100vw - 256px));
  padding: 22px clamp(16px, 3vw, 34px) 42px;
  width: 100%;
}
.app-header {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 18px;
}
.app-header h1, .page-title h2, .section-head h2, .section-head h3 {
  margin: 0;
}
.app-header h1 { font-size: clamp(1.45rem, 3vw, 2rem); }

.status-pill, .badge {
  background: var(--primary-soft);
  border: 1px solid rgba(15, 118, 110, .18);
  border-radius: 999px;
  color: var(--primary-dark);
  font-weight: 850;
  min-height: 40px;
  padding: 9px 13px;
  white-space: nowrap;
}
.status-pill.offline, .badge.offline { background: var(--warning-soft); color: var(--warning); }
.status-pill.failed, .badge.failed { background: var(--danger-soft); color: var(--danger); }

.view { display: none; }
.view.active {
  display: grid;
  gap: 16px;
}
.page-title, .section-head, .account-head, .cart-header {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}
.section-head.compact { justify-content: start; }

.metric-hero {
  background: linear-gradient(135deg, #0b5f59, #0f766e);
  border-radius: 18px;
  box-shadow: var(--shadow);
  color: white;
  display: grid;
  gap: 10px;
  padding: clamp(22px, 4vw, 34px);
}
.metric-hero span, .metric-hero small { color: rgba(255,255,255,.82); font-weight: 750; }
.metric-hero strong {
  display: block;
  font-size: clamp(2.5rem, 8vw, 5rem);
  line-height: 1;
  margin-top: 8px;
}
.stats-grid, .sync-counters {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.stats-grid article, .sync-counters span, .panel, .account-panel, .balance-card, .empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stats-grid article, .sync-counters span {
  display: grid;
  gap: 7px;
  min-height: 86px;
  padding: 14px;
}
.stats-grid span, .sync-counters span, .customer-card span, .compact-list span, .management-list span {
  color: var(--muted);
}
.stats-grid strong, .sync-counters b { font-size: 1.12rem; }
.panel { display: grid; gap: 12px; padding: 16px; }
.quick-actions, .action-row {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.primary-btn, .secondary-btn, .ghost-btn, .text-btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  display: inline-flex;
  font-weight: 900;
  justify-content: center;
  min-height: 48px;
  padding: 12px 16px;
}
.primary-btn { background: var(--primary); color: white; }
.secondary-btn { background: var(--surface); border-color: var(--line); color: var(--ink); }
.ghost-btn { background: rgba(15,118,110,.08); border-color: rgba(15,118,110,.12); color: var(--primary-dark); }
.text-btn { background: transparent; color: var(--primary-dark); min-height: 38px; padding-inline: 8px; }

label {
  color: var(--muted);
  display: grid;
  font-size: .93rem;
  font-weight: 850;
  gap: 8px;
}
input, textarea, select {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  min-height: 50px;
  padding: 11px 13px;
  width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
.search-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.search-field {
  align-items: center;
  display: grid;
  gap: 6px 10px;
  grid-template-columns: auto 1fr;
}
.search-field input {
  border: 0;
  min-height: 42px;
  padding: 8px 0;
}
.search-field small {
  color: var(--muted);
  font-weight: 700;
  grid-column: 2;
}
.search-icon {
  align-items: center;
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary-dark);
  display: inline-flex;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.customer-list, .compact-list, .management-list, .sync-list, .statement {
  display: grid;
  gap: 10px;
}
.customer-row, .compact-list article, .management-list article, .sync-list article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 14px;
}
.customer-row {
  align-items: center;
  color: inherit;
  min-height: 74px;
  text-align: start;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
  width: 100%;
}
.customer-row:hover {
  border-color: rgba(15,118,110,.35);
  box-shadow: 0 8px 22px rgba(16,32,32,.06);
}
.customer-row:active { transform: translateY(1px); }
.customer-row__identity {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.customer-row__identity strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.customer-row__identity span {
  color: var(--muted);
  direction: ltr;
  text-align: right;
}
.customer-row__balance {
  align-items: end;
  display: grid;
  gap: 5px;
  margin-inline-start: auto;
  text-align: left;
  white-space: nowrap;
}
.customer-row__balance b { color: var(--primary-dark); font-size: 1.08rem; }
.customer-row__balance small, .status-pill.is-debt, .status-pill.is-settled, .status-pill.is-credit, .status-pill.is-pending {
  border-radius: 999px;
  display: inline-flex;
  font-size: .78rem;
  font-weight: 900;
  justify-content: center;
  padding: 3px 8px;
}
.customer-row__balance small::before, .status-pill.is-debt::before, .status-pill.is-settled::before, .status-pill.is-credit::before, .status-pill.is-pending::before {
  content: "•";
  margin-inline-end: 5px;
}
.customer-row__balance .is-debt, .status-pill.is-debt { background: var(--danger-soft); color: var(--danger); }
.customer-row__balance .is-settled, .status-pill.is-settled { background: var(--success-soft); color: var(--success); }
.customer-row__balance .is-credit, .status-pill.is-credit { background: var(--warning-soft); color: var(--warning); }
.customer-row__balance .is-pending, .status-pill.is-pending { background: var(--primary-soft); color: var(--primary-dark); }
.customer-row__chevron {
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
}
.customer-card strong, .customer-card span, .customer-balance b, .customer-balance small {
  display: block;
}
.customer-balance { text-align: left; }
.customer-balance b { color: var(--primary-dark); font-size: 1.1rem; white-space: nowrap; }
.customer-balance small {
  background: var(--primary-soft);
  border-radius: 999px;
  color: var(--primary-dark);
  margin-top: 4px;
  padding: 3px 8px;
}

.customer-backdrop {
  background: rgba(16,32,32,.25);
  inset: 0;
  position: fixed;
  z-index: var(--z-backdrop);
}
.customer-drawer {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(16,32,32,.14);
  display: grid;
  gap: 14px;
  height: 100svh;
  inset-block: 0;
  inset-inline-end: 0;
  overflow-y: auto;
  padding: 18px;
  position: fixed;
  width: min(480px, calc(100vw - 24px));
  z-index: var(--z-drawer);
}
.account-panel.hidden, .customer-backdrop.hidden { display: none; }
.drawer-handle { display: none; }
.account-head p { color: var(--muted); margin: 0 0 5px; }
.account-head h2 { font-size: 1.5rem; margin: 0; }
.icon-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 1.3rem;
  height: 40px;
  justify-content: center;
  line-height: 1;
  width: 40px;
}
.balance-card {
  background: linear-gradient(180deg, #ffffff, #f8fbfb);
  display: grid;
  gap: 10px;
  padding: 18px;
}
.balance-card > span { color: var(--muted); font-weight: 850; }
.balance-card > strong {
  color: var(--primary-dark);
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1;
}
.balance-summary {
  align-items: start;
  grid-template-columns: 1fr auto;
}
.balance-summary > span, .balance-summary > strong, .balance-summary .balance-breakdown { grid-column: 1 / -1; }
.balance-breakdown {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.balance-breakdown span {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  padding: 10px;
}
.balance-breakdown b, .balance-breakdown em { display: block; }
.balance-breakdown b { color: var(--ink); margin-top: 4px; }
.balance-breakdown em { color: var(--muted); font-style: normal; }

.category-grid, .product-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.category-card, .product-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 14px;
  text-align: center;
}
.category-card span { font-size: 1.6rem; }
.product-card span { color: var(--primary-dark); font-weight: 900; }
.cart-panel {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  padding: 14px;
}
.cart-header h3 { margin: 0; }
.cart-lines { display: grid; gap: 8px; }
.cart-lines article {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px;
}
.cart-lines span { color: var(--muted); display: block; font-size: .86rem; }
.cart-lines button, .management-list button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 38px;
  padding: 7px 10px;
}
.muted-card {
  opacity: .68;
}
.cart-total {
  align-items: center;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  padding: 12px;
}
.cart-total strong { color: var(--primary-dark); font-size: 1.3rem; }

.statement article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 6px;
  padding: 14px;
}
.statement b.plus { color: var(--danger); }
.statement b.minus { color: var(--success); }
.statement ul { color: var(--muted); list-style: none; margin: 4px 0 0; padding: 0; }
.statement li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.statement small { color: var(--muted); }
.transaction-row footer {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 8px;
}
.skeleton-panel {
  display: grid;
  gap: 8px;
}
.skeleton-panel span {
  animation: pulse 1.2s ease-in-out infinite;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  height: 18px;
}
.skeleton-panel span:nth-child(2) { width: 70%; }
.skeleton-panel span:nth-child(3) { width: 45%; }
@keyframes pulse {
  50% { opacity: .45; }
}

.modal {
  border: 0;
  border-radius: 18px;
  max-width: 480px;
  padding: 0;
  width: min(480px, calc(100% - 28px));
}
.modal::backdrop { background: rgba(16,32,32,.42); }
.modal form { display: grid; gap: 14px; padding: 18px; }
.modal h2 { margin: 0; }
.modal-actions { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.check-line { align-items: center; display: flex; flex-direction: row; gap: 8px; }
.check-line input { min-height: auto; width: auto; }
.alert { border-radius: var(--radius-sm); font-weight: 850; line-height: 1.7; padding: 12px; }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.empty-state { color: var(--muted); line-height: 1.7; padding: 18px; text-align: center; }
.sync-list code { direction: ltr; display: block; overflow-wrap: anywhere; text-align: left; }
.audit-list article {
  align-items: center;
}
.audit-list time {
  color: var(--muted);
  font-size: .86rem;
  white-space: nowrap;
}
.product-admin-card, .employee-card {
  align-items: center;
}
.product-admin-card div, .employee-card div {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.product-admin-card strong, .product-admin-card span, .employee-card strong, .employee-card span, .employee-card small {
  display: block;
}
.product-admin-card b {
  color: var(--primary-dark);
  white-space: nowrap;
}

.bottom-nav { display: none; }

@media (max-width: 1020px) {
  .app-frame { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app-shell { max-width: none; }
  .app-shell { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line);
    bottom: 0;
    display: grid;
    gap: 5px;
    grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
    left: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    z-index: var(--z-nav);
  }
  .bottom-nav .nav-item {
    color: var(--muted);
    font-size: .82rem;
    min-height: 48px;
    padding: 8px 5px;
    text-align: center;
  }
  .bottom-nav .nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }
}

@media (max-width: 760px) {
  body.customer-sheet-open { overflow: hidden; }
  .app-shell { padding-inline: 12px; padding-top: 14px; }
  .app-header, .page-title, .section-head { align-items: start; }
  .stats-grid, .sync-counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quick-actions, .action-row, .balance-breakdown { grid-template-columns: 1fr; }
  .category-grid, .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .customer-row, .management-list article, .compact-list article { align-items: center; }
  .customer-drawer {
    border-radius: 18px 18px 0 0;
    bottom: 0;
    box-shadow: 0 -18px 40px rgba(16,32,32,.16);
    height: min(92svh, 760px);
    inset-block: auto 0;
    inset-inline: 0;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    width: 100%;
  }
  .drawer-handle {
    background: var(--line);
    border-radius: 999px;
    display: block;
    height: 4px;
    justify-self: center;
    width: 42px;
  }
  .drawer-actions {
    background: linear-gradient(180deg, rgba(255,255,255,0), white 24%);
    bottom: 0;
    padding-top: 12px;
    position: sticky;
    z-index: 2;
  }
  .sheet {
    border-radius: 18px 18px 0 0;
    bottom: 0;
    margin: auto 0 0;
    max-width: none;
    width: 100%;
  }
}

@media (max-width: 430px) {
  .app-header, .page-title { display: grid; }
  .status-pill, .page-title .primary-btn { width: 100%; }
  .metric-hero { padding: 20px; }
  .stats-grid { gap: 8px; }
  .stats-grid article { min-height: 78px; padding: 12px; }
  .category-grid, .product-grid { grid-template-columns: 1fr; }
  .customer-row { align-items: center; gap: 8px; padding: 12px; }
  .customer-row__balance b { font-size: 1rem; }
  .customer-row__chevron { display: none; }
  .customer-balance { text-align: right; }
  .modal-actions { grid-template-columns: 1fr; }
  .balance-breakdown { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}
