/* ===== نظام الجرد — نمط "الملف الزمردي" (Emerald Dossier) ===== */

:root {
    color-scheme: dark;
    --bg: #0a0c0b;
    --surface: #111514;
    --surface-2: #171d1b;
    --line: #26302c;
    --line-strong: #35443e;
    --accent: #45d69a;
    --accent-ink: #06231a;
    --accent-dim: rgba(69, 214, 154, 0.14);
    --text: #e9edeb;
    --muted: #9aa8a2;
    --faint: #6b7772;
    --danger: #ef6a62;
    --danger-dim: rgba(239, 106, 98, 0.12);
    --nitro: #b18cff;
    --nitro-dim: rgba(177, 140, 255, 0.14);
    --mono: "Cascadia Mono", ui-monospace, "Courier New", monospace;
    --r: 10px;
}

@font-face {
    font-family: "Thmanyah Sans";
    src: url("assets/fonts/sans/thmanyahsans-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Thmanyah Sans";
    src: url("assets/fonts/sans/thmanyahsans-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Thmanyah Sans";
    src: url("assets/fonts/sans/thmanyahsans-Black.woff2") format("woff2");
    font-weight: 900;
    font-style: normal;
    font-display: swap;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Thmanyah Sans", "Segoe UI", Tahoma, Arial, sans-serif;
    line-height: 1.7;
    font-size: 16px;
}

.app {
    width: min(1200px, 100vw - 32px);
    margin: 0 auto;
    padding: 24px 0 40px;
}

/* ===== الشريط العلوي ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.topbar-brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 54px; height: 54px; object-fit: contain; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 900; line-height: 1.3; }
.subtitle { color: var(--muted); font-size: 13px; }
.topbar-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.meta-pill {
    display: inline-block;
    padding: 2px 10px;
    border: 1px solid var(--accent);
    background: var(--accent-dim);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    border-radius: 4px;
}
.meta-code { font-family: var(--mono); color: var(--faint); font-size: 12px; letter-spacing: 2px; }

/* ===== التخطيط ===== */
.layout {
    display: grid;
    grid-template-columns: 264px 1fr;
    gap: 20px;
    margin-top: 20px;
    align-items: start;
}

/* ===== الشريط الجانبي ===== */
.rail {
    position: sticky;
    top: calc(var(--topbar-h, 88px) + 14px);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.stepper {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.step {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    text-align: start;
    cursor: pointer;
}
.step:last-child { border-bottom: 0; }
.step:disabled { cursor: not-allowed; opacity: 0.55; }
.step-num {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 13px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    color: var(--muted);
}
.step-info { display: flex; flex-direction: column; line-height: 1.4; }
.step-name { font-weight: 700; }
.step-state { font-size: 12px; color: var(--faint); }
.step.is-current {
    background: var(--surface-2);
    box-shadow: inset 3px 0 0 var(--accent);
}
.step.is-current .step-num { border-color: var(--accent); color: var(--accent); }
.step.is-done .step-num {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
}

.rail-block {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 14px 16px;
}
.rail-block h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 900;
    color: var(--faint);
}
.rail-check { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--muted); }
.rail-check li { padding: 3px 0; }
.rail-check li::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.rail-value { font-size: 18px; font-weight: 900; color: var(--accent); }
.rail-hint { font-size: 12px; color: var(--faint); }

/* ===== اللوحات ===== */
.content { min-width: 0; }
.panel {
    display: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 20px;
}
.panel.is-open { display: block; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 1px dashed var(--line-strong);
}
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.panel-tag {
    padding: 2px 10px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    border-radius: 4px;
    white-space: nowrap;
}
.panel-foot {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px dashed var(--line-strong);
}
.panel-foot.split { justify-content: space-between; }
.panel-foot.center { justify-content: center; }

/* ===== شاشة البداية ===== */
.start-hero { text-align: center; padding: 40px 16px 30px; }
.start-logo { width: 110px; height: 110px; object-fit: contain; margin-bottom: 14px; }
.start-hero h2 { margin: 0; font-size: 28px; font-weight: 900; }
.start-sub { margin: 4px 0 0; color: var(--accent); font-weight: 700; }
.start-note { max-width: 520px; margin: 14px auto 26px; color: var(--muted); font-size: 14px; }
.btn-wide { min-width: 220px; }

/* ===== الأزرار ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 18px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s ease, color 0.15s ease, filter 0.15s ease;
}
.btn-solid { background: var(--accent); color: var(--accent-ink); }
.btn-solid:hover { filter: brightness(1.1); }
.btn-ghost { border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-small { min-height: 34px; font-size: 13px; padding: 0 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ===== الحقول ===== */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 5px; }
.field-full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 700; color: var(--muted); }
.field small { font-size: 12px; color: var(--faint); }

