* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* بيشيل المربع الأزرق يلي بيطلع وقت اللمس على الأزرار بالموبايل */
    -webkit-tap-highlight-color: transparent;
}

button {
    -webkit-user-select: none;
    user-select: none;
}

button:focus {
    outline: none;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

:root {
    --bg: #FFFFFF;
    --surface: #F7F7F7;
    --text: #0A0A0A;
    --text-secondary: #6E6E6E;
    --border: #E0E0E0;
    --gray-100: #F0F0F0;
    --gray-200: #E5E5E5;
    --ink: #0A0A0A;
    --ink-contrast: #FFFFFF;
    /* شريط التنقل فاتح بالوضع النهاري */
    --nav-bg: #F0F0F2;
    --nav-active-bg: #DCDCE0;
    --nav-icon: #7A7A80;
    --nav-icon-active: #0A0A0A;
    /* اللون الوحيد بالواجهة - محصور بزر الإرسال وفقاعة المستخدم متل المرجع */
    --accent: #0A84FF;
    /* فقاعة رسائلي زرقاء دايمًا بالوضعين - ما بتصير سودا بالنهاري */
    --user-bubble: #1E4E8C;
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-panel: rgba(250, 250, 250, 0.9);
    --glass-border: rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --radius-lg: 24px;
    --spacing: 16px;
}

:root[data-theme="dark"] {
    --bg: #000000;
    --surface: #121212;
    --text: #F2F2F2;
    --text-secondary: #9A9A9A;
    --border: #2A2A2A;
    --gray-100: #202020;
    --gray-200: #2A2A2A;
    --ink: #F2F2F2;
    --ink-contrast: #0A0A0A;
    --nav-bg: #1A1A1A;
    --nav-active-bg: #333333;
    --nav-icon: #7A7A7A;
    --nav-icon-active: #FFFFFF;
    /* فقاعة المستخدم كحلية داكنة متل المرجع */
    --user-bubble: #1E3A5F;
    --glass-bg: rgba(30, 30, 30, 0.6);
    --glass-panel: rgba(24, 24, 24, 0.85);
    --glass-border: rgba(255, 255, 255, 0.14);
}

/* ===== الوضع الثالث: ليلي كحلي ===== */
:root[data-theme="midnight"] {
    --bg: #0A1120;
    --surface: #101A2C;
    --text: #E9F1FB;
    --text-secondary: #8DA2C0;
    --border: #1E2D45;
    --gray-100: #16233A;
    --gray-200: #1F2F48;
    --ink: #E9F1FB;
    --ink-contrast: #0A1120;
    --nav-bg: #101A2C;
    --nav-active-bg: rgba(59, 130, 246, 0.2);
    --nav-icon: #7C8FAC;
    --nav-icon-active: #8FC0F0;
    --accent: #3B82F6;
    --user-bubble: #1E4E8C;
    --glass-bg: rgba(16, 26, 44, 0.66);
    --glass-panel: rgba(13, 22, 38, 0.9);
    --glass-border: rgba(143, 192, 240, 0.16);
}

/* توهّج خفيف بأعلى الشاشة - متل المرجع */
:root[data-theme="midnight"] body {
    background:
        radial-gradient(1100px 620px at 88% -8%, #1B2B45 0%, transparent 60%),
        radial-gradient(900px 520px at 8% 4%, #131F35 0%, transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

/* عناوين البطاقات بلون مزرق مع خط متدرّج تحتها */
:root[data-theme="midnight"] .card h3,
:root[data-theme="midnight"] .news-head h3 {
    color: #8FC0F0;
    position: relative;
    padding-bottom: 9px;
}

:root[data-theme="midnight"] .card h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    inset-inline-start: 0;
    width: 104px;
    height: 3px;
    border-radius: 3px;
    background: linear-gradient(to left, #3B82F6, #8B5CF6);
}

/* أيقونات المواد ملوّنة */
:root[data-theme="midnight"] .subject-icon { color: #5B9BE8; }
:root[data-theme="midnight"] [data-subject="biology"] .subject-icon { color: #4ADE80; }
:root[data-theme="midnight"] [data-subject="chemistry"] .subject-icon { color: #60A5FA; }
:root[data-theme="midnight"] [data-subject="physics"] .subject-icon { color: #38BDF8; }

:root[data-theme="midnight"] .subject-btn {
    background: rgba(22, 35, 58, 0.55);
    border-color: var(--border);
}

:root[data-theme="midnight"] .bottom-nav,
:root[data-theme="midnight"] .card {
    border: 1px solid var(--border);
}

:root[data-theme="midnight"] .nav-btn.active .icon {
    box-shadow: 0 0 18px rgba(59, 130, 246, 0.35);
}

html, body {
    height: 100%;
    /* لون الخلفية بيمتد تحت أشرطة النظام حتى ما يبين شريط فاصل */
    background: var(--bg);
    overscroll-behavior: none;
}

body {
    font-family: 'IBM Plex Sans Arabic', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

body, .card, .bottom-nav, .subject-btn, .icon-btn, .select-input,
.onboarding-input, .message, .chat-input, .send-btn, .chat-list-item,
.library-item {
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

.app-container {
    height: 100vh;
    overflow-y: auto;
    padding-bottom: 100px;
    scroll-behavior: smooth;
}

/* شاشة البداية السينمائية */
#splash {
    transition: opacity .55s ease, visibility .55s ease;
}

#splash.done {
    opacity: 0;
    visibility: hidden;
}

.splash-mark {
    width: 108px;
    height: 108px;
    animation: splash-rise 1s cubic-bezier(.2, .8, .25, 1) both;
}

.splash-mark img {
    width: 100%;
    height: 100%;
    display: block;
}

.splash-name {
    color: #fff;
    font-size: 21px;
    font-weight: 700;
    letter-spacing: .5px;
    animation: splash-rise .9s cubic-bezier(.2, .8, .25, 1) .18s both;
}

.splash-bar {
    width: 132px;
    height: 2px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
    animation: splash-rise .8s ease .3s both;
}

.splash-bar span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: 2px;
    background: #fff;
    animation: splash-sweep 1.15s ease-in-out infinite;
}

@keyframes splash-rise {
    from { opacity: 0; transform: translateY(14px) scale(.94); }
    to { opacity: 1; transform: none; }
}

@keyframes splash-sweep {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

@media (prefers-reduced-motion: reduce) {
    .splash-mark, .splash-name, .splash-bar { animation: none; }
    .splash-bar span { animation: none; width: 100%; }
}

/* Onboarding */
.onboarding {
    position: fixed;
    inset: 0;
    background: #0A0A0A;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing);
}

.onboarding-card {
    text-align: center;
    color: #fff;
    max-width: 360px;
    width: 100%;
}

.onboarding-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    color: #fff;
}

.onboarding-icon svg {
    width: 100%;
    height: 100%;
}

.onboarding-card h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 8px;
}

.onboarding-sub {
    color: #9A9A9A;
    margin-bottom: 24px;
    font-size: 15px;
}

.onboarding-input {
    width: 100%;
    padding: 14px 18px;
    border-radius: 14px;
    border: 1px solid #4A4A4A;
    background: #1A1A1A;
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    margin-bottom: 12px;
    text-align: center;
}

.onboarding-input::placeholder {
    color: #6E6E6E;
}

.btn-primary {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: #fff;
    color: #0A0A0A;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: default;
}

.btn-link {
    width: 100%;
    margin-top: 12px;
    padding: 8px;
    border: none;
    background: none;
    color: #9A9A9A;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-decoration: underline;
}

.auth-error {
    color: #FF6B6B;
    font-size: 13px;
    margin-bottom: 12px;
}

.btn-primary-sm, .btn-secondary-sm {
    padding: 10px 18px;
    border-radius: 12px;
    border: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary-sm {
    background: var(--ink);
    color: var(--ink-contrast);
}

.btn-primary-sm svg {
    width: 16px;
    height: 16px;
}

.btn-secondary-sm {
    background: var(--gray-100);
    color: var(--text);
}

/* Header */
.header {
    padding: calc(env(safe-area-inset-top, 0px) + 24px) var(--spacing) var(--spacing);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

/* التحية والاسم بسطر واحد: "صباح الخير، إيهاب" */
.greeting-line {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.4;
}

.greeting-line #greeting-time {
    color: var(--text-secondary);
    font-weight: 500;
}

.greeting-line #greeting-name {
    color: var(--text);
}

.header h1 {
    font-size: 26px;
    font-weight: 700;
}

.header .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn:active {
    background: var(--gray-200);
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing);
    margin: 0 var(--spacing) var(--spacing);
    border: 1px solid var(--border);
}

.card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    font-size: 14px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--ink);
}

.dashboard-grid {
    display: flex;
    flex-direction: column;
}

/* قسم الأخبار */
.news-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.news-head h3 {
    margin-bottom: 0;
}

.news-refresh {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    flex-shrink: 0;
}

.news-refresh svg {
    width: 16px;
    height: 16px;
    display: block;
}

.news-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.news-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 13px 12px;
    border-radius: 14px;
    text-decoration: none;
    color: inherit;
}

.news-item:active {
    background: var(--gray-100);
}

.news-item + .news-item {
    border-top: 1px solid var(--border);
}

.news-title {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.55;
    color: var(--text);
}

/* علامة المصدر الرسمي الموثوق */
.news-verified {
    display: inline-block;
    width: 15px;
    height: 15px;
    vertical-align: -2px;
    margin-inline-end: 5px;
}

.news-verified svg {
    width: 100%;
    height: 100%;
    display: block;
}

.news-source b {
    color: #18A957;
}

.news-refresh.spinning svg {
    animation: news-spin 1s linear infinite;
}

@keyframes news-spin {
    to { transform: rotate(-360deg); }
}

.news-summary {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.news-source {
    font-size: 11.5px;
    color: var(--accent);
    font-weight: 600;
}

/* تنبيه صغير فوق بطاقة الأخبار (مثلاً: ما في جديد) */
.news-card {
    position: relative;
}

.news-toast {
    position: absolute;
    top: 8px;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--glass-panel);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--glass-border);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    z-index: 5;
    animation: toast-in .22s ease both;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.news-note {
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* Subject grid */
.subject-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.subject-btn {
    padding: 16px 10px;
    border: 1px solid var(--border);
    background: var(--gray-100);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.subject-btn:active {
    background: var(--ink);
    color: var(--ink-contrast);
    transform: scale(0.96);
}

.subject-icon {
    width: 26px;
    height: 26px;
}

.subject-icon svg {
    width: 100%;
    height: 100%;
}

/* Empty states */
.empty-state {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 16px 0;
}

.empty-state-full {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 40vh;
    color: var(--text-secondary);
    text-align: center;
    padding: 0 32px;
}

/* Bottom Navigation (floating) */
.bottom-nav {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    left: 16px;
    right: 16px;
    height: 60px;
    background: var(--nav-bg);
    border-radius: 30px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding: 0 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* أيقونات فقط - بلا أسماء، أكبر ومتناسقة */
.nav-btn {
    flex: 1;
    height: 100%;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--nav-icon);
    font-family: inherit;
    padding: 0;
}

.nav-btn .label {
    display: none;
}

.nav-btn .icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.nav-btn .icon svg {
    width: 23px;
    height: 23px;
    display: block;
}

.nav-btn.active {
    color: var(--nav-icon-active);
}

.nav-btn.active .icon {
    background: var(--nav-active-bg);
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Teacher page: subject bar + chat list */
.teacher-subject-bar {
    padding: 0 var(--spacing) var(--spacing);
}

.chat-list-section {
    padding: 0 var(--spacing) var(--spacing);
}

.new-chat-btn {
    width: 100%;
    padding: 14px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: none;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 12px;
}

.new-chat-btn svg {
    width: 18px;
    height: 18px;
}

.new-chat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.new-chat-row {
    display: flex;
    gap: 8px;
}

.new-chat-row .select-input {
    flex: 1;
    background-image: none;
    padding: 12px 14px;
}

.new-chat-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* زر ربط المحادثة بكتاب من المكتبة (اختياري) */
.book-link-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 11px 14px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    text-align: start;
}

.book-link-btn svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.book-link-btn.active {
    border-style: solid;
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.sheet-hint {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: -6px 4px 12px;
}

.attachment-loading {
    font-size: 12.5px;
    color: var(--text-secondary);
    padding: 8px 4px;
}

.chat-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
}

.chat-list-open {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    text-align: right;
    overflow: hidden;
}

.chat-list-icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-list-icon svg {
    width: 100%;
    height: 100%;
}

.chat-list-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    min-width: 0;
}

.chat-list-title {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-list-delete {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 13px;
}

/* Chat view: its own full-screen layer (nav disappears behind it) */
.chat-fullscreen .bottom-nav {
    display: none;
}

#chat-view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* dvh بتتابع ارتفاع الشاشة الفعلي لما يطلع الكيبورد - هيك الترويسة
       ما بتنطلع برّا الشاشة وشريط الكتابة بيضل فوق الكيبورد. */
    height: 100dvh;
    z-index: 250;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

.chat-view-header {
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
}

.chat-view-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 14px;
    flex-shrink: 0;
}

#back-to-chats, #chat-view-new {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 0;
}

#back-to-chats svg, #chat-view-new svg {
    width: 22px;
    height: 22px;
    display: block;
}

.chat-view-title {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex: 1;
    text-align: center;
}

.chat-view-title span {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Base style for any text input / select using .select-input - specific
   containers below (toolbar, subject bar, new-chat form) tune it further. */
.select-input {
    width: 100%;
    padding: 12px 36px 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background-color: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236E6E6E' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='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;
}

.select-input::placeholder {
    color: var(--text-secondary);
}

/* زر الأدوات العائم - زجاجي شفاف، بيوفر مساحة بدل الشريط الكامل */
.chat-tools-btn {
    position: absolute;
    /* لازم يتبع نفس safe-area تبع الترويسة: بملء الشاشة الترويسة بتطول
       بمقدار شريط الحالة، فرقم ثابت هون بيخلي الزر يركب فوق العنوان. */
    top: calc(env(safe-area-inset-top, 0px) + 62px);
    right: 50%;
    transform: translateX(50%);
    z-index: 8;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.tools-sep {
    width: 1px;
    height: 11px;
    background: var(--glass-border);
    flex-shrink: 0;
}

#chat-tools-power {
    color: var(--text-secondary);
    font-weight: 500;
}

.tools-caret {
    width: 13px;
    height: 13px;
    color: var(--text-secondary);
    display: flex;
}

.tools-caret svg {
    width: 100%;
    height: 100%;
}

/* لوحة الأدوات الزجاجية */
.chat-tools-panel {
    position: absolute;
    /* نفس سبب الزر فوقه - لازم تتبع safe-area وإلا بتطلع فوق العنوان */
    top: calc(env(safe-area-inset-top, 0px) + 104px);
    right: 50%;
    transform: translateX(50%);
    z-index: 9;
    width: min(300px, calc(100% - 32px));
    padding: 14px;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    background: var(--glass-panel);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    box-shadow: 0 16px 40px rgba(0,0,0,0.4);
}

.tools-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.mode-options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.mode-option {
    padding: 8px 13px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    cursor: pointer;
}

.mode-option.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.power-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.power-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

.power-row span {
    font-size: 12px;
    font-weight: 600;
    min-width: 52px;
    text-align: left;
}

/* Subject picker (a real <select>) keeps the roomier style + dropdown arrow */
.teacher-subject-bar .select-input {
    padding: 12px 36px 12px 16px;
    font-size: 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background-size: 16px;
    background-position: left 12px center;
}

/* New-chat form fields are plain text inputs - no dropdown arrow */
.new-chat-form .select-input {
    padding: 12px 16px;
    font-size: 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background-image: none;
}

/* Chat messages */
/* الرسائل بتتلاشى تحت الترويسة وفوق شريط الكتابة بدل خطوط فاصلة حادة */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 56px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 26px;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px, #000 calc(100% - 20px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 28px, #000 calc(100% - 20px), transparent 100%);
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    text-align: center;
    padding: 40px 16px;
}

.chat-empty h2 {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.suggestion-chip {
    padding: 10px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}

.suggestion-chip:active {
    background: var(--gray-100);
}

.message p {
    margin: 0;
}

/* فقاعة المستخدم - زرقاء داكنة عاليمين متل المرجع.
   ملاحظة: بالاتجاه rtl الـ flex-start هو اليمين مش اليسار. */
.message.user {
    align-self: flex-start;
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 22px;
    background: var(--user-bubble);
    color: #fff;
    font-size: 16px;
    line-height: 1.7;
    word-wrap: break-word;
}

/* صورة المستخدم بلا أي فقاعة أو إطار - بتطلع لحالها */
.message.user-media {
    align-self: flex-start;
    background: none;
    padding: 0;
    max-width: 85%;
    line-height: 0;
}

/* رسائل المعلم: بلا فقاعة وبلا أفاتار - نص حر بعرض الشاشة */
.message.ai {
    align-self: stretch;
    max-width: 100%;
}

.message.ai .message-body {
    font-size: 16px;
    line-height: 1.9;
    color: var(--text);
    word-wrap: break-word;
    min-width: 0;
}

/* الفقرات المكتملة أثناء البث بتظهر منسّقة فورًا مع تلاشي ناعم */
.message-body.streaming .tw-block {
    animation: tw-fade .32s ease both;
}

/* النص الجديد وهو عم ينكتب - تلاشي عند حافّة الكتابة */
.message-body.streaming .tw-new {
    animation: tw-type .5s ease both;
}

@keyframes tw-fade {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: none; }
}

@keyframes tw-type {
    from { opacity: 0.15; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .message-body.streaming .tw-block,
    .message-body.streaming .tw-new { animation: none; }
}

/* تنسيق محتوى رد المعلم - شرح متسلسل مرتب متل السبورة */
.message-body p {
    margin: 0 0 18px;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body h3,
.message-body h4,
.message-body h5 {
    font-size: 16px;
    font-weight: 700;
    margin: 22px 0 10px;
}

.message-body h3:first-child,
.message-body h4:first-child,
.message-body h5:first-child {
    margin-top: 0;
}

.message-body ul,
.message-body ol {
    margin: 0 0 18px;
    padding-right: 22px;
}

.message-body li {
    margin-bottom: 10px;
}

.message-body li:last-child {
    margin-bottom: 0;
}

.message-body strong {
    font-weight: 700;
}

.message-body code {
    background: var(--gray-100);
    padding: 1px 5px;
    border-radius: 5px;
    font-size: 13px;
    direction: ltr;
    display: inline-block;
}

.message-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

/* معادلات KaTeX - المعادلات المستقلة تتمركز وتتمرّر أفقيًا لو طويلة */
.message-body .katex {
    font-size: 1.05em;
}

.message-body .katex-display {
    margin: 12px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}

/* الصورة المرسلة صغيرة - ما تاخد عرض المحادثة كله */
.message-image {
    max-width: 180px;
    max-height: 200px;
    width: auto;
    height: auto;
    object-fit: cover;
    border-radius: 12px;
    display: block;
    cursor: pointer;
}

.message-image + p {
    margin-top: 8px;
}

/* أكتر من صورة برسالة وحدة - شبكة صغيرة بدل صورة واحدة كبيرة */
.user-media-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.user-media-grid .message-image {
    max-width: 130px;
    max-height: 150px;
}

.message.typing {
    align-items: center;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding-top: 8px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing-bounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* زر اختيار المادة (بديل <select> الافتراضي) */
.picker-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.picker-caret {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
    display: flex;
    flex-shrink: 0;
}

.picker-caret svg {
    width: 100%;
    height: 100%;
}

/* لوحة منزلقة من تحت - بديل قوائم النظام */
.sheet {
    position: fixed;
    inset: 0;
    z-index: 350;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    animation: sheet-fade .2s ease;
}

.sheet-panel {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 78vh;
    overflow-y: auto;
    background: var(--glass-panel);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-bottom: none;
    border-radius: 26px 26px 0 0;
    padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 18px);
    animation: sheet-up .26s cubic-bezier(.2, .8, .25, 1);
}

@keyframes sheet-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes sheet-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--text-secondary);
    opacity: 0.35;
    margin: 4px auto 14px;
}

.sheet-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding: 0 4px;
}

