/* ===== الخطوط والأساسيات ===== */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    --gold: #9b7b40;          /* لون ترويسة الجداول الذهبي/البني */
    --gold-dark: #836634;
    --title-red: #c00000;     /* لون عنوان المحضر */
    --border: #000;
    --ink: #1a1a1a;
    --paper: #fff;
    --page-w: 794px;          /* عرض A4 تقريبي عند 96dpi */
}

* { box-sizing: border-box; }

body {
    font-family: 'Cairo', 'Dubai', 'Segoe UI', Tahoma, sans-serif;
    margin: 0;
    background: #e9eaed;
    color: var(--ink);
    direction: rtl;
}

/* ===== ترويسة التطبيق (لا تُطبع) ===== */
.app-header {
    background: #0f3d2e;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.app-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.app-brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; line-height: 1.3; }
.app-brand span { display: block; font-weight: 400; font-size: 12px; opacity: .8; }
.app-header nav a { color: #cfe7d8; text-decoration: none; margin-inline-start: 14px; font-weight: 600; }
.app-header nav a:hover { color: #fff; }

.app-main { padding: 24px 16px 60px; }

/* ===== الأزرار ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: none; border-radius: 6px; cursor: pointer;
    padding: 9px 16px; font-family: inherit; font-size: 14px; font-weight: 600;
    text-decoration: none; transition: filter .15s;
}
.btn:hover { filter: brightness(.93); }
.btn-primary { background: #0f3d2e; color: #fff; }
.btn-gold { background: var(--gold); color: #fff; }
.btn-light { background: #fff; color: #333; border: 1px solid #ccc; }
.btn-danger { background: #b23b3b; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ===== قائمة المحاضر ===== */
.container-narrow { max-width: 1000px; margin: 0 auto; }
.page-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-toolbar h1 { font-size: 22px; margin: 0; }
.data-table { width: 100%; border-collapse: collapse; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.08); border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid #eee; }
.data-table th { background: #f4f1ea; color: #5b4a25; font-weight: 700; }
.data-table tr:hover td { background: #fafafa; }
.empty-state { background: #fff; border-radius: 8px; padding: 40px; text-align: center; color: #777; }
.saved-toast { background: #e6f4ea; color: #1e7a3c; border: 1px solid #b6e0c2; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }

/* ============================================================
   ورقة المستند (A4) — مشتركة بين التحرير والطباعة
   ============================================================ */
.doc-page {
    width: var(--page-w);
    min-height: 1123px;            /* ارتفاع A4 تقريبي */
    background: var(--paper);
    margin: 0 auto 24px;
    padding: 40px 48px 70px;
    box-shadow: 0 2px 12px rgba(0,0,0,.18);
    position: relative;
}
.doc-page.landscape {
    width: 1123px;
    min-height: var(--page-w);
}

/* ترويسة المستند: شعار الهيئة + شعار الدولة */
.doc-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; padding-bottom: 8px;
}
.doc-header .faic { height: 56px; }
.doc-header .emblem { height: 64px; }

/* عنوان الغلاف */
.cover {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
    min-height: 1000px; text-align: center;
}
.cover .cover-logos { display: flex; align-items: center; justify-content: center; gap: 60px; margin: 120px 0 200px; }
.cover .cover-logos .faic { height: 64px; }
.cover .cover-logos .emblem { height: 84px; }
.cover-title { color: var(--title-red); font-size: 38px; font-weight: 700; line-height: 1.6; }

/* ===== الجداول الرسمية ===== */
.gov-table { width: 100%; border-collapse: collapse; margin: 0 auto; }
.gov-table th, .gov-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: center; font-size: 14px; vertical-align: middle; }
.gov-table thead th { background: var(--gold); color: #fff; font-weight: 700; }

/* جدول بيانات الانعقاد */
.meeting-table { margin-top: 28px; }
.meeting-table td { height: 34px; }

/* عناوين الأقسام */
.section-title { text-align: center; font-weight: 700; font-size: 16px; margin: 26px 0 8px; }

/* جداول المشاركين: الأرقام التسلسلية بخلفية ذهبية على الحافة */
.participants-table td.serial { background: var(--gold); color: #fff; font-weight: 700; width: 34px; }
.col-rank { width: 90px; }
.col-number { width: 80px; }
.col-capacity { width: 30%; }

/* جدول القرارات (الأفقي) */
.decisions-table { font-size: 12px; }
.decisions-table td { height: 220px; vertical-align: top; }
.decisions-table td.serial { background: var(--gold); color: #fff; font-weight: 700; width: 28px; vertical-align: bottom; }
.decisions-table .director-options { text-align: right; font-size: 12px; }
.decisions-table .director-options label { display: block; margin: 4px 0; }
.decisions-table .director-options input { margin-left: 6px; }

/* جدول التواقيع */
.sign-table { width: 100%; border-collapse: collapse; margin-top: 40px; }
.sign-table td { border: 1px solid var(--border); height: 52px; padding: 6px 12px; vertical-align: middle; }
.sign-table td.sign-label { background: var(--gold); color: #fff; font-weight: 700; text-align: right; width: 55%; }
.sign-table td.sign-value { background: #fff; }

/* تذييل المستند */
.doc-footer {
    position: absolute; bottom: 26px; right: 48px; left: 48px;
    display: flex; align-items: center; justify-content: space-between;
    font-size: 10px; color: #555;
}
.doc-footer .code { letter-spacing: .5px; }
.doc-footer .fa-mark { color: #9b7b40; font-weight: 700; }
.doc-note { position: absolute; bottom: 26px; left: 48px; font-size: 11px; color: #444; }
.page-num { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); font-size: 11px; color: #555; }

/* ===== حقول التحرير داخل الخلايا ===== */
.cell-input {
    width: 100%; border: none; background: transparent; font-family: inherit;
    font-size: 14px; text-align: center; padding: 4px 2px; color: var(--ink);
}
.cell-input:focus { outline: 2px solid #cfe1d6; background: #f7fbf8; }
.cell-textarea { width: 100%; border: none; background: transparent; font-family: inherit; font-size: 12px; resize: vertical; min-height: 200px; padding: 4px; text-align: right; }
.cell-textarea:focus { outline: 2px solid #cfe1d6; background: #f7fbf8; }

.edit-toolbar {
    position: sticky; top: 0; z-index: 20;
    background: #fff; border: 1px solid #e2e2e2; border-radius: 8px;
    padding: 10px 14px; margin: 0 auto 18px; max-width: 1123px;
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.edit-toolbar .spacer { flex: 1; }
.row-actions { white-space: nowrap; }
.add-row-bar { text-align: center; margin: 8px 0 4px; }

.field-inline { display: inline-flex; align-items: center; gap: 6px; }
.field-inline input { border: 1px solid #ccc; border-radius: 4px; padding: 4px 6px; font-family: inherit; }

/* ===== الترويسة: المستخدم وتسجيل الخروج ===== */
.nav-user { display: inline-flex; flex-direction: column; line-height: 1.1; margin: 0 12px; color: #fff; font-weight: 700; font-size: 14px; }
.nav-user small { font-weight: 400; opacity: .8; font-size: 11px; }

/* ===== شارات الحالة ===== */
.status-badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-draft { background: #eee; color: #555; }
.badge-pending { background: #fff3cd; color: #8a6d1b; border: 1px solid #f1d98a; }
.badge-signed { background: #e6f4ea; color: #1e7a3c; border: 1px solid #b6e0c2; }

.muted { color: #888; }
hr { border: none; border-top: 1px solid #e2e2e2; margin: 20px 0; }

/* ===== تسجيل الدخول ===== */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,.08); padding: 34px; width: 100%; max-width: 420px; text-align: center; }
.login-logos { display: flex; justify-content: center; gap: 20px; margin-bottom: 14px; }
.login-logos img { height: 54px; }
.login-card h1 { font-size: 19px; margin: 6px 0; }
.login-sub { color: #888; margin: 0 0 18px; }
.login-label { display: block; text-align: right; font-weight: 700; font-size: 13px; margin: 12px 0 4px; }
.login-input { width: 100%; padding: 10px 12px; border: 1px solid #ccc; border-radius: 6px; font-family: inherit; font-size: 15px; }
.login-btn { width: 100%; margin-top: 18px; padding: 11px; font-size: 16px; }
.login-error { background: #fdecea; color: #b3261e; border: 1px solid #f5c2c0; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.login-hint { margin-top: 18px; font-size: 12px; color: #999; line-height: 1.8; }
.login-hint code { background: #f3f3f3; padding: 1px 6px; border-radius: 4px; color: #444; }

/* ===== لوحة التوقيع ===== */
.sig-pad-wrap { border: 2px dashed #bbb; border-radius: 8px; background: #fff; }
.sig-canvas { display: block; width: 100%; height: 200px; touch-action: none; cursor: crosshair; }
.sig-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.sig-current { margin: 14px 0; }
.sig-preview { display: inline-block; border: 1px solid #ddd; border-radius: 8px; background: #fff; padding: 8px; margin: 10px 0; }
.sig-preview img { max-height: 130px; max-width: 320px; display: block; }

/* ===== شاشة الاعتماد ===== */
.review-meta { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; margin: 8px 0; font-size: 14px; }
.review-director-name { margin: 22px 0 8px; display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.review-director-name label { font-weight: 700; }
.director-readonly { text-align: center; font-size: 12px; color: #555; }
.director-readonly .dir-note { font-style: italic; }

/* ===== اعتماد المدير العام في الطباعة ===== */
.director-approval { margin-top: 70px; text-align: center; }
.director-approval-title { font-weight: 700; color: var(--gold-dark); margin-bottom: 10px; }
.director-sign-box { display: inline-block; min-width: 280px; min-height: 90px; border-bottom: 2px solid #000; padding: 6px 20px; }
.director-sign-box.empty { color: #999; border-bottom: 1px dashed #999; padding: 30px 20px; font-style: italic; }
.director-sign-img { max-height: 110px; max-width: 320px; }
.director-sign-name { font-weight: 700; margin-top: 8px; }
.director-sign-date { font-size: 12px; color: #666; margin-top: 4px; }

/* ===== النافذة المنبثقة ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; box-shadow: 0 8px 40px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #eee; }
.modal-head h2 { font-size: 18px; margin: 0; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: #888; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-start; padding: 14px 20px; border-top: 1px solid #eee; }
.sign-choice { display: flex; gap: 14px; margin: 14px 0; flex-wrap: wrap; }
.choice-btn { flex: 1; min-width: 180px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px; border: 2px solid #ddd; border-radius: 10px; background: #fafafa; cursor: pointer; font-size: 16px; font-weight: 700; font-family: inherit; }
.choice-btn small { font-weight: 400; color: #888; font-size: 12px; }
.choice-btn .choice-ico { font-size: 28px; }
.choice-btn.selected { border-color: var(--gold); background: #fdf8ee; }
.sign-area { margin-top: 8px; }

/* ===== زر اختيار قرار المدير العام ===== */
.director-pick-cell { padding: 6px !important; }
.review-hint { background: #eef5f1; color: #15604a; border: 1px solid #cde6db; border-radius: 8px; padding: 10px 14px; margin: 4px 0 0; font-size: 14px; text-align: center; }

.dec-btn {
    width: 100%; min-height: 56px; border-radius: 10px; cursor: pointer;
    font-family: inherit; font-size: 15px; font-weight: 700;
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 10px 14px; border: 2px solid; transition: filter .15s, transform .05s;
    -webkit-tap-highlight-color: transparent;
}
.dec-btn:active { transform: scale(.985); }
.dec-btn .dec-btn-caret { opacity: .6; font-size: 13px; }
/* لم يُحدد */
.dec-state-0 { background: #f6f7f8; border-color: #ccd2d8; color: #5b6670; }
/* اعتماد */
.dec-state-1 { background: #e6f4ea; border-color: #7fc99a; color: #1e7a3c; }
/* استئناف */
.dec-state-2 { background: #fff4e2; border-color: #f0c277; color: #9a6713; }

/* ===== البوب-أب السفلي (Bottom Sheet) ===== */
.sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: flex-end; justify-content: center; z-index: 120;
    opacity: 0; transition: opacity .2s ease;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
    background: #fff; width: 100%; max-width: 560px;
    border-radius: 18px 18px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 40px rgba(0,0,0,.25);
    transform: translateY(100%); transition: transform .25s cubic-bezier(.22,1,.36,1);
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 46px; height: 5px; border-radius: 999px; background: #d7dadf; margin: 6px auto 12px; }
.sheet-title { font-size: 18px; font-weight: 700; text-align: center; }
.sheet-sub { font-size: 13px; color: #888; text-align: center; margin: 2px 0 14px; min-height: 16px; }
.sheet-opt {
    width: 100%; min-height: 62px; border-radius: 12px; border: 2px solid #e3e6ea;
    background: #fafbfc; font-family: inherit; font-size: 17px; font-weight: 700; color: #2a2f35;
    display: flex; align-items: center; gap: 12px; padding: 12px 18px; margin-bottom: 12px;
    cursor: pointer; transition: background .12s, border-color .12s, transform .05s;
    -webkit-tap-highlight-color: transparent;
}
.sheet-opt:active { transform: scale(.985); }
.sheet-opt .opt-ico { width: 34px; height: 34px; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; color: #fff; }
.opt-approve .opt-ico { background: #2e9e57; }
.opt-appeal .opt-ico { background: #d99a2b; }
.opt-none .opt-ico { background: #9aa3ac; }
.opt-approve.current { border-color: #2e9e57; background: #e9f7ef; }
.opt-appeal.current { border-color: #d99a2b; background: #fdf3e3; }
.opt-none.current { border-color: #9aa3ac; background: #f1f3f5; }
.sheet-cancel {
    width: 100%; min-height: 52px; border-radius: 12px; border: none; background: #eef0f2;
    font-family: inherit; font-size: 16px; font-weight: 700; color: #555; cursor: pointer; margin-top: 2px;
}

/* تكبير حقول اللمس على الشاشات المتوسطة (آيباد) */
@media (max-width: 1200px) {
    .btn { padding: 10px 16px; font-size: 16px; }
    .btn-sm { padding: 7px 12px; font-size: 14px; }
}

/* ===== الطباعة ===== */
@media print {
    @page { size: A4; margin: 12mm; }
    body { background: #fff; }
    .no-print, .edit-toolbar, .app-header, .add-row-bar, .row-actions { display: none !important; }
    .doc-page {
        width: auto; min-height: 0; margin: 0; padding: 0 0 40px;
        box-shadow: none; page-break-after: always;
    }
    .doc-page:last-child { page-break-after: auto; }
    .gov-table thead th,
    .participants-table td.serial, .decisions-table td.serial, .sign-table td.sign-label,
    .cover-title {
        -webkit-print-color-adjust: exact; print-color-adjust: exact;
    }
}
