/* رزنامة صرح بغداد — نيلي وذهبي بروح تربوية */
:root {
    --navy: #19204e;
    --navy-2: #252d66;
    --navy-soft: #e8eaf6;
    --gold: #c9a248;
    --gold-dark: #a98322;
    --gold-soft: #f6edd2;
    --cream: #fcf9f2;
    --ink: #1c2245;
    --muted: #6c7195;
    --line: #ece4cd;
    --ok: #2f9a78;
    --ok-soft: #e1f4ec;
    --danger: #c9503f;
    --danger-soft: #fbe8e4;
    --radius: 18px;
    --shadow: 0 10px 30px rgba(25, 32, 78, .10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
    color: var(--ink);
    background: var(--cream) url("/img/bg-pattern.svg") repeat;
    min-height: 100vh;
    line-height: 1.6;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; color: inherit; }
a { color: inherit; }

.page { max-width: 1180px; margin: 0 auto; padding: 18px 16px 48px; }

/* ===== الشريط العلوي ===== */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
    color: #fff;
    border-bottom: 3px solid var(--gold);
    box-shadow: 0 6px 20px rgba(25, 32, 78, .25);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand img { width: 46px; height: 46px; flex: none; }
.brand span { display: flex; flex-direction: column; min-width: 0; }
.brand b { color: var(--gold); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { opacity: .8; font-size: .78rem; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.top-actions form { margin: 0; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 999px; font-size: .88rem; font-weight: 500;
    background: rgba(255, 255, 255, .10); color: #fff; border: 1px solid rgba(255, 255, 255, .18);
    text-decoration: none; cursor: pointer; white-space: nowrap;
}
.chip[hidden] { display: none; }
.chip-user { background: transparent; border-color: transparent; color: var(--gold); font-weight: 700; cursor: default; }
.chip-link:hover, .chip-btn:hover { background: rgba(255, 255, 255, .2); }
.chip-btn { background: var(--gold); color: var(--navy); border-color: var(--gold); font-weight: 700; }
.chip-out { background: transparent; border-color: var(--gold); color: var(--gold); }
.chip-out:hover { background: var(--gold); color: var(--navy); }

/* ===== الأزرار والحقول ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 11px 22px; border-radius: 14px; border: 2px solid transparent;
    font-weight: 700; cursor: pointer; text-decoration: none;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-gold { background: var(--gold); color: var(--navy); box-shadow: 0 4px 12px rgba(201, 162, 72, .35); }
.btn-gold:hover { background: #d4ae55; }
.btn-ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { background: #27856a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 6px 14px; font-size: .88rem; border-radius: 11px; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 5px; color: var(--navy); }
.field input, .field select, .field textarea {
    width: 100%; padding: 11px 14px; border-radius: 14px;
    border: 2px solid var(--line); background: #fff; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(201, 162, 72, .2); }
.field textarea { resize: vertical; }

.alert { padding: 11px 16px; border-radius: 14px; margin-bottom: 14px; font-weight: 500; }
.alert:empty, .alert.validation-summary-valid { display: none; }
.alert-ok { background: var(--ok-soft); color: #1d6b53; border: 1px solid #b7e0d1; }
.alert-err { background: var(--danger-soft); color: #922f21; border: 1px solid #f1c3bb; }
.alert ul { margin: 0; padding-inline-start: 18px; }
.offline-bar { background: #fff4d6; border: 1px solid var(--gold); color: #7a5a0f; padding: 10px 16px; border-radius: 14px; margin-bottom: 14px; font-weight: 700; text-align: center; }
.offline-bar[hidden] { display: none; }

/* ===== صفحات الدخول ===== */
.auth-body { background: var(--navy) url("/img/bg-pattern.svg") repeat; background-blend-mode: soft-light; }
.auth-body .page { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth-card {
    width: 100%; max-width: 420px; text-align: center;
    background: #fff; border-radius: 26px; padding: 28px 24px 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .35); border-top: 6px solid var(--gold);
}
.auth-card form { text-align: right; margin-top: 18px; }
.auth-logo { width: 130px; height: 130px; background: var(--navy); border-radius: 50%; padding: 8px; margin: -70px auto 10px; display: block; box-shadow: 0 8px 20px rgba(25, 32, 78, .35); border: 4px solid #fff; }
.auth-card h1 { font-size: 1.45rem; color: var(--navy); }
.auth-sub { color: var(--muted); margin: 6px 0 0; }
.auth-foot { color: var(--muted); font-size: .85rem; margin: 16px 0 0; }
.auth-card-light { margin-top: 24px; }
.auth-body .auth-card { margin-top: 74px; }

/* ===== تخطيط الرزنامة ===== */
.layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; align-items: start; }

.layout > * { min-width: 0; }
.cal-card, .card, .day-panel {
    background: rgba(255, 255, 255, .96); border-radius: 24px; box-shadow: var(--shadow);
    border: 1px solid var(--line);
}
.cal-card { padding: 16px; }

.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.cal-title { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cal-title h2 { color: var(--navy); font-size: 1.55rem; font-weight: 800; }
.today-btn { background: var(--gold-soft); color: var(--gold-dark); border: 0; border-radius: 999px; padding: 2px 14px; font-weight: 700; cursor: pointer; font-size: .85rem; }
.nav-btn {
    width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--navy); color: var(--gold); display: grid; place-items: center;
    box-shadow: 0 4px 12px rgba(25, 32, 78, .25); transition: transform .12s ease;
}
.nav-btn:hover { transform: scale(1.07); }
.nav-btn:active { transform: scale(.93); }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.weekdays > div { white-space: nowrap; overflow: hidden; text-align: center; font-weight: 800; font-size: .85rem; color: var(--navy); background: var(--gold-soft); border-radius: 10px; padding: 5px 0; }
.weekdays > .wk { background: var(--navy-soft); color: var(--muted); }
.grid { margin-top: 6px; }

.day {
    position: relative; aspect-ratio: 1 / 1; min-height: 52px;
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
    padding: 4px 2px 6px; border-radius: 16px; cursor: pointer;
    background: #fff; border: 2px solid var(--line); color: var(--ink);
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.day:hover { transform: translateY(-2px); border-color: var(--gold); box-shadow: 0 6px 14px rgba(201, 162, 72, .25); }
.day.wk { background: #fbf8ee; }
.day.out { opacity: .42; }
.day .num { font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
.day .mkrow { display: flex; align-items: center; justify-content: center; gap: 3px; min-height: 26px; margin-bottom: 1px; }
.mk { font-style: normal; font-size: .85rem; line-height: 1; }
/* علامات اليوم: شعار المدرسة. المهمة = ذهبي على أبيض، الاجتماع = ذهبي على كحلي */
img.mk { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; display: block; box-shadow: 0 0 0 1.5px var(--gold), 0 2px 5px rgba(25, 32, 78, .25); }
img.mk-task { background: #fff; object-fit: contain; }
img.mk-meeting { background: var(--navy); }
.mk-done { color: var(--ok); font-weight: 800; font-size: 1.2rem; }
.cnt { font-style: normal; font-size: .66rem; font-weight: 700; background: var(--navy); color: #fff; border-radius: 999px; padding: 0 5px; line-height: 1.4; }
.day.has { border-color: #e4d3a1; background: linear-gradient(180deg, #fffdf6, #fff7dd); }

.day.today { border-color: var(--gold); }
.day.today .num { background: var(--navy); color: var(--gold); border-radius: 50%; width: 30px; height: 30px; display: grid; place-items: center; }
.day.sel { background: var(--navy); border-color: var(--navy); color: #fff; box-shadow: 0 8px 18px rgba(25, 32, 78, .35); }
.day.sel .num { color: #fff; }
.day.sel.today .num { background: var(--gold); color: var(--navy); }
.day.sel .mk-done { color: #7fe2bd; }
.day.sel .cnt { background: var(--gold); color: var(--navy); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 12px; color: var(--muted); font-size: .85rem; }

/* ===== لوحة اليوم ===== */
.day-panel { padding: 18px; min-height: 260px; position: relative; overflow: hidden; }
.day-panel::after {
    content: ""; position: absolute; inset-inline-start: -30px; bottom: -30px; width: 190px; height: 190px;
    background: url("/img/logo-gold.png") no-repeat center / contain; opacity: .06; pointer-events: none;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h3 { color: var(--navy); font-size: 1.2rem; font-weight: 800; }
.today-tag { display: inline-block; background: var(--gold); color: var(--navy); font-weight: 800; border-radius: 999px; padding: 0 10px; margin-bottom: 4px; }
.panel-sum { color: var(--muted); margin: 2px 0 0; font-size: .9rem; }
.btn-add { padding: 9px 18px; flex: none; }
.plus { font-size: 1.3rem; line-height: 1; }

.empty { text-align: center; padding: 18px 8px 8px; color: var(--muted); }
.empty p { margin: 8px 0 14px; }

.entries { display: grid; gap: 12px; position: relative; z-index: 1; }
.entry {
    display: flex; gap: 12px; padding: 12px; border-radius: 18px;
    background: #fff; border: 2px solid var(--line); border-inline-start: 6px solid var(--navy-2);
}
.entry.k-meeting { border-inline-start-color: var(--gold); background: linear-gradient(180deg, #fff, #fffaf0); }
.entry.is-done { background: #f6fbf8; border-color: #cfeadf; border-inline-start-color: var(--ok); }
.entry.is-done h4 { text-decoration: line-through; text-decoration-color: rgba(47, 154, 120, .6); color: var(--muted); }

.e-time { flex: none; width: 66px; text-align: center; background: var(--navy); color: #fff; border-radius: 14px; padding: 8px 4px; align-self: flex-start; }
.e-time b { display: block; font-size: 1.15rem; color: var(--gold); line-height: 1.2; }
.e-time small { font-size: .78rem; opacity: .85; }
.is-done .e-time { background: var(--ok); }
.is-done .e-time b { color: #fff; }

.e-body { flex: 1; min-width: 0; }
.e-top { display: flex; gap: 6px; margin-bottom: 3px; flex-wrap: wrap; }
.e-body h4 { font-size: 1.05rem; color: var(--navy); overflow-wrap: anywhere; }
.e-notes { margin: 4px 0 0; color: var(--muted); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.e-rem { margin: 4px 0 0; font-size: .85rem; color: var(--gold-dark); font-weight: 700; }
.e-donenote { margin-top: 8px; background: var(--ok-soft); border-radius: 12px; padding: 8px 12px; font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.e-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.btn-del { color: var(--danger); }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 1px 10px; border-radius: 999px; }
.badge-task { background: var(--navy-soft); color: var(--navy-2); }
.badge-meeting { background: var(--gold-soft); color: var(--gold-dark); }
.badge-done { background: var(--ok-soft); color: #1d6b53; }
.badge-admin { background: var(--gold-soft); color: var(--gold-dark); }
.badge-user { background: var(--navy-soft); color: var(--navy-2); }
.badge-off { background: var(--danger-soft); color: #922f21; }
.badge-wait { background: #fff4d6; color: #7a5a0f; }

/* ===== النوافذ ===== */
.dlg { border: 0; padding: 0; border-radius: 24px; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 24px 70px rgba(25, 32, 78, .45); background: #fff; color: var(--ink); overflow: auto; border-top: 6px solid var(--gold); }
.dlg::backdrop { background: rgba(25, 32, 78, .55); backdrop-filter: blur(2px); }
.dlg form { padding: 22px 20px 18px; }
.dlg h3 { color: var(--navy); font-size: 1.25rem; font-weight: 800; margin-bottom: 14px; }
.dlg-small p { margin: 0 0 14px; }
.dlg-date { color: var(--muted); margin: -8px 0 12px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 6px; }
.dlg-actions .btn { flex: 1; }
.form-err { color: #922f21; background: var(--danger-soft); border-radius: 12px; padding: 8px 12px; margin: 0 0 10px; font-weight: 700; }
.form-err[hidden] { display: none; }
.time-row { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 10px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 14px; border: 2px solid var(--line); font-weight: 700; background: #fff; }
.seg input:checked + span { background: var(--navy); color: var(--gold); border-color: var(--navy); }
.seg input:focus-visible + span { box-shadow: 0 0 0 4px rgba(201, 162, 72, .35); }

/* ===== إشعارات ===== */
.toasts { position: fixed; inset-inline: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
    pointer-events: auto; max-width: 520px; width: 100%;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 16px;
    border: 2px solid var(--gold); box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
    animation: pop .25s ease; transition: opacity .3s, transform .3s;
}
.toast.out { opacity: 0; transform: translateY(10px); }
.toast-sticky { background: #fff; color: var(--navy); font-weight: 700; }
.toast button { background: var(--navy); color: var(--gold); border: 0; width: 28px; height: 28px; border-radius: 50%; font-size: 1.1rem; cursor: pointer; flex: none; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }

/* ===== لوحة المسؤول ===== */
.page-title { color: var(--navy); font-size: 1.6rem; font-weight: 800; }
.page-sub { color: var(--muted); margin: 4px 0 16px; }
.card { padding: 18px; margin-bottom: 18px; }
.card h2 { color: var(--navy); font-size: 1.15rem; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.form-grid .field { margin-bottom: 0; }
.user-list { display: grid; gap: 10px; }
.user-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 16px; background: #fff; border: 2px solid var(--line); }
.user-row.off { opacity: .7; background: #f6f4ee; }
.user-name { font-weight: 800; font-size: 1.05rem; color: var(--navy); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.user-meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: flex; gap: 6px; margin: 0; }
.inline-form input { padding: 6px 12px; border-radius: 11px; border: 2px solid var(--line); width: 170px; }

/* ===== الهاتف: الرزنامة فوق والمهام تحتها ===== */
@media (max-width: 899px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .page { padding: 12px 10px 90px; }
    .cal-card { padding: 12px 10px; border-radius: 20px; }
    .day-panel { border-radius: 20px; }
}
@media (max-width: 560px) {
    .topbar { flex-wrap: wrap; row-gap: 8px; }
    .brand { flex: 1 1 100%; }
    .top-actions { flex: 1 1 100%; justify-content: flex-start; gap: 6px; }
    .brand small { display: none; }
    .brand b { font-size: .98rem; }
    .brand img { width: 40px; height: 40px; }
    .topbar { padding-inline: 10px; }
    .chip { padding: 5px 11px; font-size: .8rem; }
    .chip-user { display: none; }
    .weekdays, .grid { gap: 4px; }
    .weekdays > div { font-size: .74rem; padding: 4px 0; }
    .day { min-height: 46px; border-radius: 12px; padding-bottom: 4px; }
    .day .num { font-size: 1rem; }
    .day.today .num { width: 26px; height: 26px; }
    img.mk { width: 21px; height: 21px; }
    .day .mkrow { min-height: 22px; gap: 2px; }
    .cal-title h2 { font-size: 1.3rem; }
    .entry { flex-direction: column; gap: 8px; }
    .e-time { width: auto; align-self: flex-start; display: flex; gap: 6px; align-items: baseline; padding: 4px 12px; }
    .time-row { grid-template-columns: 1fr 1fr 1.2fr; gap: 6px; }
    .inline-form input { width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ===== لوحة الأدمن: التبويبات، الإحصاءات، سجل النشاط ===== */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.tabs a { padding: 8px 20px; border-radius: 999px; background: #fff; border: 2px solid var(--line); font-weight: 700; text-decoration: none; color: var(--navy); }
.tabs a:hover { border-color: var(--gold); }
.tabs a.on { background: var(--navy); border-color: var(--navy); color: var(--gold); }
.tabs .tab-back { margin-inline-start: auto; background: var(--gold-soft); border-color: transparent; color: var(--gold-dark); }
.link { color: var(--gold-dark); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.8rem; color: var(--navy); line-height: 1.2; }
.stat span { color: var(--muted); font-size: .88rem; font-weight: 500; }
.stat-warn { border-color: #f1c3bb; background: var(--danger-soft); }
.stat-warn b { color: var(--danger); }

.user-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.filters .field { margin-bottom: 0; }

.log-list { display: grid; gap: 8px; }
.log-row { padding: 10px 14px; border-radius: 14px; background: #fff; border: 2px solid var(--line); }
.log-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.log-who { color: var(--navy); }
.log-time { margin-inline-start: auto; color: var(--muted); font-size: .85rem; }
.log-det { margin-top: 4px; overflow-wrap: anywhere; }
.log-dev { margin-top: 2px; color: var(--muted); font-size: .8rem; }
.lg-ok { background: var(--ok-soft); color: #1d6b53; }
.lg-bad { background: var(--danger-soft); color: #922f21; }
.lg-muted { background: #eef0f5; color: var(--muted); }
.lg-admin { background: var(--gold-soft); color: var(--gold-dark); }
.lg-info { background: var(--navy-soft); color: var(--navy-2); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 14px; color: var(--muted); }

.day-group h2 { font-size: 1.05rem; }
.day-group .entry .e-time { width: auto; padding: 6px 10px; }
.day-group .entry .e-time b { font-size: .95rem; }
