/* Light, calm and tidy. One main colour: the company's own (--accent, set per company).
   Status colours are used for statuses only. Logical properties (inline-start / inline-end)
   make every layout flip correctly between Arabic (RTL) and English / French (LTR). */

:root {
  --accent: #2F5BEA;
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --line: #E7E9EE;
  --line-strong: #D6DAE1;
  --text: #1C2130;
  --muted: #6B7280;
  --soft: #F1F3F6;
  --hover: #F4F5F8;
  --ok: #15803D;   --ok-bg: #E8F5EC;
  --bad: #C2271B;  --bad-bg: #FCECEA;
  --warn: #C2570C; --warn-bg: #FDF0E4;
  --gray: #6B7280; --gray-bg: #EEF0F3;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--card));
  --accent-line: color-mix(in srgb, var(--accent) 30%, var(--card));
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .12), 0 2px 6px rgba(16, 24, 40, .06);
  --top-h: 56px;
  --bottom-h: 64px;
  --ease: 150ms ease;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0F1218; --card: #171B23; --line: #262B36; --line-strong: #323846; --text: #E7E9EE; --muted: #9AA1AE;
  --soft: #1D222C; --hover: #1F2430;
  --ok: #4ADE80; --ok-bg: #12291B; --bad: #F87171; --bad-bg: #2E1614; --warn: #FB923C; --warn-bg: #2E1D10; --gray: #9AA1AE; --gray-bg: #232833;
  --shadow: none; --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0F1218; --card: #171B23; --line: #262B36; --line-strong: #323846; --text: #E7E9EE; --muted: #9AA1AE;
    --soft: #1D222C; --hover: #1F2430;
    --ok: #4ADE80; --ok-bg: #12291B; --bad: #F87171; --bad-bg: #2E1614; --warn: #FB923C; --warn-bg: #2E1D10; --gray: #9AA1AE; --gray-bg: #232833;
    --shadow: none; --shadow-pop: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.6 "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
