:root {
  --brand: #950d0f;
  --brand-600: #7c0a0c;
  --brand-50: #fbeeee;
  --ink: #111111;
  --ink-2: #3b3b3b;
  --muted: #6b6b6b;
  --line: #e7e5e4;
  --bg: #f6f5f4;
  --card: #ffffff;
  --ok: #157f3d;   --ok-bg: #e8f6ee;
  --warn: #a15c00; --warn-bg: #fff4e0;
  --info: #1d4ed8; --info-bg: #e8efff;
  --gray-bg: #efefef;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Cairo", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; white-space: nowrap; }

/* boot / spinner */
.boot { min-height: 100vh; display: grid; place-items: center; align-content: center; gap: 24px; }
.boot img { width: 160px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: grid; place-items: center; padding: 56px 0; }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--ink); color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 56px; gap: 16px; }
.auth-side h2 { font-size: 30px; font-weight: 800; }
.auth-side p { color: #c9c9c9; max-width: 420px; }
.auth-side .bar { width: 56px; height: 4px; background: var(--brand); border-radius: 2px; }
.auth-main { display: grid; place-items: center; padding: 32px 20px; background: #fff; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card img { width: 140px; display: block; margin: 0 auto 24px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; text-align: center; }
.auth-card .sub { color: var(--muted); text-align: center; margin-bottom: 24px; }
.auth-switch { text-align: center; margin-top: 16px; color: var(--muted); }
.auth-switch button { background: none; border: 0; color: var(--brand); font-weight: 700; cursor: pointer; }

/* layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: #ddd; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; }
.sidebar .logo { background: #fff; border-radius: 10px; padding: 10px; margin-bottom: 20px; display: grid; place-items: center; }
.sidebar .logo img { width: 110px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav .group { font-size: 12px; color: #8a8a8a; margin: 14px 10px 4px; }
.nav a { color: #d6d6d6; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; font-weight: 600; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: #1f1f1f; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.me { border-top: 1px solid #2a2a2a; padding-top: 14px; margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.me .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; flex: none; }
.me .who { flex: 1; min-width: 0; }
.me .who b { display: block; color: #fff; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who span { font-size: 12px; color: #9a9a9a; }
.me button svg { width: 18px; height: 18px; display: block; }
.me button { background: none; border: 1px solid #333; color: #ccc; border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.me button:hover { border-color: var(--brand); color: #fff; }

.topbar { display: none; }
.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 800; }
.page-head .crumbs { color: var(--muted); font-size: 13px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 18px 20px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 2px; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.accent { border-top: 3px solid var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.project-card h3 { font-size: 18px; font-weight: 800; }
.project-card .meta { color: var(--muted); font-size: 13px; }
.bar-track { height: 8px; background: var(--gray-bg); border-radius: 4px; overflow: hidden; display: flex; }
.bar-track span { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 4px; }
.project-card .foot { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 9px; padding: 8px 16px; font-weight: 700; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap; min-height: 40px; }
.btn:hover { background: var(--brand-600); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: #cfcfcf; background: #fafafa; }
.btn.dark { background: var(--ink); }
.btn.dark:hover { background: #2a2a2a; }
.btn.danger { background: #fff; color: #b42318; border-color: #f2c9c5; }
.btn.danger:hover { background: #fdf0ef; }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--ink-2); }
.icon-btn:hover { background: var(--gray-bg); }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field label .req { color: var(--brand); }
.field .help { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; border: 1px solid #d6d3d1; border-radius: 9px; padding: 9px 12px; background: #fff; min-height: 42px; }
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { outline: 2px solid rgba(149,13,15,.25); border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: #fdf0ef; color: #b42318; border: 1px solid #f2c9c5; border-radius: 9px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.form-section { font-weight: 800; margin: 6px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line); grid-column: 1 / -1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--ink); color: #fff; }

/* filters */
.filters { display: grid; grid-template-columns: 2fr repeat(5, 1fr); gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.filters .input { min-height: 38px; padding: 6px 10px; }

/* table */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: start; font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 16px; background: #fafaf9; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { white-space: nowrap; padding: 12px 16px; border-bottom: 1px solid #f0efee; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fcfbfb; }
.tbl td.acts { text-align: end; white-space: nowrap; }
.tbl td.acts > * + * { margin-inline-start: 4px; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-available, .b-active { color: var(--ok); background: var(--ok-bg); }
.b-reserved, .b-draft { color: var(--warn); background: var(--warn-bg); }
.b-sold { color: var(--brand); background: var(--brand-50); }
.b-completed, .b-info { color: var(--info); background: var(--info-bg); }
.b-cancelled, .b-muted { color: #555; background: var(--gray-bg); }
.b-admin { color: #fff; background: var(--ink); }
.b-sales { color: var(--brand); background: var(--brand-50); }
.b-accounting { color: var(--info); background: var(--info-bg); }
.b-pending { color: var(--warn); background: var(--warn-bg); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,17,17,.45); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.lg { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 18px; font-weight: 800; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-start; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }

/* toasts */
#toasts { position: fixed; bottom: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); min-width: 240px; max-width: 380px; border-inline-start: 4px solid var(--ok); animation: fade .2s; }
.toast.error { border-inline-start-color: #f04438; }

/* misc */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0efee; }
.list-plain li:last-child { border-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 12px 14px; font-weight: 600; margin-bottom: 16px; }
.dropzone { border: 2px dashed #d6d3d1; border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone:hover { border-color: var(--brand); color: var(--brand); }
.diff { font-size: 12px; color: var(--ink-2); }
.diff code { background: var(--gray-bg); padding: 0 4px; border-radius: 4px; }


/* language switch */
.lang-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink-2); font-family: inherit; }
.lang-btn svg { width: 16px; height: 16px; }
.lang-btn.side { color: #d6d6d6; border-color: #333; margin-top: 10px; }
.lang-btn.side:hover { border-color: var(--brand); color: #fff; }
.lang-btn.ghosty:hover, .lang-btn.compact:hover { border-color: var(--brand); color: var(--brand); }
.auth-lang { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.lang-btn span { font-family: "Cairo", system-ui, sans-serif; }

/* permissions editor */
.perm-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.perm-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.perm-group h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.perm-group label { display: flex; gap: 8px; align-items: flex-start; padding: 4px 0; cursor: pointer; font-size: 14px; }
.perm-group input { margin-top: 5px; accent-color: var(--brand); }
.perm-group input:disabled + span { color: var(--muted); }
.perm-chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 360px; white-space: normal; }
.chip { font-size: 11px; background: var(--gray-bg); border-radius: 6px; padding: 1px 7px; color: var(--ink-2); }
.pass-row { display: flex; gap: 8px; }
.pass-row .input { flex: 1; }
.switch-row { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.switch-row input { accent-color: var(--brand); width: 18px; height: 18px; }

/* project media */
.project-card { overflow: hidden; }
.project-cover { display: block; margin: -20px -20px 4px; aspect-ratio: 16 / 9; background: var(--gray-bg); overflow: hidden; }
.project-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.project-cover:hover img { transform: scale(1.03); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; position: relative; }
.gallery .thumb { display: block; width: 100%; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: zoom-in; background: var(--gray-bg); aspect-ratio: 4 / 3; }
.gallery .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery figcaption { font-size: 12px; color: var(--ink-2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery .file-tools { position: absolute; top: 4px; inset-inline-end: 4px; display: flex; gap: 2px; background: rgba(255,255,255,.92); border-radius: 6px; }
#docs .file-tools { display: inline-flex; gap: 2px; }
.modal.xl { max-width: 1100px; }
.lightbox img { width: 100%; max-height: 70vh; object-fit: contain; display: block; background: #111; border-radius: 8px; }
.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.price-pick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* print (contract document) */
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  body { background: #fff; }
  @page { margin: 18mm; }
}
.doc { font-size: 14px; color: #000; }
.doc header { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 18px; }
.doc header img { width: 110px; }
.doc h1 { font-size: 22px; }
.doc table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.doc th, .doc td { border: 1px solid #bbb; padding: 7px 10px; text-align: start; }
.doc th { background: #f3f3f3; width: 30%; }
.doc h2 { font-size: 16px; margin: 18px 0 8px; color: var(--brand); }
.doc .sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 56px; }
.doc .sign div { border-top: 1px solid #000; padding-top: 6px; text-align: center; }

/* responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 270px; z-index: 40; transform: translateX(100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  [dir="ltr"] .sidebar { inset: 0 auto 0 0; transform: translateX(-100%); }
  [dir="ltr"] .sidebar.open { transform: none; }
  .perm-groups { grid-template-columns: 1fr; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; display: none; }
  .scrim.show { display: block; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .topbar img { height: 36px; }
  .main { padding: 18px 14px 40px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 110px 1fr; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 22px; }
  .filters { grid-template-columns: 1fr 1fr; padding: 12px; }
  .filters .search { grid-column: 1 / -1; }
  .page-head h1 { font-size: 20px; }
  .tbl.responsive thead { display: none; }
  .tbl.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .tbl.responsive td { display: block; text-align: end; border: 0; padding: 4px 14px; white-space: normal; overflow: hidden; }
  .tbl.responsive td::before { content: attr(data-label); float: inline-start; margin-inline-end: 12px; color: var(--muted); font-size: 12px; font-weight: 600; }
  .tbl.responsive td.acts { display: flex; }
  .tbl.responsive td.acts::before { content: none; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { max-height: 92vh; border-radius: 14px 14px 0 0; }
  #toasts { inset-inline: 10px; }
}

/* inline icons inside lists and text */
.list-plain svg, .card-pad p svg { width: 16px; height: 16px; vertical-align: -3px; flex: none; }
.icon-btn svg { width: 18px; height: 18px; display: block; }

.me .who[role=button] { cursor: pointer; border-radius: 8px; }
.me .who[role=button]:hover b { text-decoration: underline; }
