/* =========================================================================
   Personal Life Hub — نظام التصميم "Focus"
   هوية حديثة مبنية لتطبيق جوال (iOS / Android) قبل أن تكون موقعاً.
   لا يعتمد على أي مكتبة خارجية. RTL أصلي.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. الرموز (Design Tokens)
   ------------------------------------------------------------------------- */
:root {
    color-scheme: light;

    /* الأسطح والنصوص */
    --bg: #F4F5F8;
    --surface: #FFFFFF;
    --surface-2: #EEF0F5;
    --surface-3: #E4E7EF;
    --ink: #111827;
    --ink-2: #4B5563;
    --ink-3: #8A93A3;
    --line: #E3E6ED;
    --line-strong: #CFD4DF;

    /* اللون الهيكلي */
    --brand: #4F46E5;
    --brand-2: #6366F1;
    --brand-soft: #EEF0FE;
    --brand-ink: #FFFFFF;

    /* ألوان الحالة */
    --ok: #0E9F6E;
    --ok-soft: #E4F7F0;
    --warn: #D97706;
    --warn-soft: #FDF3E3;
    --danger: #DC2626;
    --danger-soft: #FDEBEB;
    --info: #2563EB;
    --info-soft: #E8EFFE;

    /* ألوان الأقسام — تُستخدم للأيقونات والشارات، لا كخلفيات كاملة */
    --c-tasks: #2563EB;
    --c-calendar: #7C3AED;
    --c-health: #E11D48;
    --c-finance: #059669;
    --c-fitness: #EA580C;
    --c-academic: #4F46E5;
    --c-work: #0891B2;
    --c-notes: #CA8A04;
    --c-worship: #0E9F6E;

    /* الانحناءات */
    --r-sm: 10px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 24px;
    --r-full: 999px;

    /* الظلال — خفيفة ومتدرّجة، لا ظلال ثقيلة */
    --sh-1: 0 1px 2px rgba(16, 24, 40, .05);
    --sh-2: 0 2px 8px rgba(16, 24, 40, .07);
    --sh-3: 0 8px 28px rgba(16, 24, 40, .12);
    --sh-up: 0 -4px 20px rgba(16, 24, 40, .07);

    /* المقاسات الثابتة للهيكل */
    --appbar-h: 56px;
    --tabbar-h: 60px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --ease: cubic-bezier(.32, .72, 0, 1);
}

html[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0B0D13;
    --surface: #151823;
    --surface-2: #1C2030;
    --surface-3: #262B3C;
    --ink: #F2F4F8;
    --ink-2: #B4BBC9;
    --ink-3: #7D8597;
    --line: #262B3A;
    --line-strong: #353C50;

    --brand: #7C7BF0;
    --brand-2: #9593F5;
    --brand-soft: #1E1F3A;
    --brand-ink: #FFFFFF;

    --ok: #34D399;
    --ok-soft: #10281F;
    --warn: #FBBF24;
    --warn-soft: #2A2110;
    --danger: #F87171;
    --danger-soft: #2E1618;
    --info: #60A5FA;
    --info-soft: #131E33;

    --c-tasks: #60A5FA;
    --c-calendar: #A78BFA;
    --c-health: #FB7185;
    --c-finance: #34D399;
    --c-fitness: #FB923C;
    --c-academic: #818CF8;
    --c-work: #22D3EE;
    --c-notes: #FACC15;

    --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-2: 0 2px 10px rgba(0, 0, 0, .45);
    --sh-3: 0 10px 32px rgba(0, 0, 0, .6);
    --sh-up: 0 -4px 22px rgba(0, 0, 0, .5);
}

/* -------------------------------------------------------------------------
   2. الأساسيات
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--ink);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    /* يمنع تمييز العناصر باللون الأزرق عند اللمس على أندرويد */
    -webkit-tap-highlight-color: transparent;
    /* يمنع تكبير الصفحة بالضغط المزدوج داخل التطبيق المثبّت */
    touch-action: manipulation;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 700; line-height: 1.35; letter-spacing: -.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img, svg, video { display: block; max-width: 100%; }
ul, ol { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea {
    font: inherit;
    color: inherit;
    margin: 0;
}
button { background: none; border: 0; cursor: pointer; }

/* الأرقام دائماً LTR ومتساوية العرض — مهم جداً في واجهة عربية */
.num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-full); }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 6px;
}

