:root {
  --malachite: #0E4D45;
  --malachite-2: #16655B;
  --malachite-3: #0A3B35;
  --gold: #C9A04E;
  --gold-text: #8A6420;
  --gold-wash: #F6EEDC;
  --lapis: #1F3A68;
  --kaolin: #F4F5F1;
  --white: #FFFFFF;
  --ink: #1C2B28;
  --muted: #5E6E6A;
  --line: #DCD9CC;
  --cinnabar: #A8322D;
  --cinnabar-wash: #F7E4E1;
  --ruqaa: 'Aref Ruqaa', serif;
  --sans: 'Tajawal', system-ui, sans-serif;
  --khatam: polygon(50% 0%, 65.3% 13%, 85.4% 14.6%, 87% 34.7%, 100% 50%, 87% 65.3%, 85.4% 85.4%, 65.3% 87%, 50% 100%, 34.7% 87%, 14.6% 85.4%, 13% 65.3%, 0% 50%, 13% 34.7%, 14.6% 14.6%, 34.7% 13%);
  --girih: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23C9A04E' stroke-opacity='.4' stroke-width='1'%3E%3Cpath d='M52 32L43.5 36.8L46.1 46.1L36.8 43.5L32 52L27.2 43.5L17.9 46.1L20.5 36.8L12 32L20.5 27.2L17.9 17.9L27.2 20.5L32 12L36.8 20.5L46.1 17.9L43.5 27.2Z'/%3E%3Cpath d='M20 0L11.5 4.8L14.1 14.1L4.8 11.5L0 20M64 20L59.2 11.5L49.9 14.1L52.5 4.8L44 0M44 64L52.5 59.2L49.9 49.9L59.2 52.5L64 44M0 44L4.8 52.5L14.1 49.9L11.5 59.2L20 64'/%3E%3Ccircle cx='32' cy='32' r='5'/%3E%3Cpath d='M52 32H58M6 32H12M32 52V58M32 6V12M58 32L64 26M58 32L64 38M6 32L0 26M6 32L0 38M32 58L26 64M32 58L38 64M32 6L26 0M32 6L38 0'/%3E%3C/g%3E%3C/svg%3E");
  --girih-faint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%230E4D45' stroke-opacity='.07' stroke-width='1'%3E%3Cpath d='M52 32L43.5 36.8L46.1 46.1L36.8 43.5L32 52L27.2 43.5L17.9 46.1L20.5 36.8L12 32L20.5 27.2L17.9 17.9L27.2 20.5L32 12L36.8 20.5L46.1 17.9L43.5 27.2Z'/%3E%3Cpath d='M20 0L11.5 4.8L14.1 14.1L4.8 11.5L0 20M64 20L59.2 11.5L49.9 14.1L52.5 4.8L44 0M44 64L52.5 59.2L49.9 49.9L59.2 52.5L64 44M0 44L4.8 52.5L14.1 49.9L11.5 59.2L20 64'/%3E%3Ccircle cx='32' cy='32' r='5'/%3E%3Cpath d='M52 32H58M6 32H12M32 52V58M32 6V12M58 32L64 26M58 32L64 38M6 32L0 26M6 32L0 38M32 58L26 64M32 58L38 64M32 6L26 0M32 6L38 0'/%3E%3C/g%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--kaolin); color: var(--ink); font: 400 16px/1.65 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn { border: 1px solid var(--line); background: var(--white); padding: 8px 18px; border-radius: 999px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--gold); }
.btn-main { background: var(--malachite); color: var(--white); border-color: var(--malachite); box-shadow: inset 0 0 0 2px var(--malachite), inset 0 0 0 3px var(--gold); }
.btn-main:hover { background: var(--malachite-2); border-color: var(--malachite-2); }
.btn-danger { color: var(--cinnabar); }
.btn-danger.is-armed, .c-danger.is-armed { background: var(--cinnabar); border-color: var(--cinnabar); color: var(--white); }

/* زخرفة فاصلة: خطان ونجمة ثمانية بينهما */
.orn { display: flex; align-items: center; gap: 10px; color: var(--gold); }
.orn::before, .orn::after { content: ""; flex: 1; border-top: 1px solid currentColor; opacity: .7; }
.orn svg { flex: none; }

/* ---------- الدخول ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login-org { background: var(--malachite) var(--girih); color: var(--white); padding: 48px; display: grid; align-content: center; justify-items: center; gap: 28px; text-align: center; }
.login-org h1 { font: 700 46px/1.8 var(--ruqaa); margin: 0; color: var(--white); }
.login-org .orn { width: min(360px, 100%); }
.mini-org { display: grid; justify-items: center; gap: 10px; font-size: 13px; }
.mini-org span { border: 1px solid var(--gold); padding: 4px 14px; border-radius: 999px; background: var(--malachite-3); }
.mini-org .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.mini-org .stem { width: 1px; height: 12px; background: var(--gold); }
.login-panel { padding: 48px clamp(16px, 5vw, 64px); display: grid; place-items: center; background: var(--kaolin) var(--girih-faint); }
.arch { width: min(440px, 100%); background: var(--white); border: 4px double var(--gold); border-radius: 220px 220px 14px 14px / 150px 150px 14px 14px; padding: 92px 32px 32px; display: grid; gap: 22px; position: relative; }
.arch::before { content: ""; position: absolute; top: 34px; left: 50%; width: 30px; height: 30px; transform: translateX(-50%); background: var(--gold); clip-path: var(--khatam); }
.arch h2 { font: 700 28px/1.4 var(--ruqaa); margin: 0; text-align: center; color: var(--malachite); }
.login-form { display: grid; gap: 14px; }

/* ---------- الحقول ---------- */
.f { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.f-field { display: grid; gap: 4px; font-weight: 500; font-size: 15px; }
.f-wide { grid-column: 1 / -1; }
.f-field input:not([type=range]), .f-field select, .f-field textarea, .c textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--white); font-weight: 400;
}
.f-field input:focus, .f-field select:focus, .f-field textarea:focus, .c textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-wash); }
.f-field input[type=range] { accent-color: var(--malachite); width: 100%; }
.f-field output { color: var(--malachite); font-weight: 700; }
.f-note { grid-column: 1 / -1; margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--gold-wash); border: 1px solid var(--gold); }
.f-error { grid-column: 1 / -1; margin: 0; color: var(--cinnabar); font-weight: 500; }

