:root {
  --ink: #1b2559;
  --muted: #707eae;
  --line: #d5deee;
  --edge: #b7c3da;
  --red: #c4161c;
  --red-dark: #9e1218;
  --bg: #f4f7fe;
  --card: #fff;
  --ok: #067647;
  --warn: #b54708;
  --dock: 4.6rem;
  --shadow: 0 18px 40px rgba(112, 144, 176, 0.12);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; }
button { border: 0; border-radius: 8px; background: var(--red); color: #fff; padding: 10px 14px; min-height: 44px; cursor: pointer; }
button:hover { background: var(--red-dark); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; }
.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.ghost:hover { background: #f7f8fa; }
.hidden { display: none !important; }
.error { color: var(--red); min-height: 1.2em; margin-top: 8px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(720px 360px at 100% 0%, rgba(196, 22, 28, 0.14), transparent 60%),
    var(--bg);
}
.login-stage {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: #fff;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(27, 37, 89, 0.14);
  animation: rise 0.45s ease both;
}
.login-brand {
  background: #1b2559;
  color: #fff;
  padding: 40px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-brand .logo { width: min(250px, 100%); background: #fff; border-radius: 16px; padding: 12px; }
.login-brand h1 { margin: 22px 0 8px; font-size: 1.7rem; font-weight: 700; letter-spacing: -0.03em; }
.login-brand p { margin: 0 0 18px; color: #c9d2ea; line-height: 1.7; }
.login-brand ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.login-brand li { position: relative; padding-inline-start: 18px; color: #eef2ff; }
.login-brand li::before { content: ""; position: absolute; inset-inline-start: 0; top: 0.55em; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.login-card { width: auto; border-radius: 0; box-shadow: none; padding: 40px 32px; text-align: right; }
.eyebrow { margin: 0; color: var(--red); font-weight: 700; font-size: 0.82rem; }
.login-card h2 { margin: 6px 0 18px; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.03em; }
label { display: block; text-align: right; margin-bottom: 12px; font-size: 0.92rem; font-weight: 500; }
input, select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}
.login-card button { width: 100%; margin-top: 6px; transition: transform 0.15s ease, background 0.15s ease; }
.login-card button:hover { transform: translateY(-1px); }

.shell { min-height: 100dvh; display: grid; grid-template-columns: 268px 1fr; gap: 8px; padding: 16px; }
.side {
  background: #fff;
  color: var(--ink);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 16px;
  height: calc(100dvh - 32px);
  border-radius: 24px;
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
}
.brand img { width: 100%; border-radius: 12px; }
.brand strong { display: block; margin-top: 12px; letter-spacing: 0.08em; font-size: 0.72rem; font-weight: 700; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; }
nav button, .side .ghost {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: right;
}
nav button {
  background: #f8fafd;
  color: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 12px;
  min-height: 44px;
  font-weight: 600;
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}
nav button:hover { background: #eef2f8; color: var(--ink); border-color: #8ea0bf; transform: translateX(-2px); }
nav button.active { background: var(--red); color: #fff; border-color: var(--red-dark); }
.side .ghost { color: var(--ink); border-color: var(--line); background: #fff; margin-top: auto; justify-content: center; }
.side .ghost:hover { background: var(--bg); }
.workspace { min-width: 0; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 4px;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 5;
}
.top h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 1.45rem; font-weight: 700; letter-spacing: -0.03em; color: var(--ink); }
.ico { width: 20px; height: 20px; display: inline-grid; flex: 0 0 auto; }
.ico svg, .menu-btn svg { width: 20px; height: 20px; }
.menu-btn { width: 44px; padding: 0; justify-content: center; }
.top p { margin: 4px 0 0; color: var(--muted); font-size: 0.86rem; }
.menu-btn, .dock { display: none; }
#who {
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  font-weight: 700;
}
main { padding: 12px 8px 28px; max-width: 1440px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi, .panel { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); border: 1px solid var(--edge); }
.kpi { padding: 18px 18px 16px; animation: rise 0.4s ease both; }
.kpi-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: #fdecec; color: var(--red); margin-bottom: 12px; }
.kpi span { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.kpi strong { display: block; margin-top: 6px; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.03em; color: var(--ink); }
.panel { margin-top: 16px; overflow: hidden; animation: rise 0.45s ease 0.12s both; }
.panel h3 { margin: 0; padding: 16px 18px 12px; font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.panel-pad { padding: 16px; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(140px, 220px) auto auto; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input, .toolbar select { margin-top: 0; }
.sale-form .toolbar { grid-template-columns: minmax(0, 1.4fr) minmax(120px, 180px) minmax(90px, 120px) auto; }
.checkline { display: flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 500; }
.checkline input { width: auto; margin: 0; }
.meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin: 8px 0; font-size: 0.86rem; }
.note { color: var(--muted); font-size: 0.84rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .actions { display: flex; gap: 8px; margin-top: 8px; }
.form-grid input[readonly] { background: #f4f7fe; color: var(--muted); }

.data { border-radius: 20px; background: #fff; overflow: auto; max-height: calc(100dvh - 220px); box-shadow: var(--shadow); border: 1px solid var(--edge); }
.data-head, .data-row { display: grid; grid-template-columns: var(--cols); gap: 8px; align-items: center; padding: 12px 16px; }
.data-head { position: sticky; top: 0; z-index: 1; background: #eef2f8; color: #3d4d6e; font-size: 0.75rem; font-weight: 700; border-bottom: 1px solid var(--edge); }
.data-row { border-top: 1px solid var(--line); min-height: 52px; }
.data-row:nth-child(even) { background: #f8fafd; }
.data-row:last-child { border-bottom: 0; }
.data-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clickable { cursor: pointer; }
.data-row.clickable:hover { background: #f8f9fd; }
.neg, .due, .ok { font-weight: 700; border-radius: 999px; width: max-content; max-width: 100%; padding: 4px 10px; }
.neg { color: var(--red); background: #fdecec; }
.due { color: var(--warn); background: #fff6ed; }
.ok { color: var(--ok); background: #ecfdf3; }
.pager { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.pager button { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.pager button:hover { background: #f7f8fa; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.skeleton { display: grid; gap: 10px; }
.skeleton span { display: block; height: 72px; border-radius: 12px; background: linear-gradient(90deg, #e8edf2 25%, #f7f8fa 37%, #e8edf2 63%); background-size: 400% 100%; animation: shine 1.1s ease infinite; }
@keyframes shine { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.scrim { position: fixed; inset: 0; background: rgba(18, 24, 32, 0.46); z-index: 20; }
.drawer { position: fixed; inset: 0; background: rgba(18, 24, 32, 0.46); display: grid; justify-content: start; z-index: 50; }
.sheet { width: min(760px, 100%); height: 100%; background: #fff; padding: 16px; overflow: auto; }
.sheet header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet h2 { margin: 0; font-size: 1.2rem; }
.sheet header p { margin: 4px 0 0; color: var(--muted); }
.money { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.money div { background: var(--bg); border-radius: 10px; padding: 10px; }
.money span { color: var(--muted); font-size: 0.78rem; }
.money strong { display: block; margin-top: 4px; }

@media (max-width: 980px) {
  .login-wrap { padding: 12px; }
  .login-stage { grid-template-columns: 1fr; }
  .login-brand { padding: 16px 18px 12px; align-items: center; text-align: center; }
  .login-brand .logo {
    width: min(210px, 68%);
    height: 72px;
    object-fit: cover;
    object-position: center;
    padding: 0;
    border-radius: 12px;
  }
  .login-brand h1 { margin: 10px 0 4px; font-size: 1.2rem; }
  .login-brand p { margin: 0; font-size: 0.86rem; line-height: 1.5; }
  .login-brand ul { display: none; }
  .login-card { padding: 18px 18px 16px; }
  .login-card h2 { font-size: 1.35rem; margin-bottom: 12px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .toolbar, .sale-form .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar button, .sale-form .toolbar button { grid-column: 1 / -1; }
  .shell { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .side {
    position: fixed;
    z-index: 30;
    top: 0;
    height: 100dvh;
    width: min(300px, 88vw);
    border-radius: 0;
    transform: translateX(110%);
    transition: transform 0.18s ease;
    box-shadow: -12px 0 32px rgba(27, 37, 89, 0.12);
  }
  .side.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; align-items: center; }
  main { padding: 12px 12px calc(var(--dock) + 16px); }
  .top {
    padding: calc(12px + env(safe-area-inset-top)) 12px 12px;
    background: #fff;
    border-bottom: 1px solid var(--edge);
  }
  .top #who { background: #f4f7fe; border: 1px solid var(--edge); box-shadow: none; }
  .data { max-height: none; overflow: visible; background: transparent; box-shadow: none; }
  .data-head { display: none; }
  .data-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: #fff;
    border: 1px solid var(--edge);
    border-radius: 12px;
    margin-bottom: 8px;
    padding: 12px;
    gap: 10px 12px;
  }
  .data-row span { white-space: normal; overflow: visible; display: flex; flex-direction: column; gap: 2px; }
  .neg, .due, .ok { width: auto; background: transparent; padding: 0; border-radius: 0; }
  .data-row span::before { content: attr(data-label); color: var(--muted); font-size: 0.72rem; font-weight: 600; }
  #appView:not(.hidden) ~ .dock {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 15;
    background: #fff;
    border-top: 1px solid var(--edge);
    box-shadow: 0 -8px 24px rgba(27, 37, 89, 0.08);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .dock button {
    background: transparent;
    color: var(--muted);
    border-radius: 8px;
    min-height: 48px;
    padding: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
  }
  .dock button em { font-style: normal; }
  .dock .ico { width: 18px; height: 18px; }
  .dock button.active { background: #f8e8e7; color: var(--red); }
  .drawer { align-items: end; justify-content: stretch; }
  .sheet { width: 100%; height: min(92dvh, 100%); border-radius: 16px 16px 0 0; }
  .money { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