[hidden], [x-cloak] { display: none !important; }

/* -------------------------------------------------------------------------
   3. هيكل التطبيق — شريط علوي + شريط تبويب سفلي
   ------------------------------------------------------------------------- */

/* الغلاف العام: يترك مساحة للشريطين ولحواف الآيفون */
.app-main {
    padding: 14px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 84px);
    max-width: 720px;
    margin: 0 auto;
}
.app-main--plain { padding-bottom: calc(var(--safe-bottom) + 32px); }

/* --- الشريط العلوي --- */
.appbar {
    position: sticky;
    top: 0;
    z-index: 40;
    padding-top: var(--safe-top);
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(180%) blur(18px);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    border-bottom: 1px solid var(--line);
}
.appbar__inner {
    height: var(--appbar-h);
    max-width: 720px;
    margin: 0 auto;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.appbar__title {
    font-size: 17px;
    font-weight: 700;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* عنوان كبير يتقلّص مع التمرير — نمط iOS */
.page-head { padding: 6px 2px 16px; }
.page-head__title { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.page-head__sub { color: var(--ink-3); font-size: 13.5px; margin-top: 2px; }

/* زر أيقونة دائري داخل الأشرطة */
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--r-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-2);
    flex-shrink: 0;
    transition: background .15s;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn--brand { background: var(--brand); color: var(--brand-ink); }

/* شعار العلامة في رأس الصفحة.

   بلا خلفية ولا زوايا مستديرة: الملف PNG شفاف والشكل دائري أصلاً،
   فأي خلفية تضيفها تظهر كمربّع خلف الدائرة. */
.brand-mark {
    width: 28px;
    height: 28px;
    display: block;
    object-fit: contain;
}

/* شارة عدّاد فوق أيقونة */
.badge-dot {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: var(--r-full);
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--surface);
}

/* --- شريط التبويب السفلي --- */
.tabbar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 45;
    padding-bottom: var(--safe-bottom);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--line);
    box-shadow: var(--sh-up);
}
.tabbar__inner {
    height: var(--tabbar-h);
    max-width: 720px;
    margin: 0 auto;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
}
.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--ink-3);
    font-size: 10.5px;
    font-weight: 600;
    position: relative;
    transition: color .15s;
}
.tab svg { width: 22px; height: 22px; stroke-width: 2; }
/* سبعة تبويبات: الاسم يبقى سطراً واحداً ولا يُقصّ ولا يُكسر.
   الحجم يصغر مع ضيق الشاشة بدل أن يلتفّ «الرئيسية» سطرين
   فيختلف ارتفاع التبويبات بينها. */
.tab span {
    white-space: nowrap;
    max-width: 100%;
    font-size: clamp(8.5px, 2.6vw, 10.5px);
    letter-spacing: -.01em;
}
@media (max-width: 400px) {
    .tab svg { width: 20px; height: 20px; }
    .tab { gap: 2px; }
}
.tab.is-active { color: var(--brand); }
.tab.is-active::before {
    content: "";
    position: absolute;
    top: 0;
    width: 26px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--brand);
}

/* --- زر الإضافة العائم --- */
.fab {
    position: fixed;
    inset-inline-end: 18px;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    z-index: 44;
    width: 56px;
    height: 56px;
    border-radius: var(--r-full);
    background: var(--brand);
    color: var(--brand-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--brand) 45%, transparent);
    transition: transform .18s var(--ease);
}
.fab:active { transform: scale(.92); }
.fab svg { width: 26px; height: 26px; }

