:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --panel-strong: #eef2ff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ef;
  --primary: #1d4ed8;
  --primary-strong: #1e3a8a;
  --primary-soft: #dbeafe;
  --accent: #f59e0b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --sidebar-width: 294px;
  --topbar-height: 74px;
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: radial-gradient(circle at top right, rgba(29, 78, 216, 0.11), transparent 30%), var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
.app-shell { min-height: 100vh; }
.shell-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  background: transparent;
}
.sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #111827 55%, #0b1222 100%);
  color: #ffffff;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 12px 0 35px rgba(15, 23, 42, 0.16);
  overflow-y: auto;
}
.brand {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
}
.brand img { width: 58px; height: 58px; object-fit: contain; border-radius: 16px; background: #fff; padding: 6px; }
.brand-title { font-weight: 900; letter-spacing: 0.2px; font-size: 15px; }
.brand-subtitle { margin-top: 4px; color: rgba(255,255,255,.70); font-size: 12px; line-height: 1.45; }
.nav-section-title { color: rgba(255,255,255,.52); font-size: 12px; font-weight: 800; margin: 8px 10px 4px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.nav-button {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 10px 11px;
  border-radius: 14px;
  color: rgba(255,255,255,.84);
  background: transparent;
  text-align: right;
  transition: transform .15s ease, background .15s ease, color .15s ease;
}
.nav-button:hover { background: rgba(255,255,255,.09); transform: translateX(-2px); color: #fff; }
.nav-button.is-active { background: #ffffff; color: #0f172a; box-shadow: 0 8px 18px rgba(0,0,0,.18); }
.nav-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: rgba(255,255,255,.10); }
.nav-button.is-active .nav-icon { background: var(--primary-soft); color: var(--primary); }
.nav-label { font-weight: 800; font-size: 14px; }
.nav-badge { font-size: 11px; border-radius: 999px; padding: 3px 8px; background: rgba(255,255,255,.12); color: rgba(255,255,255,.72); }
.nav-button.is-active .nav-badge { background: #e2e8f0; color: #334155; }
.sidebar-footer { margin-top: auto; color: rgba(255,255,255,.58); font-size: 12px; padding: 10px 12px; line-height: 1.65; }
.main-shell { min-width: 0; display: grid; grid-template-rows: var(--topbar-height) 1fr; }
.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(255,255,255,.74);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(219, 227, 239, .85);
}
.topbar-title { display: grid; gap: 3px; }
.topbar-title strong { font-size: 18px; }
.topbar-title span { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill, .action-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--text); font-weight: 800; font-size: 12px;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px rgba(22, 163, 74, .12); }
.action-pill { background: var(--primary); color: #fff; border-color: var(--primary); }
.content-area { overflow: auto; padding: 24px; }
.page { display: none; animation: fadeIn .16s ease both; }
.page.is-active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px;
}
.page-eyebrow { color: var(--primary); font-weight: 900; font-size: 12px; margin-bottom: 6px; }
.page-title { margin: 0; font-size: 28px; line-height: 1.25; letter-spacing: -0.2px; }
.page-description { margin: 8px 0 0; color: var(--muted); line-height: 1.7; max-width: 900px; }
.card-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 16px; margin-bottom: 18px; }
.card-grid.three { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
.card-grid.two { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.metric-card, .panel, .placeholder-card {
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(219, 227, 239, .95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.metric-card { padding: 18px; min-height: 120px; }
.metric-label { color: var(--muted); font-size: 13px; font-weight: 800; }
.metric-value { margin-top: 8px; font-size: 30px; font-weight: 900; letter-spacing: -0.4px; }
.metric-note { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.panel { padding: 18px; margin-bottom: 18px; }
.panel-title { margin: 0 0 12px; font-size: 18px; }
.panel-subtitle { color: var(--muted); margin: -4px 0 16px; line-height: 1.7; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; }
.field { display: grid; gap: 7px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 900; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 14px; min-height: 44px; padding: 10px 13px; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(29, 78, 216, .12); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 9px 14px; border-radius: 13px; font-weight: 900; }
.button.primary { background: var(--primary); color: #fff; }
.button.secondary { background: #e2e8f0; color: #0f172a; }
.button.success { background: var(--success); color: #fff; }
.button.warning { background: var(--warning); color: #fff; }
.button.ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 760px; background: #fff; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th { background: #f8fafc; color: #475569; font-size: 12px; font-weight: 900; }
td { font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.badge.mvp { background: #dcfce7; color: #166534; }
.badge.phase { background: #fef3c7; color: #92400e; }
.badge.shell { background: #dbeafe; color: #1e40af; }
.placeholder-card { padding: 22px; min-height: 190px; display: grid; align-content: center; gap: 12px; }
.placeholder-card strong { font-size: 20px; }
.placeholder-card p { margin: 0; color: var(--muted); line-height: 1.75; max-width: 780px; }
.notice {
  border: 1px solid #bfdbfe; background: #eff6ff; color: #1e3a8a; padding: 13px 15px; border-radius: 16px; line-height: 1.7; margin-bottom: 16px; font-weight: 700;
}
.notice.warning { border-color: #fed7aa; background: #fff7ed; color: #9a3412; }
.split-layout { display: grid; grid-template-columns: 1.35fr .85fr; gap: 16px; align-items: start; }
.cart-box { min-height: 320px; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)); gap: 12px; }
.product-tile { border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 12px; min-height: 94px; display: grid; gap: 8px; }
.product-tile strong { font-size: 14px; }
.product-tile span { color: var(--muted); font-size: 12px; }
.mobile-menu-button { display: none; }
.hidden { display: none !important; }
@media (max-width: 1100px) {
  :root { --sidebar-width: 248px; }
  .card-grid, .card-grid.three { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .split-layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .shell-layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 20; transform: translateX(-105%); transition: transform .18s ease; }
  .sidebar.is-open { transform: translateX(0); }
  .main-shell { min-height: 100vh; }
  .topbar { padding: 0 14px; gap: 10px; }
  .mobile-menu-button { display: inline-flex; }
  .topbar-title span { display: none; }
  .content-area { padding: 16px; }
  .page-header { display: grid; }
  .card-grid, .card-grid.three, .card-grid.two { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .product-grid { grid-template-columns: 1fr; }
}

/* Step 03 — IndexedDB status UI */
.metric-value.small { font-size: 20px; line-height: 1.45; }
.db-pill { background: #eef2ff; color: #1e3a8a; border-color: #c7d2fe; }
.db-info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}
.db-info-grid > div {
  display: grid;
  gap: 7px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-soft);
}
.db-info-grid strong { color: var(--muted); font-size: 12px; }
.db-info-grid span { font-weight: 900; overflow-wrap: anywhere; }
.db-info-grid.compact { grid-template-columns: repeat(3, minmax(160px, 1fr)); margin-bottom: 0; }
@media (max-width: 820px) {
  .db-info-grid, .db-info-grid.compact { grid-template-columns: 1fr; }
}

/* Step 05 — Login, session and role-aware UI */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top right, rgba(212, 175, 55, .18), transparent 34%),
    linear-gradient(145deg, #07101f 0%, #111827 48%, #0f172a 100%);
}
.login-card {
  width: min(480px, 100%);
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(226, 232, 240, .9);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .25);
  border-radius: 28px;
  padding: 28px;
}
.login-card.compact { text-align: center; }
.login-logo-wrap { display: flex; justify-content: center; margin-bottom: 14px; }
.login-logo-wrap img { max-width: 150px; max-height: 94px; object-fit: contain; }
.login-heading { text-align: center; margin-bottom: 18px; }
.login-heading h1, .login-card h1 { margin: 0; font-size: 30px; }
.login-heading p, .login-card p { color: var(--muted); line-height: 1.8; margin: 8px 0 0; }
.login-form { display: grid; gap: 13px; }
.login-button { width: 100%; min-height: 48px; }
.check-line { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 800; font-size: 13px; }
.login-footnote { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; color: var(--muted); font-size: 11px; font-weight: 800; }
.login-footnote span { padding: 5px 8px; border-radius: 999px; background: #f1f5f9; }
.loader-bar { height: 8px; overflow: hidden; border-radius: 999px; background: #e2e8f0; margin-top: 18px; }
.loader-bar span { display: block; height: 100%; width: 42%; border-radius: inherit; background: var(--primary); animation: loader-slide 1.15s infinite ease-in-out; }
@keyframes loader-slide { 0% { transform: translateX(135%); } 100% { transform: translateX(-250%); } }
.user-mini-card {
  border: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.06);
  border-radius: 16px;
  padding: 11px 12px;
  margin: 10px 2px 16px;
}
.user-mini-card span { display: block; color: #94a3b8; font-size: 11px; font-weight: 900; margin-bottom: 5px; }
.user-mini-card strong { display: block; color: #fff; font-size: 12px; line-height: 1.6; }
.user-pill { background: #f8fafc; color: #0f172a; }
.small-button { min-height: 34px; padding: 6px 10px; border-radius: 11px; }
.permission-list { display: flex; flex-wrap: wrap; gap: 8px; }
.permission-chip { display: inline-flex; align-items: center; min-height: 30px; padding: 6px 10px; border-radius: 999px; background: #eef2ff; color: #1e3a8a; border: 1px solid #c7d2fe; font-size: 12px; font-weight: 900; }

/* Step 06 — Products, categories and inventory */
.card-grid.four { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.stacked-form { display: grid; gap: 14px; }
.wide-field { grid-column: span 2; }
.readonly-input { background: #f8fafc; color: #475569; font-weight: 900; }
.form-actions { margin: 2px 0 0; }
.form-status { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 10px; border-radius: 999px; background: #f1f5f9; color: #475569; font-size: 12px; font-weight: 900; }
.form-status[data-mode="success"] { background: #dcfce7; color: #166534; }
.form-status[data-mode="error"] { background: #fee2e2; color: #991b1b; }
.form-status[data-mode="info"] { background: #dbeafe; color: #1e40af; }
.category-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, .65fr) auto auto; align-items: end; margin-bottom: 0; }
.product-filter-bar { align-items: stretch; }
.product-filter-bar .search-input { min-width: min(360px, 100%); flex: 1 1 320px; }
.quantity-pill { display: inline-flex; min-width: 52px; justify-content: center; padding: 5px 9px; border-radius: 999px; background: #eef2ff; color: #1e3a8a; font-weight: 900; }
.quantity-pill.danger { background: #fee2e2; color: #991b1b; }
.row-warning td { background: #fff7ed; }
@media (max-width: 1100px) {
  .card-grid.four { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .wide-field { grid-column: span 1; }
  .category-toolbar { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .card-grid.four { grid-template-columns: 1fr; }
}

/* Step 07 — Sales, invoices and stock deduction */
.sales-layout { grid-template-columns: minmax(520px, 1.05fr) minmax(420px, .95fr); }
.sales-product-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); max-height: 560px; overflow: auto; padding-left: 4px; }
.sale-product-tile { text-align: right; cursor: pointer; transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease; }
.sale-product-tile:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 10px 22px rgba(15, 23, 42, .08); }
.compact-table-wrap table { min-width: 560px; }
.cart-table th, .cart-table td { padding: 10px 9px; }
.cart-qty-input { min-height: 36px; width: 86px; padding: 6px 9px; border-radius: 11px; text-align: center; font-weight: 900; }
.sales-form-grid { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.readonly-total {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 13px;
  border: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 14px;
  font-weight: 900;
}
.primary-total { background: #eef2ff; color: #1e3a8a; border-color: #c7d2fe; }
.muted-line { color: var(--muted); font-size: 11px; margin-top: 4px; }
@media (max-width: 1220px) {
  .sales-layout { grid-template-columns: 1fr; }
  .sales-product-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); max-height: none; }
}
@media (max-width: 820px) {
  .sales-product-grid { grid-template-columns: 1fr; }
  .sales-form-grid { grid-template-columns: 1fr; }
}

/* Step 10 — Customers, suppliers and purchases */
.parties-layout, .purchases-layout { grid-template-columns: minmax(440px, 1fr) minmax(440px, 1fr); }
.purchase-product-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); max-height: 560px; overflow: auto; padding-left: 4px; }
.purchase-product-tile { text-align: right; cursor: pointer; transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease; }
.purchase-product-tile:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 10px 22px rgba(15, 23, 42, .08); }
.purchase-head-grid { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
.purchase-total-grid { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
.purchase-line-input { min-height: 36px; width: 96px; padding: 6px 9px; border-radius: 11px; text-align: center; font-weight: 900; }
.purchase-cart-table th, .purchase-cart-table td { padding: 10px 8px; }
@media (max-width: 1220px) {
  .parties-layout, .purchases-layout { grid-template-columns: 1fr; }
  .purchase-product-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); max-height: none; }
}
@media (max-width: 820px) {
  .purchase-product-grid { grid-template-columns: 1fr; }
  .purchase-head-grid, .purchase-total-grid { grid-template-columns: 1fr; }
}


/* Step 16 — Runtime stability and client testing polish */
.runtime-error-banner {
  position: fixed;
  inset-inline: 18px;
  top: 16px;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-radius: 18px;
  background: rgba(254, 242, 242, 0.98);
  color: #7f1d1d;
  box-shadow: 0 18px 45px rgba(127, 29, 29, 0.18);
}
.runtime-error-banner strong,
.runtime-error-banner span,
.runtime-error-banner small { display: block; }
.runtime-error-banner small { color: #991b1b; margin-top: 4px; }
.runtime-error-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.runtime-error-actions button {
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}
.runtime-error-actions [data-runtime-refresh] { background: #7f1d1d; color: #fff; }
.runtime-error-actions [data-runtime-hide] { background: #fee2e2; color: #7f1d1d; }
.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-inline-end: 8px;
  border-radius: 999px;
  background: #64748b;
}
.health-dot.ok { background: #16a34a; }
.health-dot.warning { background: #d97706; }
.health-dot.error { background: #dc2626; }
.badge.danger { background: #fee2e2; color: #991b1b; border-color: rgba(220, 38, 38, 0.28); }
.form-status[data-mode="success"] { background: #ecfdf5; color: #065f46; border-color: rgba(5, 150, 105, 0.28); }
.form-status[data-mode="error"] { background: #fef2f2; color: #991b1b; border-color: rgba(220, 38, 38, 0.28); }
.form-status[data-mode="warning"] { background: #fffbeb; color: #92400e; border-color: rgba(217, 119, 6, 0.28); }
@media (max-width: 720px) {
  .runtime-error-banner { flex-direction: column; align-items: stretch; inset-inline: 10px; top: 10px; }
  .runtime-error-actions { justify-content: stretch; }
  .runtime-error-actions button { flex: 1; }
}