textarea, select, input[type="text"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    min-height: 42px;
    padding: 8px 12px;
    outline: none;
}
textarea:focus, select:focus, input:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.input-box { min-height: 130px; font-family: var(--mono); font-size: 13px; }
.input-box-short { min-height: 90px; }

.output {
    font-family: var(--mono);
    font-size: 13px;
    min-height: 150px;
    background: var(--bg);
    cursor: pointer;
}
.output-tall { min-height: 300px; }
.part-output { min-height: 220px; }
#reportParts .field { margin-bottom: 18px; }

/* زر Nitro Copy — نفس تشريح أزرار النظام (حد 1px، نصف قطر 6) بلون مميز */
.nitro-row { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--line-strong); }
.nitro-row .btn {
    border: 1px solid var(--nitro);
    color: var(--nitro);
    background: var(--nitro-dim);
}
.nitro-row .btn:hover { background: var(--nitro); color: var(--accent-ink); border-color: var(--nitro); }

/* ===== الأخطاء والتنبيهات ===== */
.errors {
    margin-top: 14px;
    padding: 10px 14px;
    background: var(--danger-dim);
    border: 1px solid var(--danger);
    color: var(--danger);
    font-size: 13px;
    border-radius: 6px;
}
.hint-bar {
    margin-top: 12px;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 13px;
    border-radius: 6px;
}
.fallback {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 13px;
    border-radius: 6px;
}
.fallback-actions { display: inline-flex; gap: 8px; }

.fetch-status { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.fetch-status b { color: var(--accent); }
.fetch-status.is-error { color: var(--danger); }

/* ===== القوائم (تحقق / يدوي / مراجعة) ===== */
.list-head { font-size: 13px; color: var(--muted); margin: 14px 0 8px; }
.list-head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.list-head-row .list-head { margin: 14px 0 8px; }
.list-head b { color: var(--accent); }
.flag-head { color: var(--danger); }
.list {
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}
.list-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    font-size: 14px;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row.is-flagged { box-shadow: inset 3px 0 0 var(--danger); }
.list-row.is-excluded { opacity: 0.55; }

.row-who { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.row-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-id { font-family: var(--mono); font-size: 12px; color: var(--faint); direction: ltr; text-align: end; }
.row-ctl { display: inline-flex; align-items: center; gap: 6px; }
.row-ctl label { font-size: 12px; color: var(--faint); white-space: nowrap; }
.row-ctl select { min-height: 34px; width: auto; font-size: 13px; padding: 4px 8px; }

.chip {
    display: inline-block;
    padding: 1px 8px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    border-radius: 4px;
    white-space: nowrap;
}
.chip-accent { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.chip-danger { border-color: var(--danger); color: var(--danger); background: var(--danger-dim); }
.badge-num {
    font-family: var(--mono);
    font-weight: 700;
    color: var(--accent);
    direction: ltr;
    white-space: nowrap;
}
.row-outcome { flex: 1 1 100%; font-size: 13px; color: var(--muted); }
.row-outcome b { color: var(--accent); }
.row-outcome .flag { color: var(--danger); font-weight: 700; }
.row-outcome .flag-ceiling { color: var(--accent); font-weight: 700; }

/* مربع الاستبعاد */
.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.check input {
    appearance: none;
    width: 16px;
    height: 16px;
    margin: 0;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
}
.check input::before { content: "✓"; font-size: 11px; color: var(--accent-ink); transform: scale(0); }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::before { transform: scale(1); }

/* ===== العدادات ===== */
.meter {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.meter-cell {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
}
.meter-cell b { font-size: 20px; font-weight: 900; color: var(--accent); }
.meter-cell span { font-size: 12px; color: var(--faint); }

/* ===== التذييل ===== */
.footer {
    margin-top: 24px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}
.credit { font-size: 13px; color: var(--faint); text-align: center; }
.credit b { color: var(--accent); font-weight: 700; }

/* ===== التوست ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translate(-50%, 16px);
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 14px;
    font-weight: 700;
    padding: 10px 22px;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== الاستجابة ===== */
@media (max-width: 920px) {
    .layout { grid-template-columns: 1fr; }
    .rail { position: static; }
    .stepper { flex-direction: row; }
    .step {
        flex: 1 1 0;
        flex-direction: column;
        gap: 6px;
        padding: 10px 4px;
        border-bottom: 0;
        border-inline-end: 1px solid var(--line);
        text-align: center;
    }
    .step:last-child { border-inline-end: 0; }
    .step-state { display: none; }
    .step.is-current { box-shadow: inset 0 -3px 0 var(--accent); }
    .fields { grid-template-columns: 1fr; }
    .rail-block { display: none; }
}
@media (max-width: 560px) {
    .topbar { position: static; flex-direction: column; align-items: flex-start; }
    .topbar-meta { align-items: flex-start; }
    .meter-cell b { font-size: 15px; }
    .meter-cell span { font-size: 10px; }
    .step-name { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