/* -------------------------------------------------------------------------
   4. البطاقات والقوائم
   ------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
}
.card--flat { box-shadow: none; }
.card--pad { padding: 16px; }

.card__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.card__title { font-size: 15px; font-weight: 700; flex: 1; min-width: 0; }
.card__body { padding: 16px; }

/* قائمة صفوف بفواصل داخلية — النمط الأساسي لعرض البيانات */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    min-height: 58px;
    transition: background .15s;
}
a.row:active, button.row:active { background: var(--surface-2); }
.row__main { flex: 1; min-width: 0; }
.row__title { font-size: 14.5px; font-weight: 600; line-height: 1.4; }
.row__sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row__end { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
/* سهم التنقّل في صف قابل للفتح — يتبع اتجاه الصفحة (RTL) تلقائياً */
.row__chev { width: 18px; height: 18px; flex: none; color: var(--ink-3); }

/* مربّع أيقونة ملوّن — هوية القسم */
.tile {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: color-mix(in srgb, var(--tile-c, var(--brand)) 13%, var(--surface));
    color: var(--tile-c, var(--brand));
}
.tile svg { width: 19px; height: 19px; }
.tile--sm { width: 32px; height: 32px; border-radius: 9px; }
.tile--sm svg { width: 16px; height: 16px; }
.tile--lg { width: 48px; height: 48px; border-radius: 14px; }
.tile--lg svg { width: 23px; height: 23px; }
.tile--solid { background: var(--tile-c, var(--brand)); color: #fff; }

.t-tasks { --tile-c: var(--c-tasks); }
.t-calendar { --tile-c: var(--c-calendar); }
.t-health { --tile-c: var(--c-health); }
.t-finance { --tile-c: var(--c-finance); }
.t-fitness { --tile-c: var(--c-fitness); }
.t-academic { --tile-c: var(--c-academic); }
.t-work { --tile-c: var(--c-work); }
.t-notes { --tile-c: var(--c-notes); }
.t-ok { --tile-c: var(--ok); }
.t-warn { --tile-c: var(--warn); }
.t-danger { --tile-c: var(--danger); }

/* -------------------------------------------------------------------------
   5. الأزرار
   ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 16px;
    height: 42px;
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 700;
    border: 1px solid transparent;
    background: var(--surface-2);
    color: var(--ink);
    transition: transform .12s var(--ease), background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 17px; height: 17px; flex-shrink: 0; }

.btn--brand { background: var(--brand); color: var(--brand-ink); box-shadow: var(--sh-1); }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-2); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--ok { background: var(--ok-soft); color: var(--ok); }
.btn--block { width: 100%; }
.btn--lg { height: 50px; font-size: 15.5px; border-radius: var(--r-lg); }
.btn--sm { height: 34px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn:disabled { opacity: .5; pointer-events: none; }

/* -------------------------------------------------------------------------
   6. الشارات والرقائق
   ------------------------------------------------------------------------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    font-size: 11.5px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--ink-2);
    white-space: nowrap;
}
.chip svg { width: 13px; height: 13px; }
.chip--ok { background: var(--ok-soft); color: var(--ok); }
.chip--warn { background: var(--warn-soft); color: var(--warn); }
.chip--danger { background: var(--danger-soft); color: var(--danger); }
.chip--info { background: var(--info-soft); color: var(--info); }
.chip--brand { background: var(--brand-soft); color: var(--brand); }

/* نقطة ملوّنة صغيرة */
.dot { width: 7px; height: 7px; border-radius: var(--r-full); flex-shrink: 0; display: inline-block; }

/* -------------------------------------------------------------------------
   7. النماذج
   ------------------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.label {
    display: block;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--ink-2);
    margin-bottom: 6px;
}
.input, .select, .textarea {
    width: 100%;
    /* 16px إلزامي: أي أصغر يجعل iOS Safari يكبّر الصفحة تلقائياً عند التركيز */
    font-size: 16px;
    padding: 11px 13px;
    border-radius: var(--r-md);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A93A3' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
    background-size: 16px;
    padding-left: 36px;
}
input[type="date"], input[type="time"], input[type="datetime-local"] { min-height: 44px; }
.input-file {
    width: 100%;
    font-size: 13px;
    padding: 10px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-md);
    background: var(--surface-2);
    color: var(--ink-2);
}
.hint { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }

/* مفتاح تبديل */
.switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch__track {
    position: absolute;
    inset: 0;
    border-radius: var(--r-full);
    background: var(--surface-3);
    transition: background .2s var(--ease);
}
.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    inset-inline-start: 3px;
    width: 22px;
    height: 22px;
    border-radius: var(--r-full);
    background: #fff;
    box-shadow: var(--sh-1);
    transition: transform .2s var(--ease);
}
.switch input:checked ~ .switch__track { background: var(--ok); }
.switch input:checked ~ .switch__track::after { transform: translateX(-18px); }