p { margin: 0 0 12px; }
small { font-size: 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.block { display: block; }
.num, .ltr-inline { font-variant-numeric: tabular-nums; }
.ltr-inline { unicode-bidi: isolate; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; inset-inline-start: -999px; }
.skip:focus { inset-inline-start: 12px; top: 8px; z-index: 100; background: var(--card); padding: 6px 10px; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background var(--ease), border-color var(--ease);
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.subtle { border-color: transparent; background: var(--soft); }
.btn.subtle:hover { background: var(--line); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.wide { width: 100%; height: 40px; }
.btn .ic { width: 16px; height: 16px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 36px; min-width: 36px; padding: 0 8px; justify-content: center;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; font: inherit;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.lang-code { font-size: 12px; font-weight: 600; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 20px; height: var(--top-h); padding: 0 20px; max-width: 1440px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px; flex: none; display: grid; place-items: center; object-fit: contain;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
img.brand-logo { background: none; }
.app-logo { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #fff)); }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.sections { display: flex; align-items: stretch; gap: 4px; height: 100%; }
.sections a {
  display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--ease), border-color var(--ease);
}
.sections a:hover { color: var(--text); text-decoration: none; }
.sections a.on { color: var(--text); border-bottom-color: var(--accent); }
.tools { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.search-btn {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; min-width: 200px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--soft); color: var(--muted); font: inherit; cursor: pointer;
}
.search-btn:hover { border-color: var(--line-strong); }
.search-btn kbd, .search-field kbd { margin-inline-start: auto; }
kbd { font: 500 11px/1 system-ui, sans-serif; padding: 3px 5px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); background: var(--card); direction: ltr; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; list-style: none;
}

/* ---------- Pop-up menus (<details>) ---------- */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 40; min-width: 200px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  animation: pop 120ms ease;
}
.new-menu .menu-pop { inset-inline-end: auto; inset-inline-start: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-pop a, .menu-pop button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; text-align: start; cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--hover); text-decoration: none; }
.menu-pop button.on { color: var(--accent); font-weight: 600; }
.menu-pop form { margin: 0; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; display: grid; gap: 2px; }
.menu-head small { color: var(--muted); }
.menu-label { padding: 8px 10px 4px; color: var(--muted); font-size: 12px; }
.seg { display: flex; gap: 4px; padding: 0 6px 6px; }
.seg form { flex: 1; }
.seg button { justify-content: center; padding: 6px; background: var(--soft); font-size: 12px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.danger-link { color: var(--bad) !important; }

/* ---------- Page: side menu + content ---------- */
.page { display: flex; gap: 24px; max-width: 1440px; margin: 0 auto; padding: 24px 20px 40px; }
.subnav { width: 200px; flex: none; position: sticky; top: calc(var(--top-h) + 24px); align-self: flex-start; }
.subnav-title { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 10px 8px; }
.subnav nav { display: grid; gap: 2px; }
.subnav a {
  position: relative; display: block; padding: 7px 10px; border-radius: 8px; color: var(--muted); font-weight: 500;
  transition: background var(--ease), color var(--ease);
}
.subnav a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.subnav a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 6px 9px; }
.subnav a.on::before { content: ""; position: absolute; inset-inline-start: -1px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.content { flex: 1; min-width: 0; display: grid; gap: 16px; align-content: start; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card-title { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head .card-title { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { display: grid; gap: 6px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.kpi-value small { font-size: 12px; color: var(--muted); font-weight: 500; }
.steps { display: grid; gap: 8px; }
.step {
  display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); transition: border-color var(--ease), background var(--ease);
}
.step:hover { border-color: var(--accent-line); background: var(--accent-soft); text-decoration: none; }
.step > span:nth-child(2) { display: grid; flex: 1; }
.step small { color: var(--muted); }
.step-ic { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.step-go { color: var(--muted); }
[dir="rtl"] .step-go { transform: scaleX(-1); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); margin: 0; }

/* ---------- Status pills, filters ---------- */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.muted { background: var(--gray-bg); color: var(--gray); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-weight: 500;
}
.chip:hover { text-decoration: none; color: var(--text); border-color: var(--line-strong); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--card); }
.chip-n { font-size: 12px; opacity: .75; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: start; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px;
  background: var(--soft); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--hover); }
.table .num { text-align: end; }
.table small { color: var(--muted); }
.row-end { text-align: end; width: 1%; white-space: nowrap; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; }
.form label > span:first-child { font-weight: 500; font-size: 13px; }
.form label small { color: var(--muted); }
input, select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--card); color: var(--text); font: inherit; transition: border-color var(--ease), box-shadow var(--ease);
}
textarea { height: auto; padding: 10px 12px; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--soft); color: var(--muted); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.form label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form label.check.off { opacity: .45; cursor: not-allowed; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.w-md { max-width: 420px; }
.prefix-input { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--card); }
.prefix-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.prefix-input > span { display: flex; align-items: center; padding: 0 10px; background: var(--soft); color: var(--muted); font-size: 13px; }
.prefix-input input { border: 0; border-radius: 0; box-shadow: none !important; }
.hp { position: absolute !important; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.perm { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0; display: grid; gap: 8px; }
.perm legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.danger-zone { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

/* ---------- Messages ---------- */
.flash { display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: 8px; font-weight: 500; margin-bottom: 4px; }
.flash .ic { margin-top: 2px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list-ic { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--soft); color: var(--muted); flex: none; }
.list-main { flex: 1; display: grid; gap: 2px; min-width: 0; }
.list-main small { color: var(--muted); }
.list form { margin: 0; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 16px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }

/* ---------- Pages without the app frame (sign-in, sign-up, messages) ---------- */
.plain { min-height: 100vh; display: flex; flex-direction: column; }
.plain-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; max-width: 1100px; width: 100%; margin: 0 auto; }
.plain-main { flex: 1; display: grid; align-content: center; justify-items: center; padding: 16px; gap: 16px; }
.plain-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.card.narrow { width: 100%; max-width: 400px; padding: 28px; }
.card.narrow.wide-form { max-width: 480px; }
.card.narrow h1 { margin-bottom: 12px; }
.card.narrow p.center { margin: 16px 0 0; }
.big-code { font-size: 40px; font-weight: 700; color: var(--accent); line-height: 1; margin-bottom: 8px; }
.done-ic { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); margin-bottom: 12px; }
.done-ic .ic { width: 24px; height: 24px; }
.hero { max-width: 640px; text-align: center; padding: 40px 0; }
.hero h1 { font-size: 30px; line-height: 1.3; margin-bottom: 12px; }
.hero p { font-size: 16px; }
.hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.hero-actions .btn { height: 42px; padding: 0 20px; }

/* ---------- Quick search (Ctrl+K) ---------- */
.search-modal { position: fixed; inset: 0; z-index: 60; background: rgba(15, 18, 24, .35); display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.search-card { width: 100%; max-width: 560px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); overflow: hidden; animation: pop 120ms ease; }
.search-field { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line); color: var(--muted); }
.search-field input { border: 0; height: 52px; padding: 0; font-size: 15px; box-shadow: none !important; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.search-results a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-empty { padding: 20px; text-align: center; color: var(--muted); margin: 0; }

/* ---------- Phone: bottom bar, sheets ---------- */
.bottombar, .sheet { display: none; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .search-btn { min-width: 0; }
  .search-btn .search-label, .search-btn kbd { display: none; }
}

@media (max-width: 760px) {
  body.app { padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom)); }
  .topbar-in { padding: 0 12px; gap: 8px; }
  .sections, .new-menu { display: none; }
  .brand-name { max-width: 50vw; }
  .search-btn { border: 0; background: none; padding: 0 8px; }
  .page { display: block; padding: 0 0 24px; }
  /* The side menu becomes horizontal tabs that scroll sideways under the top bar. */
  .subnav { position: sticky; top: var(--top-h); z-index: 20; width: auto; background: var(--card); border-bottom: 1px solid var(--line); }
  .subnav-title { display: none; }
  .subnav nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
  .subnav nav::-webkit-scrollbar { display: none; }
  .subnav a { white-space: nowrap; flex: none; background: var(--soft); border: 0 !important; padding: 6px 12px !important; border-radius: 99px; }
  .subnav a.on { background: var(--accent); color: #fff; box-shadow: none; }
  .subnav a.on::before { display: none; }
  .content { padding: 16px 12px 0; gap: 12px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 18px; }
  .card { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 18px; }
  /* Tables turn into stacked cards, each cell with its label. */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: end; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: start; flex: none; }
  .table td:not([data-label])::before { content: none; }
  .table td:first-child { display: block; text-align: start; margin-bottom: 4px; }
  .table td:first-child::before { content: none; }
  .table .row-end { width: 100%; text-align: start; padding-top: 8px; display: block; }
  .table tbody tr:hover td { background: none; }

  .bottombar {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 30; height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  }
  .bottombar > a, .bottombar > button:not(.bb-new) {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); font: 500 11px/1.2 inherit; background: none; border: 0; cursor: pointer;
  }
  .bottombar > a:hover { text-decoration: none; }
  .bottombar .on { color: var(--accent); }
  .bottombar .ic { width: 22px; height: 22px; }
  .bb-new {
    flex: none; align-self: center; width: 48px; height: 48px; margin: 0 8px; border-radius: 14px; border: 0;
    background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer;
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
  }
  .bb-new .ic { width: 24px; height: 24px; }
  .sheet { display: flex; position: fixed; inset: 0; z-index: 50; background: rgba(15, 18, 24, .35); align-items: flex-end; }
  .sheet[hidden] { display: none; }
  .sheet-card {
    width: 100%; background: var(--card); border-radius: 16px 16px 0 0; padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
    animation: up 180ms ease; display: grid;
  }
  @keyframes up { from { transform: translateY(30%); opacity: .6; } to { transform: none; opacity: 1; } }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 12px; }
  .sheet-card > a { display: flex; align-items: center; gap: 12px; padding: 14px 8px; border-radius: 10px; color: var(--text); font-weight: 500; }
  .sheet-card > a:hover { background: var(--hover); text-decoration: none; }
  .search-modal { padding-top: 8px; }
  .hero h1 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Small fixes */