.sheet-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sheet-option {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 15px 14px;
    border: none;
    background: none;
    border-radius: 15px;
    cursor: pointer;
    font-family: inherit;
    font-size: 16px;
    color: var(--text);
    text-align: right;
}

.sheet-option:active {
    background: var(--gray-100);
}

.sheet-option.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.sheet-option .opt-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    color: var(--text-secondary);
    display: flex;
}

.sheet-option.active .opt-icon {
    color: #fff;
}

.sheet-option .opt-icon svg {
    width: 100%;
    height: 100%;
}

/* حوارات التأكيد/الإدخال */
.dialog-panel {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
}

.dialog-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    padding: 0 4px;
}

.dialog-msg {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding: 0 4px;
}

.dialog-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    margin-bottom: 16px;
    outline: none;
}

.dialog-input:focus {
    border-color: var(--accent);
}

.dialog-actions {
    display: flex;
    gap: 10px;
}

.dialog-actions button {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 14px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.dialog-cancel {
    background: var(--gray-100);
    color: var(--text);
}

.dialog-ok {
    background: var(--accent);
    color: #fff;
}

.dialog-ok.danger {
    background: #E5484D;
}

/* زر النزول لآخر المحادثة */
.scroll-bottom-btn {
    position: absolute;
    bottom: 86px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: var(--glass-panel);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    line-height: 0;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.scroll-bottom-btn span {
    width: 20px;
    height: 20px;
    display: block;
}

.scroll-bottom-btn svg {
    width: 100%;
    height: 100%;
}

/* آخر المحادثات بصفحة المعلم (لما ما تكون مختار مادة) */
.recent-chats-section {
    padding: 0 var(--spacing) var(--spacing);
}

.recent-chats-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* شريط الكتابة عائم: بلا خلفية ولا خط فاصل - الكبسولة لحالها طايفة */
.input-area {
    flex-shrink: 0;
    padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
    background: transparent;
    position: relative;
}

/* شريط الكتابة - كبسولة واحدة. الاتجاه ltr عمدًا حتى يثبت ترتيب الأزرار
   بصريًا متل المرجع (+ يسار، مايك وإرسال يمين)، والنص جوّاتها بيضل rtl. */
.input-group {
    direction: ltr;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    background: var(--gray-100);
    border-radius: 30px;
    padding: 6px 8px;
}

/* ارتفاع السطر الواحد (42px) مضبوط ليساوي ارتفاع الأزرار بالضبط،
   هيك بتكون كلها متنصّفة تمامًا وقت السطر الواحد. */
.chat-input {
    direction: rtl;
    text-align: right;
    flex: 1;
    border: none;
    background: none;
    outline: none;
    resize: none;
    padding: 10px 8px;
    font-size: 15px;
    font-family: inherit;
    line-height: 22px;
    color: var(--text);
    min-height: 42px;
    max-height: 160px;
    overflow-y: auto;
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.send-btn, #attach-btn, #mic-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    line-height: 0;
}

#attach-btn, #mic-btn {
    color: var(--text);
}

#attach-btn svg {
    width: 23px;
    height: 23px;
    display: block;
}