/* مربّع اختيار دائري — نمط المهام */
.check {
    width: 26px;
    height: 26px;
    border-radius: var(--r-full);
    border: 2px solid var(--line-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: transparent;
    transition: all .18s var(--ease);
}
.check svg { width: 15px; height: 15px; stroke-width: 3; }
.check.is-done { background: var(--ok); border-color: var(--ok); color: #fff; }

/* شريط تبويب أفقي (segmented) */
.seg {
    display: flex;
    gap: 3px;
    padding: 3px;
    background: var(--surface-2);
    border-radius: var(--r-md);
    overflow-x: auto;
    scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg__item {
    flex: 1;
    min-width: max-content;
    padding: 8px 13px;
    border-radius: 11px;
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-3);
    text-align: center;
    transition: all .18s var(--ease);
}
.seg__item.is-active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--sh-1);
}

/* شريط رقائق قابل للتمرير أفقياً */
.scroller {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    /* يتجاوز حشو .app-main ليصل لحافة الشاشة — نمط جوال أصيل */
    margin-inline: -16px;
    padding-inline: 16px;
    scroll-snap-type: x proximity;
}
.scroller::-webkit-scrollbar { display: none; }
.scroller > * { scroll-snap-align: start; flex-shrink: 0; }

/* -------------------------------------------------------------------------
   8. النوافذ المنزلقة (Bottom Sheet) — بديل المودال على الجوال
   ------------------------------------------------------------------------- */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(8, 11, 18, .45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s var(--ease);
}
.sheet-backdrop.is-open { opacity: 1; pointer-events: auto; }

.sheet {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 61;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--sh-3);
    transform: translateY(101%);
    transition: transform .3s var(--ease);
    /* الشاشات الكبيرة: يتحوّل لنافذة وسطية بدل شريط ممتد */
    max-width: 560px;
    margin: 0 auto;
}
.sheet.is-open { transform: translateY(0); }

/*
    النموذج داخل النافذة يلفّ الجسم والتذييل معاً، فلا بد أن يكون هو نفسه
    عمود مرن — وإلا لم يرث .sheet__body ارتفاعاً محدوداً فلا يعمل تمريره،
    وتختفي الحقول السفلية خارج حدود النافذة (كان يظهر بوضوح في نموذج
    إضافة مقرر لكثرة حقوله).
*/
.sheet > form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.sheet__grip {
    width: 38px;
    height: 4px;
    border-radius: var(--r-full);
    background: var(--line-strong);
    margin: 10px auto 2px;
    flex-shrink: 0;
}
.sheet__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 12px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.sheet__title { font-size: 16.5px; font-weight: 700; flex: 1; }
.sheet__body {
    padding: 16px 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    /* ضروري مع flex: بدونه يرفض العنصر الانكماش دون ارتفاع محتواه فلا يمرّر */
    min-height: 0;
}
.sheet__foot {
    padding: 12px 18px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    display: flex;
    gap: 9px;
    flex-shrink: 0;
    background: var(--surface);
}
.sheet__foot .btn { flex: 1; }

/* يمنع تمرير الصفحة خلف النافذة المفتوحة */
body.sheet-locked { overflow: hidden; }

/* -------------------------------------------------------------------------
   9. التنبيهات العائمة (Toast)
   ------------------------------------------------------------------------- */
.toasts {
    position: fixed;
    top: calc(var(--safe-top) + 10px);
    inset-inline: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    max-width: 480px;
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--sh-3);
    font-size: 13.5px;
    font-weight: 600;
    animation: toast-in .3s var(--ease);
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast--ok { color: var(--ok); }
.toast--error { color: var(--danger); }
.toast--warn { color: var(--warn); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-14px); }
    to { opacity: 1; transform: translateY(0); }
}

/* شريط تنبيه داخل الصفحة (بريد غير مؤكَّد، جلسة جديدة، ...) */
.notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: var(--r-lg);
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 13px;
    line-height: 1.5;
}
.notice__icon {
    width: 20px;
    height: 20px;
    flex: none;
    color: var(--ink-3);
}
.notice__body { flex: 1; min-width: 0; }
.notice__body strong { display: block; color: var(--ink); font-weight: 700; }
.notice__body span { color: var(--ink-2); }
.notice form { flex: none; }

