/* ===========================
   PartnersShareHistory — App CSS
   Custom tweaks + print styles
   =========================== */

/* ---- Base ---- */
* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

/* الخط الأساسي للنظام: عربي واضح ورسمي (IBM Plex Sans Arabic) — مفروض على كل العناصر والحقول */
html, body, button, input, select, textarea, .font-body, .font-heading {
    font-family: "IBM Plex Sans Arabic", "Segoe UI", "Tahoma", sans-serif;
}

/* ---- Smooth transitions ---- */
[x-cloak] {
    display: none !important;
}

/* ---- App navigation: compact on phones ---- */
.app-nav-toggle {
    display: none;
}

@media (max-width: 640px) {
    .app-nav-inner {
        align-items: stretch !important;
        flex-direction: column;
        gap: 0 !important;
    }

    .app-nav-brand {
        justify-content: space-between;
        width: 100%;
        min-width: 0;
    }

    .app-nav-brand a {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-nav-toggle {
        align-items: center;
        background: rgba(255,255,255,.08);
        border: 1px solid rgba(255,255,255,.14);
        border-radius: 10px;
        color: #fff;
        display: inline-flex;
        height: 40px;
        justify-content: center;
        transition: background .15s, border-color .15s;
        width: 40px;
    }

    .app-nav-toggle:hover {
        background: rgba(255,255,255,.16);
        border-color: rgba(255,255,255,.24);
    }

    .app-nav-menu {
        background: rgba(255,255,255,.06);
        border: 1px solid rgba(255,255,255,.12);
        border-radius: 14px;
        display: none !important;
        gap: 8px !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-top: 12px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
        padding: 10px;
    }

    .app-nav-menu.is-open {
        display: grid !important;
    }

    .app-nav-menu > a,
    .app-nav-menu > span {
        align-items: center;
        display: flex;
        justify-content: center;
        min-height: 38px;
        min-width: 0;
        text-align: center;
        white-space: nowrap;
    }

    .app-nav-user {
        grid-column: 1 / -1;
        justify-content: center;
        max-width: none;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ---- Print styles ---- */
@media print {
    @page {
        margin: 1.5cm;
        size: A4 portrait;
    }

    body {
        font-family: 'IBM Plex Sans Arabic', sans-serif;
        font-size: 10pt;
        color: #213039;
        background: white;
        direction: rtl;
    }

    /* Hide non-printable elements */
    nav,
    footer,
    .print\:hidden,
    button {
        display: none !important;
    }

    /* Remove shadows and backgrounds for print */
    .shadow,
    .shadow-lg,
    .shadow-xl {
        box-shadow: none !important;
    }

    .bg-navy,
    .bg-navy-deep {
        background-color: #f8f8f8 !important;
        color: #213039 !important;
    }

    /* Page breaks */
    .print-break-avoid {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Ensure tables don't break mid-row */
    tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Tables in print */
    table {
        border-collapse: collapse;
        width: 100%;
    }

    th, td {
        border: 1px solid #ccc !important;
        padding: 4pt 6pt !important;
    }

    /* Keep colours for key numbers */
    .text-gold {
        color: #9A8E5E !important;
    }

    .text-teal {
        color: #0A7A78 !important;
    }

    .text-green {
        color: #0A7A4F !important;
    }

    /* Print-specific title spacing */
    h1, h2, h3 {
        page-break-after: avoid;
        break-after: avoid;
    }

    /* Rounded corners don't matter in print */
    * {
        border-radius: 0 !important;
    }
}

/* ---- Scrollbar styling (webkit) ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #F4F7F9;
}

::-webkit-scrollbar-thumb {
    background: #0DA9A6;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #15445A;
}

/* ---- Number cells: keep LTR for Western digits ---- */
.num,
td.num {
    direction: ltr;
    text-align: end;
    unicode-bidi: plaintext;
}

/* ---- Story page: mobile containment ---- */
.story-shell {
    overflow-x: clip;
}

.story-card,
.story-scene {
    min-width: 0;
}

.story-scene {
    overflow-wrap: anywhere;
}

.story-scene .font-heading,
.story-scene strong {
    line-height: 1.25;
}

.story-nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.story-prev,
.story-next,
.story-end {
    width: 100%;
    min-width: 0;
}

.story-dots {
    display: none !important;
}

@media (min-width: 641px) {
    .story-nav {
        display: flex;
        justify-content: space-between;
    }

    .story-prev,
    .story-next,
    .story-end {
        flex: 0 0 auto;
        width: auto;
    }

    .story-dots {
        display: flex !important;
        flex: 1 1 auto;
        justify-content: center;
    }
}

@media (max-width: 640px) {
    .story-scene .text-6xl { font-size: 3rem !important; }
    .story-scene .text-5xl { font-size: 2.5rem !important; }
    .story-scene .text-4xl { font-size: 2rem !important; }
    .story-scene .text-3xl { font-size: 1.75rem !important; }
    .story-scene .text-2xl { font-size: 1.35rem !important; }

    .story-scene p {
        font-size: 1rem !important;
        line-height: 1.9 !important;
    }
}

/* ===========================
   Hijri date picker (تقويم هجري لاختيار تاريخ الميلاد)
   =========================== */
.hijri-picker { position: relative; display: flex; gap: 8px; align-items: stretch; }
.hp-toggle {
    flex: 0 0 auto; width: 44px; border: 1px solid #d1d5db; border-radius: 10px;
    background: #15445A; color: #fff; font-size: 18px; cursor: pointer; line-height: 1;
    transition: background .15s;
}
.hp-toggle:hover { background: #0E3A48; }
.hp-display {
    flex: 1 1 auto; width: 100%; padding: 10px 14px; border: 1px solid #d1d5db;
    border-radius: 10px; background: #fff; cursor: pointer; text-align: start; color: #213039;
}
.hp-display:focus { outline: none; border-color: #0DA9A6; box-shadow: 0 0 0 2px rgba(13,169,166,.35); }

.hp-pop {
    display: none; position: fixed; z-index: 60; width: 300px; max-width: calc(100vw - 16px);
    background: #fff; border: 1px solid #e5e7eb; border-radius: 14px;
    box-shadow: 0 20px 50px -18px rgba(10,43,58,.45); padding: 12px;
}
.hp-pop.show { display: block; }
.hp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.hp-nav {
    flex: 0 0 auto; width: 32px; height: 32px; border: 1px solid #e5e7eb; border-radius: 8px;
    background: #F4F7F9; color: #15445A; font-size: 18px; cursor: pointer;
}
.hp-nav:hover { background: #EAF3F4; }
.hp-select {
    flex: 1 1 auto; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 8px;
    background: #fff; color: #213039; font-family: inherit; font-size: 14px;
}
.hp-week, .hp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.hp-week { margin-bottom: 4px; }
.hp-week span { text-align: center; font-size: 11px; color: #5B7480; padding: 4px 0; }
.hp-day {
    aspect-ratio: 1 / 1; border: 0; border-radius: 8px; background: #F4F7F9; color: #213039;
    cursor: pointer; font-family: inherit; font-size: 13px; transition: background .12s;
}
.hp-day:hover { background: #0DA9A6; color: #fff; }
.hp-day.out { color: #c5cdd1; background: transparent; }
.hp-day.today { outline: 2px solid #0DA9A6; }
.hp-day.sel { background: #C1B489; color: #fff; font-weight: 700; }
.hp-foot { display: flex; gap: 8px; margin-top: 10px; }
.hp-btn {
    flex: 1 1 0; padding: 8px; border: 1px solid #e5e7eb; border-radius: 8px;
    background: #fff; color: #15445A; cursor: pointer; font-family: inherit; font-size: 13px;
}
.hp-btn:hover { background: #F4F7F9; }
.hp-clear { color: #b91c1c; }

/* ===========================
   الوضع الليلي (كحلي داكن — بهوية النظام)
   =========================== */
html.dark body { background-color: #0F2A36; color: #DCE6EA; }

html.dark .bg-cloud  { background-color: #0F2A36 !important; }
html.dark .bg-white  { background-color: #163A4A !important; }
html.dark .bg-gray-50  { background-color: #12303C !important; }
html.dark .bg-gray-100 { background-color: #1D4456 !important; }

/* النصوص */
html.dark .text-navy { color: #E7EFF2 !important; }
html.dark .text-ink  { color: #DCE6EA !important; }
html.dark .text-gray-700,
html.dark .text-gray-600,
html.dark .text-gray-500,
html.dark .text-gray-400 { color: #9FB3BD !important; }
html.dark .text-gray-300 { color: #7E94A0 !important; }

/* الحدود */
html.dark .border-gray-50,
html.dark .border-gray-100,
html.dark .border-gray-200,
html.dark .border-gray-300 { border-color: #2C4F60 !important; }

/* اللمسات تُضاء قليلًا على الخلفية الداكنة */
html.dark .text-teal  { color: #1FC3BF !important; }
html.dark .text-green { color: #2FC489 !important; }
html.dark .text-gold  { color: #D6C99C !important; }

/* الحقول */
html.dark input,
html.dark select,
html.dark textarea {
    background-color: #163A4A !important;
    color: #DCE6EA !important;
    border-color: #2C4F60 !important;
}

/* صناديق ملوّنة فاتحة → داكنة شفافة */
html.dark .bg-red-50, html.dark .bg-red-100 { background-color: rgba(200,70,70,.18) !important; }
html.dark .text-red-700, html.dark .text-red-800 { color: #F0A29A !important; }
html.dark .bg-green-50, html.dark .bg-green-100 { background-color: rgba(7,168,105,.20) !important; }
html.dark .text-green-700, html.dark .text-green-800 { color: #4FD79C !important; }
html.dark .bg-purple-50, html.dark .bg-purple-100 { background-color: rgba(114,88,164,.22) !important; }
html.dark .text-purple-600, html.dark .text-purple-700 { color: #BCA6E6 !important; }
html.dark .bg-amber-50 { background-color: rgba(193,180,137,.16) !important; }
html.dark .text-amber-700 { color: #D6C99C !important; }
html.dark .bg-blue-50 { background-color: rgba(61,126,185,.18) !important; }
html.dark .text-blue-600 { color: #8FB6E0 !important; }

/* ظلال أنعم */
html.dark .shadow, html.dark .shadow-lg, html.dark .shadow-xl {
    box-shadow: 0 12px 32px -14px rgba(0,0,0,.55) !important;
}

/* التقويم في الوضع الليلي */
html.dark .hp-pop { background: #163A4A; border-color: #2C4F60; }
html.dark .hp-display { background: #163A4A; color: #DCE6EA; border-color: #2C4F60; }
html.dark .hp-select { background: #163A4A; color: #DCE6EA; border-color: #2C4F60; }
html.dark .hp-day { background: #12303C; color: #DCE6EA; }
html.dark .hp-day.out { background: transparent; color: #5B7280; }
html.dark .hp-btn { background: #163A4A; color: #E7EFF2; border-color: #2C4F60; }