#mic-btn svg {
    width: 21px;
    height: 21px;
    display: block;
}

#mic-btn.recording {
    background: var(--ink);
    color: var(--ink-contrast);
}

/* زر الإرسال أزرق متل المرجع - دايمًا ظاهر بس باهت لما ما يكون في شي
   تبعته، وبيصير كامل الوضوح أول ما تكتب أو ترفق. */
.send-btn {
    background: var(--accent);
    color: #fff;
    opacity: 0.35;
    transition: opacity .18s ease;
}

.send-btn.active {
    opacity: 1;
}

.send-btn svg {
    width: 21px;
    height: 21px;
    display: block;
}

/* قائمة الإرفاق (تطلع من زر +) */
.attach-menu {
    position: absolute;
    bottom: calc(100% - 4px);
    left: 12px;
    background: var(--glass-panel);
    backdrop-filter: blur(28px) saturate(180%);
    -webkit-backdrop-filter: blur(28px) saturate(180%);
    border: 1px solid var(--glass-border);
    border-radius: 22px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.35);
    z-index: 20;
    min-width: 240px;
}

.attach-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 15px 16px;
    border: none;
    background: none;
    border-radius: 15px;
    cursor: pointer;
    font-family: inherit;
    font-size: 16px;
    color: var(--text);
    text-align: right;
}