.notice--warn {
    background: var(--warn-soft);
    border-color: color-mix(in srgb, var(--warn) 28%, transparent);
}
.notice--warn .notice__icon { color: var(--warn); }

.notice--danger {
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 28%, transparent);
}
.notice--danger .notice__icon { color: var(--danger); }

/* رسم أعمدة بـ CSS خالص — لا مكتبة جافاسكربت ولا طلب شبكة إضافي.
   الارتفاع يأتي من متغيّر --h يضبطه القالب. */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 120px;
    padding: 0 2px;
}
.chart__col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    height: 100%;
    justify-content: flex-end;
}
.chart__bar {
    width: 100%;
    max-width: 34px;
    height: var(--h, 0%);
    min-height: 3px;
    background: var(--brand);
    border-radius: 5px 5px 2px 2px;
    transition: height .25s ease;
}
.chart__bar--ok { background: var(--ok); }
.chart__bar--danger { background: var(--danger); }
.chart__bar--muted { background: var(--surface-3); }
.chart__label {
    font-size: 10.5px;
    color: var(--ink-3);
    white-space: nowrap;
}
.chart__value {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--ink-2);
}

/* مفتاح الرسم */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); }
.legend__item { display: flex; align-items: center; gap: 5px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; }

/* مؤشر الاتجاه */
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 700; }
.delta svg { width: 14px; height: 14px; }
.delta--good { color: var(--ok); }
.delta--bad { color: var(--danger); }
.delta--flat { color: var(--ink-3); }

/* -------------------------------------------------------------------------
   10. حالات فارغة / تحميل
   ------------------------------------------------------------------------- */
.empty {
    text-align: center;
    padding: 40px 22px;
    color: var(--ink-3);
}
.empty__icon {
    width: 58px;
    height: 58px;
    border-radius: var(--r-lg);
    background: var(--surface-2);
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}
.empty__icon svg { width: 26px; height: 26px; }
.empty__title { font-size: 15px; font-weight: 700; color: var(--ink-2); }
.empty__text { font-size: 13px; margin-top: 4px; }

/* شريط تقدّم */
.bar {
    height: 8px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    overflow: hidden;
}
.bar__fill {
    height: 100%;
    border-radius: var(--r-full);
    background: var(--bar-c, var(--brand));
    transition: width .5s var(--ease);
}

/* حلقة تقدّم دائرية (تُغذّى بـ --p من 0 إلى 100) */
.ring {
    --p: 0;
    --ring-c: var(--brand);
    width: 56px;
    height: 56px;
    border-radius: var(--r-full);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: conic-gradient(var(--ring-c) calc(var(--p) * 1%), var(--surface-3) 0);
}
.ring__inner {
    width: 44px;
    height: 44px;
    border-radius: var(--r-full);
    background: var(--surface);
    display: grid;
    place-items: center;
    font-size: 12.5px;
    font-weight: 800;
}

/* -------------------------------------------------------------------------
   11. بطاقات الإحصاء
   ------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stats--3 { grid-template-columns: repeat(3, 1fr); }

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 13px;
    box-shadow: var(--sh-1);
}
.stat__label { font-size: 11.5px; font-weight: 700; color: var(--ink-3); display: flex; align-items: center; gap: 5px; }
.stat__value { font-size: 23px; font-weight: 800; margin-top: 5px; letter-spacing: -.02em; }
.stat__hint { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }

/* -------------------------------------------------------------------------
   12. أدوات مساعدة (طبقة مختصرة فقط لما تحتاجه القوالب فعلياً)
   ------------------------------------------------------------------------- */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.block { display: block; }
.hidden { display: none; }
.col { flex-direction: column; }
.wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1; min-width: 0; }
.shrink-0 { flex-shrink: 0; }

.g-4 { gap: 4px; }
.g-6 { gap: 6px; }
.g-8 { gap: 8px; }
.g-10 { gap: 10px; }
.g-12 { gap: 12px; }
.g-16 { gap: 16px; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.p-0 { padding: 0; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }

.w-full { width: 100%; }
.text-center { text-align: center; }
.text-end { text-align: left; }

.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12.5px; }
.fs-13 { font-size: 13.5px; }
.fs-15 { font-size: 15px; }
.fs-17 { font-size: 17px; }
.fs-20 { font-size: 20px; }
.fw-6 { font-weight: 600; }
.fw-7 { font-weight: 700; }
.fw-8 { font-weight: 800; }