.perm { align-content: start; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
@media (max-width: 760px) { .plain-main { align-content: start; padding-top: 8vh; } }

/* ---------- Step 2: company settings ---------- */
.plain-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 16px; }
.plain-fieldset:disabled input, .plain-fieldset:disabled select { background: var(--soft); }
.identity { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.logo-box { width: 96px; height: 96px; border: 1px dashed var(--line-strong); border-radius: 12px; display: grid; place-items: center; overflow: hidden; background: var(--soft); flex: none; }
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-logo.big { width: 64px; height: 64px; font-size: 28px; border-radius: 14px; }
.identity-main { flex: 1; min-width: 220px; display: grid; gap: 10px; }
.identity-main p { margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input[type="file"] { height: auto; padding: 6px; flex: 1; min-width: 200px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { position: relative; cursor: pointer; }
.swatch input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.swatch > span { display: block; width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.swatch input:checked + span { outline: 2px solid var(--text); outline-offset: 2px; }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.custom input[type="color"] { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--line-strong); cursor: pointer; }
.swatch.custom input[type="radio"]:checked ~ input[type="color"] { outline: 2px solid var(--text); outline-offset: 2px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.big-currency { font-size: 18px; margin: 0 0 6px; }
.example { margin: 0; padding: 10px 12px; background: var(--soft); border-radius: 8px; }
.card-head.padded { padding: 16px 20px 0; }
.rate-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rate-form input { width: 140px; height: 32px; }
.rate-form span { color: var(--muted); font-size: 13px; }
.warn-text { color: var(--warn); }
.add-row { display: flex; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.add-row select { flex: 2; min-width: 200px; }
.add-row input { flex: 1; min-width: 140px; }
.w-form { max-width: 560px; }
.suffix-input { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.suffix-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.suffix-input input { border: 0; border-radius: 0; box-shadow: none !important; }
.suffix-input > span { display: flex; align-items: center; padding: 0 12px; background: var(--soft); color: var(--muted); }
.numbering input { height: 34px; max-width: 140px; }
.numbering code { font: 600 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--accent-soft); color: var(--accent); padding: 5px 8px; border-radius: 6px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.small-empty { margin: 0; }
@media (max-width: 760px) {
  .numbering input { max-width: none; width: 60%; }
  .rate-form input { width: 110px; }
}

/* ---------- Step 3: customers and catalog ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.search-inline { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--card); color: var(--muted); min-width: 260px; }
.search-inline:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-inline input { border: 0; height: 36px; padding: 0; box-shadow: none !important; }
.search-inline select { border: 0; border-inline-start: 1px solid var(--line); border-radius: 0; height: 36px; width: auto; max-width: 160px; box-shadow: none !important; }
.row-link { color: var(--text); }
.table tr.off td { color: var(--muted); }
.neg { color: var(--bad); }
.empty-state { display: grid; justify-items: center; gap: 12px; padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state p { margin: 0; max-width: 420px; }
.empty-ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty-ic .ic { width: 26px; height: 26px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; }
.seg-choice { display: inline-flex; padding: 3px; background: var(--soft); border-radius: 10px; gap: 2px; justify-self: start; }
.seg-choice label { display: block !important; cursor: pointer; }
.seg-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-choice span { display: block; padding: 6px 16px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.seg-choice input:checked + span { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg-choice input:focus-visible + span { outline: 2px solid var(--accent); }
.tag-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list li { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; padding-inline: 10px 4px; background: var(--soft); border-radius: 99px; }
.tag-list form { margin: 0; }
.x-btn { border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; }
.x-btn:hover { background: var(--line); color: var(--bad); }
.x-btn .ic { width: 14px; height: 14px; }
.pre { white-space: pre-line; margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (max-width: 760px) {
  .search-inline { min-width: 0; width: 100%; }
  .toolbar .filters { overflow-x: auto; flex-wrap: nowrap; }
}

/* ---------- Step 4: invoices ---------- */
.pill.info { background: color-mix(in srgb, var(--accent) 12%, var(--card)); color: var(--accent); }
.scroll-x { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.head-actions { display: flex; gap: 8px; align-items: center; }
.no-m { margin: 0 0 4px; }
.small-note { font-size: 12px; margin: 8px 0 0; }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.doc-side { display: grid; gap: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: flex; gap: 10px; }
.tl-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 7px; flex: none; }

/* Editor */
.editor { display: grid; grid-template-columns: minmax(360px, 440px) minmax(0, 1fr); gap: 16px; align-items: start; }
.ed-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 70vh; position: sticky; top: calc(var(--top-h) + 16px); max-height: calc(100vh - var(--top-h) - 32px); }
.ed-tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; flex: none; }
.ed-tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }
.ed-tab.on { background: var(--accent-soft); color: var(--accent); }
.ed-pane { padding: 16px; overflow-y: auto; flex: 1; display: grid; gap: 14px; align-content: start; }
.ed-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex: none; }
.ed-total { margin-inline-end: auto; display: grid; line-height: 1.3; }
.ed-total strong { font-size: 16px; }
.ed-preview { min-width: 0; }
.only-narrow { display: none; }
.form-label { display: grid; gap: 6px; }
.form-label > span:first-child { font-weight: 500; font-size: 13px; }
.lookup { position: relative; display: grid; gap: 6px; }
.lookup .search-inline { min-width: 0; }
.lookup-list { list-style: none; margin: 0; padding: 4px; position: absolute; top: 100%; inset-inline: 0; z-index: 20; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-pop); max-height: 260px; overflow: auto; }
.lookup-list button { width: 100%; text-align: start; border: 0; background: none; padding: 8px 10px; border-radius: 6px; font: inherit; color: var(--text); cursor: pointer; }
.lookup-list button:hover { background: var(--accent-soft); }
.small-link { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.small-link .ic { width: 14px; height: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-days { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.quick-days .chip { height: 28px; padding: 0 10px; cursor: pointer; font: inherit; font-size: 12px; }
.lines { display: grid; gap: 10px; }
.line { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 8px; background: var(--card); }
.line.l-group { background: var(--soft); }
.line.l-text { border-style: dashed; }
.line.is-loss { border-color: var(--warn); }
.line-head { display: flex; gap: 6px; align-items: center; }
.line-handle { display: flex; flex-direction: column; }
.line-handle .x-btn { height: 14px; font-size: 9px; }
.line-name { flex: 1; font-weight: 600; }
.line-desc { min-height: 0; height: auto; font-size: 13px; resize: vertical; }
.line-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.line-nums label { display: grid; gap: 2px; }
.line-nums label > span { font-size: 11px; color: var(--muted); }
.line-nums input, .line-nums select { height: 34px; padding: 0 8px; }
.line-total { display: grid; gap: 2px; align-content: end; }
.line-total span { font-size: 11px; color: var(--muted); }
.line-total strong { height: 34px; display: flex; align-items: center; font-variant-numeric: tabular-nums; }
.loss-warn { margin: 0; font-size: 12px; color: var(--warn); font-weight: 500; }
.add-lines { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-lines { margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.sm-select { height: 30px; font-size: 13px; }
.tpl-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tpl-card { display: grid !important; gap: 6px; cursor: pointer; text-align: center; font-size: 13px; font-weight: 500; }
.tpl-card input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tpl-thumb { display: grid; gap: 4px; align-content: start; height: 86px; padding: 8px; border: 2px solid var(--line); border-radius: 8px; background: #fff; }
.tpl-card input:checked + .tpl-thumb { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl-thumb i { display: block; height: 6px; border-radius: 3px; background: #E4E7EC; }
.tpl-thumb i:first-child { width: 50%; background: var(--accent); }
.tpl-modern i:first-child { width: 100%; height: 18px; border-radius: 4px; }
.tpl-thermal { width: 50%; margin: 0 auto; }
.tpl-thermal i:first-child { width: 70%; margin: 0 auto; background: #98A2B3; }
@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .ed-panel { position: static; max-height: none; min-height: 0; }
  .ed-preview { display: none; }
  .editor.show-preview .ed-preview { display: block; }
  .editor.show-preview .ed-pane { display: none; }
  .only-narrow { display: inline-block; }
  .ed-foot { position: sticky; bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom)); background: var(--card); border-radius: 0 0 var(--radius) var(--radius); }
  .doc-layout { grid-template-columns: 1fr; }
}
@media (min-width: 761px) and (max-width: 1100px) { .ed-foot { bottom: 0; } }
@media (max-width: 760px) {
  .line-nums { grid-template-columns: repeat(2, 1fr); }
  .head-actions { width: 100%; }
  .row-2 { grid-template-columns: 1fr; }
}
.kpi-link { color: inherit; }
.kpi-link:hover { text-decoration: none; border-color: var(--accent-line); }
/* Grid children may shrink below their content (long tab rows scroll inside instead of widening the page). */
.content > *, .editor > *, .ed-panel, .doc-layout > * { min-width: 0; }

/* ---------- Document designs (settings › designs) ---------- */
.lay-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.lay-card { display: grid; gap: 8px; align-content: start; }
.lay-thumb { display: block; height: 250px; overflow: hidden; border-radius: 10px; background: #E9ECF1; border: 1px solid var(--line); position: relative; padding: 10px; }
.lay-thumb:hover { border-color: var(--accent); }
html[data-theme="dark"] .lay-thumb { background: #0B0E13; }
.lay-mini { width: 210mm; transform: scale(.22); transform-origin: top left; pointer-events: none; }
[dir="rtl"] .lay-mini { transform-origin: top right; }
.lay-mini .doc { box-shadow: 0 2px 10px rgba(16, 24, 40, .15); margin: 0; }
.lay-mini .lay-roll { margin-inline: auto; }
.lay-card-body { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lay-card-body small { flex-basis: 100%; }
.lay-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.lay-card-actions form { margin: 0; }
.lay-note { margin: 0 0 8px; font-size: 13px; }
.row-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.color-pair { display: flex; align-items: center; gap: 8px; }
.color-pair input[type="color"] { width: 44px; height: 34px; padding: 2px; flex: none; }
.color-pair select { flex: 1; }
.blk-list, .col-list { display: grid; gap: 6px; }
.blk-row { border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.blk-row.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.blk-row summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none; }
.blk-row summary::-webkit-details-marker { display: none; }
.blk-body { padding: 0 12px 12px; gap: 10px; }
.col-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto auto; gap: 6px; align-items: center; }
.col-row .check { white-space: nowrap; }
.upload-box { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.upload-box input[type="file"] { flex: 1; min-width: 0; }
.img-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.img-list li { display: grid; gap: 4px; justify-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; text-align: center; }
.img-list img { width: 100%; height: 60px; object-fit: contain; background: repeating-conic-gradient(#F2F4F7 0% 25%, #fff 0% 50%) 50% / 12px 12px; border-radius: 4px; }
.designer .ed-fields { display: contents; }
@media (max-width: 760px) { .row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Extra fields (settings) ---------- */
.field-rows { display: grid; gap: 8px; margin-bottom: 14px; }
.field-row fieldset { display: grid; grid-template-columns: minmax(0, 1fr) auto 70px auto auto; gap: 8px; align-items: center; }
.field-row.off input[name="label"] { opacity: .55; }
.inline-form.field-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field-add select { width: auto; }
.field-add input { flex: 1; min-width: 160px; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.set-card { display: grid; gap: 6px; align-content: start; padding: 14px; border: 1px solid var(--line); border-radius: 10px; }
.set-card form { margin: 0; }
@media (max-width: 760px) { .field-row fieldset { grid-template-columns: minmax(0, 1fr) 64px; } }

/* ---------- Payments ---------- */
.pay-form { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.pay-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.pay-list li { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pay-list li.voided strong { text-decoration: line-through; color: var(--muted); }
.pay-list form { margin: 0; }

/* ---------- Receivables ---------- */
.aging-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--soft); margin-bottom: 14px; }
.aging { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.aging-item { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.aging-item:hover, .aging-item.on { border-color: var(--accent); text-decoration: none; }
.aging-item .dot { width: 10px; height: 10px; border-radius: 50%; }
.ag-current { background: #12B76A; } .ag-d30 { background: #FDB022; } .ag-d60 { background: #F79009; } .ag-d90 { background: #F04438; } .ag-older { background: #912018; }
@media (max-width: 760px) { .aging { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.bal-row { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-bottom: 6px; }
.stmt-range { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.stmt-range label { display: grid; gap: 4px; }
.stmt-sec + .stmt-sec { border-top: 1px solid var(--line); }
.stmt-cur { padding: 14px 16px 0; margin: 0; font-size: 15px; }
.table.stmt tfoot th { border-top: 1px solid var(--line-strong); padding-top: 10px; }
.stmt-open td { color: var(--muted); }