.attach-option:hover,
.attach-option:active {
    background: var(--gray-100);
}

.attach-option span:first-child {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.attach-option svg {
    width: 100%;
    height: 100%;
}

/* معاينة المرفق قبل الإرسال */
/* شريط أفقي فيه بلاطة لكل مرفق معلّق - يدعم أكتر من صورة بنفس الوقت */
.attachment-preview {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 8px;
    padding: 4px 2px;
}

.attachment-tile {
    position: relative;
    flex-shrink: 0;
}

.attachment-tile img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 12px;
    display: block;
    border: 1px solid var(--border);
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-100);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    max-width: 200px;
    height: 64px;
    box-sizing: border-box;
}

.attachment-chip span:first-child {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.attachment-chip svg {
    width: 100%;
    height: 100%;
}

.attachment-chip .chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-remove {
    position: absolute;
    top: -6px;
    left: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: var(--ink);
    color: var(--ink-contrast);
    font-size: 11px;
    cursor: pointer;
    line-height: 1;
    z-index: 1;
}

/* شريط التسجيل الصوتي - كبسولة عائمة فيها موجة صوت حيّة متل المرجع */
.recording-bar {
    direction: ltr;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-100);
    border-radius: 30px;
    padding: 6px 8px;
}

#rec-cancel {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text);
    font-size: 17px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.rec-wave {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 34px;
    overflow: hidden;
}