.c-muted { color: var(--ink-3); }
.c-soft { color: var(--ink-2); }
.c-brand { color: var(--brand); }
.c-ok { color: var(--ok); }
.c-warn { color: var(--warn); }
.c-danger { color: var(--danger); }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.strike { text-decoration: line-through; opacity: .55; }

/* خانة الاختيار في صفحة تخصيص الرئيسية — الحجم الافتراضي للمتصفّح
   صغير على الشاشات اللمسية (أقل من هدف اللمس الموصى به 24px). */
.layout-check {
    width: 22px;
    height: 22px;
    flex: none;
    accent-color: var(--brand);
    cursor: pointer;
}

.section-title {
    font-size: 12.5px;
    font-weight: 800;
    color: var(--ink-3);
    letter-spacing: .02em;
    margin: 22px 2px 9px;
    display: flex;
    align-items: center;
    gap: 7px;
}
.section-title:first-child { margin-top: 4px; }

.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

/* -------------------------------------------------------------------------
   13. الشاشات الكبيرة — يتحوّل لعمودين مع إبقاء منطق الجوال
   ------------------------------------------------------------------------- */
@media (min-width: 860px) {
    .app-main { max-width: 820px; padding-bottom: calc(var(--safe-bottom) + 48px); }
    .tabbar { max-width: 820px; inset-inline: auto; left: 50%; transform: translateX(-50%); border-radius: var(--r-xl) var(--r-xl) 0 0; border: 1px solid var(--line); border-bottom: 0; }
    .fab { inset-inline-end: calc(50% - 410px + 18px); }
    .stats { grid-template-columns: repeat(4, 1fr); }
}

/* -------------------------------------------------------------------------
   14. احترام تفضيل تقليل الحركة
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* -------------------------------------------------------------------------
   15. الطباعة
   ------------------------------------------------------------------------- */
@media print {
    .appbar, .tabbar, .fab, .sheet, .sheet-backdrop, .toasts { display: none !important; }
    .app-main { padding: 0; max-width: 100%; }
    .card, .list { box-shadow: none; border-color: #ddd; }
}

/* -------------------------------------------------------------------------
   20. خطط الأهداف
   ------------------------------------------------------------------------- */
.plan {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
    overflow: hidden;
}

.plan--done { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }

.plan__head {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 13px;
    color: inherit;
}

.plan__ring { width: 50px; height: 50px; }
.plan__ring .ring__inner { width: 39px; height: 39px; font-size: 11.5px; }

.plan__meta { flex: 1; min-width: 0; }

.plan__title {
    display: block;
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.4;
}

.plan__sub {
    display: block;
    font-size: 12px;
    color: var(--ink-3);
    margin-top: 2px;
}

.plan__streak {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 5px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--warn);
    background: var(--warn-soft);
    padding: 2px 8px;
    border-radius: var(--r-full);
}

.plan__msg {
    margin: 0;
    padding: 0 13px 11px;
    font-size: 12.8px;
    line-height: 1.75;
    color: var(--ink-2);
}

.plan__actions {
    display: flex;
    gap: 8px;
    padding: 0 13px 13px;
}

.plan__actions .btn { flex: 1; }
.plan__actions .btn[aria-label] { flex: 0 0 auto; }

/* شبكة الأيام */
.pgrid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.pgrid__c {
    aspect-ratio: 1;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid transparent;
}

.pgrid__c.is-done { background: var(--brand); }
.pgrid__c.is-before { background: transparent; border-color: var(--line); }
/* اليوم بإطار لا بلون: لونه يقول «أُنجز» وهو ما لم يُعرف بعد */
.pgrid__c.is-today { border-color: var(--ink-3); }

.pgrid__legend {
    display: flex;
    gap: 14px;
    justify-content: center;
    margin-top: 12px;
    font-size: 11px;
    color: var(--ink-3);
}

.pgrid__legend span { display: flex; align-items: center; gap: 5px; }