/* ---------- الهيكل ---------- */
.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--malachite) var(--girih); color: var(--white); position: sticky; top: 0; height: 100vh; overflow-y: auto; border-inline-end: 4px double var(--gold); scrollbar-width: thin; scrollbar-color: var(--gold) transparent; }
.side-inner { padding: 22px 18px; }
.side-brand { text-align: center; padding: 6px 0 14px; }
.side-brand h1 { font: 700 26px/2 var(--ruqaa); margin: 0; }
.side-brand p { margin: 0 0 12px; font-size: 14px; color: #E4D3A8; }
.tree-box { margin-top: 18px; background: rgba(10, 59, 53, .82); border: 1px solid rgba(201, 160, 78, .45); border-radius: 14px; padding: 12px 10px; }
.tree-box summary { list-style: none; font: 700 18px/1.5 var(--ruqaa); color: #E4D3A8; margin: 0 4px 8px; cursor: default; }
.tree-box summary::-webkit-details-marker { display: none; }
.tree-box summary small { display: block; font: 400 13px/1.5 var(--sans); color: rgba(255,255,255,.7); }

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-inline-start: 18px; }
.tree li { position: relative; }
.tree ul > li::before { content: ""; position: absolute; inset-inline-start: -10px; top: 0; bottom: 0; border-inline-start: 1px solid rgba(201, 160, 78, .55); }
.tree ul > li:last-child::before { bottom: auto; height: 22px; }
.tree ul > li::after { content: ""; position: absolute; inset-inline-start: -10px; top: 22px; width: 10px; border-top: 1px solid rgba(201, 160, 78, .55); }
.node { width: 100%; text-align: right; background: transparent; border: 1px solid transparent; color: var(--white); border-radius: 10px; padding: 6px 10px; margin: 2px 0; cursor: pointer; display: grid; line-height: 1.35; }
.node:hover:not(:disabled) { background: var(--malachite-2); border-color: rgba(201, 160, 78, .4); }
.node.is-focus { background: var(--gold-wash); color: var(--ink); border: 1px solid var(--gold); box-shadow: inset 0 0 0 3px var(--gold-wash), inset 0 0 0 4px rgba(201, 160, 78, .6); }
.node:disabled { opacity: .45; cursor: default; }
.n-name { font-weight: 700; font-size: 15px; }
.n-title { font-size: 12px; opacity: .78; }
.n-load { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-top: 2px; }
.n-load em { font-style: normal; display: inline-grid; place-items: center; min-width: 22px; height: 22px; background: var(--cinnabar); color: var(--white); clip-path: var(--khatam); font-size: 11px; font-weight: 700; }
.n-me { font-size: 11px; color: var(--gold); font-weight: 700; }
.is-focus .n-me { color: var(--gold-text); }
.side-foot { margin-top: 20px; font-size: 13px; color: rgba(255,255,255,.8); text-align: center; }
.side-foot button { background: none; border: 0; color: #E4D3A8; text-decoration: underline; cursor: pointer; padding: 0; }

.main { padding: 0 clamp(16px, 3vw, 40px) 48px; min-width: 0; }
.cartouche { margin: 24px 0 0; padding: 20px 24px 18px; background: var(--white) var(--girih-faint); border: 4px double var(--gold); border-radius: 18px; position: relative; }
.cartouche::before, .cartouche::after { content: ""; position: absolute; top: -12px; width: 20px; height: 20px; background: var(--gold); clip-path: var(--khatam); }
.cartouche::before { inset-inline-start: 24px; }
.cartouche::after { inset-inline-end: 24px; }
.main-top { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.focus h2 { font: 700 34px/1.7 var(--ruqaa); margin: 0; color: var(--malachite); }
.focus .ft { color: var(--muted); }
.me { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.me-text { display: grid; line-height: 1.35; text-align: left; }
.me-text span { color: var(--muted); font-size: 13px; }
.cartouche .orn { margin: 12px 0 10px; }
.summary { font-size: 18px; margin: 0 0 4px; max-width: 70ch; }
.summary b { color: var(--malachite); }
.summary .late-n { color: var(--cinnabar); }
.perm { color: var(--muted); font-size: 14px; margin: 0; }

.bar-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 22px 0 16px; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 4px 14px; cursor: pointer; font-size: 14px; }
.seg button:hover { border-color: var(--gold); }
.seg button[aria-pressed=true] { background: var(--malachite); color: var(--white); border-color: var(--gold); }
.bar-tools .btn-main { margin-inline-start: auto; }

.group { margin-bottom: 26px; }
.group-head { display: flex; align-items: center; gap: 10px; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--gold); position: relative; }
.group-head::after { content: ""; position: absolute; inset-inline-start: 0; bottom: -4px; width: 100%; border-bottom: 1px solid rgba(201, 160, 78, .45); }
.group-head i { width: 14px; height: 14px; background: var(--gold); clip-path: var(--khatam); flex: none; }
.group-head h3 { font: 700 21px/1.8 var(--ruqaa); margin: 0; color: var(--malachite); }
.group-head span { color: var(--muted); font-size: 14px; }
.task { display: grid; grid-template-columns: minmax(0, 1fr) 130px 150px 120px; gap: 14px; align-items: center; padding: 11px 10px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.task:hover { background: var(--white); box-shadow: inset 3px 0 0 var(--gold); }
.t-title { font-weight: 500; }
.t-sub { font-size: 13px; color: var(--muted); }
.t-sub .urgent { color: var(--cinnabar); font-weight: 700; }
.chip { justify-self: start; font-size: 13px; padding: 1px 10px; border-radius: 999px; background: #E9ECE6; white-space: nowrap; }
.chip-doing { background: var(--gold-wash); color: var(--gold-text); }
.chip-review { background: #E3E8F2; color: var(--lapis); }
.chip-done { background: var(--malachite); color: var(--white); }
.prog { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; }
.prog span { flex: 1; height: 6px; border-radius: 3px; background: #E6E6DE; overflow: hidden; }
.prog i { display: block; height: 100%; width: var(--p); background: var(--gold); }
.task.is-done .prog i { background: var(--malachite); }
.t-due { font-size: 14px; color: var(--muted); }
.is-late .t-due { color: var(--cinnabar); font-weight: 700; }
.none { padding: 32px; text-align: center; color: var(--muted); border: 1px dashed var(--gold); border-radius: 14px; background: var(--white); }

/* ---------- الدرج الجانبي ---------- */
dialog.drawer { margin: 0; margin-inline-start: auto; height: 100vh; height: 100dvh; max-height: 100dvh; width: min(580px, 100vw); max-width: 100vw; border: 0; border-inline-start: 4px double var(--gold); padding: 0; color: var(--ink); background: var(--white); }
dialog.drawer[open] { animation: slide .22s ease-out; }
@keyframes slide { from { transform: translateX(-40px); opacity: 0; } }
dialog::backdrop { background: rgba(10, 40, 36, .45); }
.d-head { padding: 22px 24px 18px; background: var(--malachite) var(--girih); color: var(--white); position: sticky; top: 0; z-index: 1; border-bottom: 4px double var(--gold); }
.d-head .code { color: #E4D3A8; font-size: 14px; }
.d-head h2 { font: 700 24px/1.9 var(--ruqaa); margin: 2px 0 0; padding-inline-end: 40px; }
.x { position: absolute; inset-inline-end: 16px; top: 18px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--gold); background: var(--malachite-3); color: var(--white); cursor: pointer; font-size: 20px; line-height: 1; }
.d-body { padding: 20px 24px 28px; display: grid; gap: 20px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin: 0; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.desc { margin: 0; }
.big-prog { background: var(--gold-wash); border: 1px solid rgba(201, 160, 78, .5); border-radius: 12px; padding: 14px 16px; display: grid; gap: 8px; }
.big-prog .r { display: flex; justify-content: space-between; font-weight: 700; }
.big-prog .prog span { height: 10px; border-radius: 5px; background: var(--white); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.d-body h3 { font: 700 21px/1.8 var(--ruqaa); margin: 0 0 10px; color: var(--malachite); }

/* ---------- التعليقات ---------- */
.c-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 12px; }
.c-item { display: grid; gap: 2px; }
.c-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 15px; }
.c-avatar { width: 30px; height: 30px; background: var(--malachite); color: var(--white); display: grid; place-items: center; font-size: 13px; font-weight: 700; clip-path: var(--khatam); }
.c-mine .c-avatar { background: var(--gold); color: var(--ink); }
.c-role { color: var(--muted); font-size: 13px; }
.c-head time { margin-inline-start: auto; color: var(--muted); font-size: 13px; }
.c-text { margin: 0; padding: 8px 14px; background: var(--kaolin); border-radius: 4px 14px 14px 14px; margin-inline-start: 38px; white-space: pre-wrap; }
.c-mine .c-text { background: var(--gold-wash); }
.c-system { display: flex; gap: 8px; color: var(--muted); font-size: 14px; padding-inline-start: 38px; }
.c-system p { margin: 0; }
.c-system p::before { content: "✦ "; color: var(--gold); }
.c-system time { margin-inline-start: auto; white-space: nowrap; }
.c-empty { color: var(--muted); }
.c-actions { display: flex; gap: 6px; margin-inline-start: 38px; margin-top: 4px; }
.c-btn { border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 0 12px; font-size: 13px; cursor: pointer; }
.c-btn:hover { border-color: var(--gold); }
.c-danger { color: var(--cinnabar); }
.c-edit-form { margin-inline-start: 38px; }
.c-form { display: grid; gap: 8px; }
.c-submit { justify-self: start; background: var(--malachite); color: var(--white); border: 0; border-radius: 999px; padding: 7px 18px; cursor: pointer; font-weight: 500; box-shadow: inset 0 0 0 2px var(--malachite), inset 0 0 0 3px var(--gold); }

.toasts { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--malachite-3); color: var(--white); padding: 9px 20px; border-radius: 999px; font-weight: 500; border: 1px solid var(--gold); }
.toast-error { background: var(--cinnabar); }

@media (max-width: 1100px) {
  .task { grid-template-columns: minmax(0, 1fr) 120px 110px; }
  .task .t-due { grid-column: 1 / -1; margin-top: -8px; }
}
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-org { padding: 32px 16px; }
  .login-org h1 { font-size: 36px; }
  .login-panel { padding: 24px 16px 40px; }
  .arch { padding: 84px 20px 24px; }
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-inline-end: 0; border-bottom: 4px double var(--gold); }
  .side-inner { padding: 16px; }
  .tree-box summary { cursor: pointer; }
  .main { padding: 0 16px 40px; }
  .cartouche { padding: 18px 16px 16px; }
  .focus h2 { font-size: 28px; }
  .me-text { display: none; }
  .task { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .task .prog { grid-column: 1 / -1; }
  .f { grid-template-columns: 1fr; }
  .facts { gap: 8px 14px; }
}
@media (prefers-reduced-motion: reduce) { dialog.drawer[open] { animation: none; } }

/* ---------- إضافات النسخة الفعلية ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; background: var(--malachite) var(--girih); color: #E4D3A8; font: 700 28px/1.8 var(--ruqaa); }
.me-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-quiet { padding: 6px 14px; font-size: 14px; }
.f-check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.f-check input { width: 18px; height: 18px; accent-color: var(--malachite); }
.f-hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.btn[disabled], .c-submit[disabled] { opacity: .6; cursor: progress; }

.ulist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.urow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.urow b { font-weight: 700; }
.urow .meta { font-size: 13px; color: var(--muted); grid-column: 1; }
.urow .btn { grid-row: span 2; grid-column: 2; }
.urow.is-off { opacity: .6; }
.tag-admin { font-size: 12px; background: var(--gold-wash); color: var(--gold-text); border: 1px solid var(--gold); border-radius: 999px; padding: 0 8px; margin-inline-start: 6px; }
.tag-off { font-size: 12px; background: var(--cinnabar-wash); color: var(--cinnabar); border-radius: 999px; padding: 0 8px; margin-inline-start: 6px; }
.users-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------- التوقيع ---------- */
.credit { margin-top: 40px; padding-top: 14px; border-top: 1px solid rgba(201, 160, 78, .5); text-align: center; font-size: 13px; color: var(--muted); }
.credit a { color: var(--gold-text); text-decoration: none; }
.credit a:hover { text-decoration: underline; }
.login-panel { grid-template-rows: 1fr auto; }
.login-panel .credit { border-top: 0; margin-top: 24px; padding-top: 0; justify-self: center; align-self: end; }

/* ---------- الجوال ---------- */
@media (max-width: 820px) {
  /* iOS يكبّر الصفحة عند التركيز على حقل أصغر من 16px */
  .f-field input:not([type=range]), .f-field select, .f-field textarea, .c textarea { font-size: 16px; }
  .seg button, .btn, .c-btn, .c-submit, .node { min-height: 40px; }
  .seg { gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding-inline: 16px; width: calc(100% + 32px); }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { white-space: nowrap; flex: none; }
  .bar-tools .btn-main { width: 100%; margin-inline-start: 0; }
  .side-brand { padding: 0; }
  .side-brand h1 { font-size: 22px; }
  .side-brand .orn { display: none; }
  .tree-box { margin-top: 10px; }
  .tree-box summary { margin: 0 4px; }
  .tree-box[open] summary { margin-bottom: 8px; }
  .tree-box summary { position: relative; padding-inline-end: 28px; }
  .tree-box summary::after { content: "▾"; position: absolute; inset-inline-end: 0; top: 2px; color: var(--gold); font-size: 20px; }
  .tree-box[open] summary::after { content: "▴"; }
  .main-top { flex-direction: column; gap: 10px; }
  .me { margin-inline-start: 0; width: 100%; }
  .me-actions { width: 100%; }
  .me-actions .btn { flex: 1 1 auto; white-space: nowrap; padding: 6px 10px; font-size: 14px; }
  .summary { font-size: 16px; }
  .d-head { padding: 16px; }
  .d-head h2 { font-size: 20px; }
  .d-body { padding: 16px 16px 32px; }
  .actions .btn, .form-actions .btn { flex: 1; }
  .c-text, .c-actions, .c-edit-form { margin-inline-start: 0; }
  .c-system { padding-inline-start: 0; }
  .toasts { inset-inline-start: 16px; inset-inline-end: 16px; transform: none; bottom: max(16px, env(safe-area-inset-bottom)); }
  .toast { text-align: center; }
  .arch { border-radius: 160px 160px 14px 14px / 110px 110px 14px 14px; }
}