.rec-wave span {
    width: 3px;
    min-height: 3px;
    border-radius: 2px;
    background: var(--text-secondary);
    transition: height .08s linear;
}

.recording-time {
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    flex-shrink: 0;
    min-width: 34px;
    text-align: center;
}

#rec-stop {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--gray-200);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 0;
}

#rec-stop svg {
    width: 17px;
    height: 17px;
    display: block;
}

/* تكبير الصورة عند الضغط */
.img-lightbox {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, 0.94);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.img-lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
}

/* مشغّل الصوت المخصص داخل الرسالة */
.audio-player {
    direction: ltr;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 210px;
}

.audio-player audio {
    display: none;
}

.audio-play {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 0;
}

.audio-play svg {
    width: 15px;
    height: 15px;
    display: block;
}

.audio-wave {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2.5px;
    height: 22px;
}

.audio-wave span {
    flex: 1;
    min-width: 2px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.35);
    transition: background .15s linear;
}

.audio-wave span.played {
    background: #fff;
}

.audio-time {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 30px;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-100);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 13px;
    margin-bottom: 6px;
}

.message-file span:first-child {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.message-file svg {
    width: 100%;
    height: 100%;
}

/* Library page */
.library-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 var(--spacing) 12px;
}

.library-toolbar .picker-btn {
    flex: 1;
    min-width: 0;
}