.pgrid__legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: var(--surface-2);
}

.pgrid__legend i.is-done { background: var(--brand); }
.pgrid__legend i.is-before { background: transparent; border: 1px solid var(--line); }

/* الشعارات */
.badges {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 10px;
}

.badge2 {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 13px 10px;
    text-align: center;
    /* غير المستحقّ يبقى ظاهراً باهتاً: إخفاؤه يحرم المستخدم من معرفة
       ما ينتظره، وهو نصف الدافع */
    opacity: .45;
    filter: grayscale(1);
    transition: opacity .3s, filter .3s;
}

.badge2.is-earned {
    opacity: 1;
    filter: none;
    border-color: color-mix(in srgb, var(--brand) 40%, var(--line));
    background: var(--brand-soft);
}

.badge2__icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    margin: 0 auto 7px;
    border-radius: var(--r-full);
    background: var(--surface-2);
    color: var(--ink-2);
}

.badge2.is-earned .badge2__icon { background: var(--brand); color: #fff; }

.badge2__label {
    display: block;
    font-size: 12px;
    font-weight: 700;
}

.badge2__hint {
    display: block;
    font-size: 10.5px;
    color: var(--ink-3);
    margin-top: 3px;
    line-height: 1.5;
}

/* -------------------------------------------------------------------------
   21. بطاقة الإنجاز اليومي (صفحة الاتجاهات)
   ------------------------------------------------------------------------- */
.dayc {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
    padding: 16px;
    margin-bottom: 16px;
}

.dayc__top { display: flex; align-items: center; gap: 15px; }

.dayc__ring { width: 72px; height: 72px; }
.dayc__ring .ring__inner { width: 57px; height: 57px; font-size: 14px; }

.dayc__head { flex: 1; min-width: 0; }

.dayc__title {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.4;
}

.dayc__msg {
    margin: 5px 0 0;
    font-size: 12.8px;
    line-height: 1.75;
    color: var(--ink-2);
}

.dayc__stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 15px;
}

.dayc__stat {
    background: var(--surface-2);
    border-radius: var(--r-md);
    padding: 10px 6px;
    text-align: center;
}

.dayc__num {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.1;
}

.dayc__num small { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.dayc__flame { color: var(--warn); }

.dayc__lbl {
    display: block;
    margin-top: 4px;
    font-size: 10.5px;
    color: var(--ink-3);
}

/* شبكة الثلاثين يوماً */
.dayc__grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 5px;
    margin-top: 15px;
}

.dayc__cell {
    aspect-ratio: 1;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid transparent;
}

.dayc__cell.is-full { background: var(--brand); }
.dayc__cell.is-partial { background: var(--brand-2); opacity: .5; }
.dayc__cell.is-missed { background: var(--danger-soft); }
/* الراحة لا لون لها: لم يُقصّر فيها أحد، فتلوينها كالفائت ظلم */
.dayc__cell.is-rest { background: var(--surface-2); }
/* اليوم بإطار لا بلون: لونه يقول «اكتمل» وهو ما لم يُعرف بعد */
.dayc__cell.is-today { border-color: var(--ink-3); }

.dayc__legend {
    display: flex;
    gap: 11px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 11px;
    font-size: 10.5px;
    color: var(--ink-3);
}

.dayc__legend span { display: flex; align-items: center; gap: 4px; }

.dayc__legend i {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    background: var(--surface-2);
    /* إطار خفيف: مربّع «الراحة» بلون السطح نفسه كان يختفي على
       البطاقة البيضاء فيبدو الدليل ناقص عنصر */
    border: 1px solid var(--line);
}

.dayc__legend i.is-full { background: var(--brand); }
.dayc__legend i.is-partial { background: var(--brand-2); opacity: .5; }
.dayc__legend i.is-missed { background: var(--danger-soft); }

/* علامة الإنجاز في صفوف اليوم */
.dayc__mark {
    width: 21px;
    height: 21px;
    flex: none;
    border-radius: var(--r-full);
    border: 1.6px solid var(--line-strong);
    display: grid;
    place-items: center;
    color: transparent;
}

.dayc__mark.is-done {
    background: var(--ok);
    border-color: var(--ok);
    color: #fff;
}