.library-toolbar .btn-primary-sm {
    flex-shrink: 0;
}

#library-kind-filter {
    padding-inline: var(--spacing);
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 var(--spacing);
}

/* خيار كتاب بلوحة الاختيار: اسم + سطر تصنيف تحته */
.opt-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    text-align: start;
}

.opt-sub {
    font-size: 11.5px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* شرائح التصنيف (نوع الكتاب / المادة) */
.chip-row {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 10px;
}

.chip {
    flex-shrink: 0;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.chip-n {
    opacity: .65;
    font-size: 11.5px;
}

/* وسم نوع الكتاب فوق الغلاف */
.book-kind-tag {
    position: absolute;
    bottom: 6px;
    inset-inline-start: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 10.5px;
    font-weight: 600;
}

/* بطاقة كتاب: غلاف من أول صفحة + اسم تحته - على نمط بطاقات منهاجي */
.library-item {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 18px 34px -20px rgba(0,0,0,.45);
    transition: transform .18s ease;
}

.library-item:active {
    transform: scale(.98);
}

.book-cover {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: var(--gray-100);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
}

.book-cover-ph {
    width: 34px;
    height: 34px;
    color: var(--text-secondary);
    opacity: .5;
    display: block;
}

.book-cover-ph svg {
    width: 100%;
    height: 100%;
}

.book-body {
    padding: 11px 12px 13px;
}

.book-title {
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta {
    font-size: 11.5px;
    color: var(--text-secondary);
    margin-top: 3px;
}

.library-actions {
    position: absolute;
    top: 7px;
    left: 7px;
    display: flex;
    gap: 5px;
}

.library-act {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.library-act svg {
    width: 16px;
    height: 16px;
    display: block;
}

.library-act[data-act="delete"]:active {
    background: #E5484D;
    color: #fff;
}

/* PDF viewer overlay */
.pdf-viewer {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 400;
    display: flex;
    flex-direction: column;
}

.pdf-viewer-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

#pdf-viewer-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

#pdf-viewer-close svg {
    width: 18px;
    height: 18px;
}

#pdf-viewer-title {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* القفز لصفحة برقمها - ضروري بكتب الدورات (مئات الصفحات) */
.pdf-jump {
    width: 68px;
    flex-shrink: 0;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: center;
    outline: none;
}

.pdf-jump:focus {
    border-color: var(--accent);
}

.pdf-pages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--gray-100);
}

.pdf-page {
    width: 100%;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    /* بدونها بينكمش الحاجز داخل عمود الفلكس فتفقد الصفحات ارتفاعها،
       وبتنرسم كل الصفحات دفعة وحدة وبيعلّق الموبايل بالكتب الكبيرة. */
    flex-shrink: 0;
}

.pdf-page-num {
    color: #b9b9b9;
    font-size: 15px;
    font-weight: 600;
}

/* وضع اختيار صفحات (لربط محادثة بكتاب) - كل صفحة قابلة للضغط بوضوح،
   وممكن تختار أكتر من وحدة (درس كامل بتماريه) */
.pdf-viewer.pick-mode .pdf-page {
    cursor: pointer;
    outline: 2px solid transparent;
    outline-offset: 2px;
    transition: outline-color .15s ease;
    position: relative;
}

.pdf-viewer.pick-mode .pdf-page:active {
    outline-color: var(--accent);
}

.pdf-viewer.pick-mode #pdf-viewer-title {
    color: var(--accent);
    font-weight: 700;
}