/* -------------------------------------------------------------------------
   22. شريط الصلاة القادمة (أعلى الرئيسية)
   ------------------------------------------------------------------------- */
.pstrip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg,
        var(--brand) 0%,
        color-mix(in srgb, var(--brand) 62%, #10121A) 100%);
    color: #fff;
    box-shadow: var(--sh-2);
}

/* بلا موقع: صفّ هادئ لا بطاقة ملوّنة — دعوةٌ للضبط لا إعلان */
.pstrip--quiet {
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    box-shadow: var(--sh-1);
}

.pstrip__icon {
    width: 38px;
    height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, .2);
}

.pstrip--quiet .pstrip__icon {
    background: var(--brand-soft);
    color: var(--brand);
}

.pstrip__main { flex: 1; min-width: 0; }

.pstrip__label {
    display: block;
    font-size: 11px;
    opacity: .82;
}

.pstrip--quiet .pstrip__label { color: var(--ink-3); opacity: 1; }

.pstrip__name {
    display: block;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.3;
}

.pstrip__right { text-align: end; flex: none; }

.pstrip__time {
    display: block;
    font-size: 15px;
    font-weight: 700;
}

/* العدّاد المتحرّك: أرقام جدولية وعرض ثابت.

   بدونهما يتغيّر عرض الرقم مع كل ثانية (١ أضيق من ٨) فيرتجف الشريط
   كله أمام العين — وهذا أسوأ من ألّا يتحرّك. */
.pstrip__left {
    display: block;
    font-size: 15px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: .02em;
    min-height: 19px;
    direction: ltr;
    text-align: end;
}

.pstrip__time { font-size: 11.5px; font-weight: 600; opacity: .82; }

/* الدقيقة الأخيرة: نبضة هادئة لا وميض — إشارة لا إنذار */
@keyframes pstrip-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .55; }
}

.pstrip.is-soon .pstrip__left { animation: pstrip-pulse 1.6s ease-in-out infinite; }

.pstrip.is-due .pstrip__left {
    font-size: 13px;
    animation: none;
}

@media (prefers-reduced-motion: reduce) {
    .pstrip.is-soon .pstrip__left { animation: none; }
}

/* رابط «المزيد» في البطاقة المختصرة */
.dayc__more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 13px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    font-weight: 700;
    color: var(--brand);
}

/* =========================================================================
   محادثة الوكيل
   ========================================================================= */

.chat {
    display: flex;
    flex-direction: column;
    gap: 14px;
    /* ارتفاع محسوب لا مطلق: الفقاعات تمرّ داخل الصندوق ويبقى صندوق
       الكتابة ثابتاً أسفله — وإلا طاردَه المستخدم بالتمرير في كل رسالة */
    max-height: calc(100vh - 330px);
    min-height: 240px;
    overflow-y: auto;
    padding: 4px 2px 8px;
    scrollbar-width: thin;
}

.chat__turn { display: flex; flex-direction: column; gap: 6px; }

.chat__bubble {
    max-width: 88%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 14.5px;
    line-height: 1.75;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* المستخدم إلى اليمين والوكيل إلى اليسار — الاتجاه يفرّق بينهما
   قبل أن يُقرأ اللون */
.chat__bubble--user {
    align-self: flex-end;
    background: var(--brand);
    color: #fff;
}

.chat__bubble--assistant {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
}

.chat__bubble--bad { background: var(--danger-soft); color: var(--danger); }

.chat__steps {
    align-self: flex-start;
    margin: 0;
    font-size: 10.5px;
    color: var(--ink-3);
}

.chat__action { border: 1px solid var(--line); }
.chat__action--wait { border-color: var(--warn); }

.chat__intro { display: flex; flex-direction: column; gap: 10px; padding: 18px 0; }

.chat__suggest {
    text-align: start;
    font: inherit;
    font-size: 13.5px;
    cursor: pointer;
    color: var(--ink);
}

.chat__compose {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.chat__input {
    flex: 1;
    resize: none;
    min-height: 46px;
    max-height: 140px;
    line-height: 1.6;
}

.chat__send {
    width: 46px;
    min-width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 50%;
    font-size: 18px;
}

.chat__mic {
    width: 46px;
    min-width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--surface-2);
}

.chat__mic--on { background: var(--danger); color: #fff; }