/* صفحة مختارة - إطار واضح وعلامة صح بالزاوية */
.pdf-page.picked {
    outline: 3px solid var(--accent) !important;
}

.pdf-page.picked::after {
    content: '✓';
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* شريط تأكيد اختيار الصفحات - ثابت بأسفل الفاتح */
.pdf-pick-bar {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.pdf-pick-bar span {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
}

.pdf-page canvas {
    display: block;
}

.pdf-loading {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 30px 16px;
}

/* Pomodoro */
.pomodoro-phase {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.pomodoro-ring {
    position: relative;
    width: 200px;
    height: 200px;
    margin: 16px auto 20px;
}

.pomodoro-svg {
    width: 100%;
    height: 100%;
}

.pomodoro-track {
    fill: none;
    stroke: var(--gray-100);
    stroke-width: 10;
}

.pomodoro-progress {
    fill: none;
    stroke: var(--ink);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 552.9;
    stroke-dashoffset: 0;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 1s linear, stroke 0.2s ease;
}

.pomodoro-time {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.pomodoro-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 18px;
}

.pomodoro-toggle-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: var(--ink);
    color: var(--ink-contrast);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.pomodoro-toggle-btn svg {
    width: 26px;
    height: 26px;
}

.pomodoro-durations {
    display: flex;
    justify-content: center;
    gap: 24px;
    font-size: 13px;
    color: var(--text-secondary);
}

.pomodoro-durations input {
    width: 44px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    text-align: center;
    font-family: inherit;
    margin: 0 4px;
}

/* Goals */
.goal-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.goal-input-row .select-input {
    background-image: none;
}

.goals-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.goal-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--gray-100);
    border-radius: 12px;
}

.goal-checkbox {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    color: var(--ink-contrast);
}

.goal-checkbox.checked {
    background: var(--ink);
    border-color: var(--ink);
}

.goal-checkbox svg {
    width: 12px;
    height: 12px;
}

.goal-text {
    flex: 1;
    font-size: 14px;
}

.goal-text.done {
    text-decoration: line-through;
    color: var(--text-secondary);
}

.goal-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
}
