@font-face {
  font-family: "Cairo";
  src: url("/fonts/cairo-arabic.woff2") format("woff2");
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "Cairo";
  src: url("/fonts/cairo-latin.woff2") format("woff2");
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0000-024F, U+2000-206F, U+20AC;
}
@font-face {
  font-family: "Warsh";
  src: url("/fonts/warsh.woff2") format("woff2");
  font-display: swap;
}

:root {
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='72' height='72' viewBox='0 0 72 72'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.07' stroke-width='1.2'%3E%3Cpath d='M36 4l9.4 22.6L68 36l-22.6 9.4L36 68l-9.4-22.6L4 36l22.6-9.4z'/%3E%3Crect x='17' y='17' width='38' height='38' transform='rotate(45 36 36)'/%3E%3Crect x='17' y='17' width='38' height='38'/%3E%3C/g%3E%3C/svg%3E");
  --primary: #0b4f3a;
  --primary-2: #0f766e;
  --primary-3: #12996b;
  --soft: #dcf5ea;
  --gold: #c8962e;
  --gold-soft: #fdf3dc;
  --gold-ink: #7a5610;
  --red: #c02626;
  --red-soft: #fde8e8;
  --ink: #15231d;
  --ink-2: #33453d;
  --muted: #64766d;
  --line: #e3e9e5;
  --bg: #f3f6f4;
  --card: #fff;
  --th: #f1f5f2;
  --paper: #fffdf4;
  --paper-line: #e6d9ac;
  --input: #fff;
  --shadow: 0 1px 2px #0b2f2212, 0 6px 18px #0b2f2212;
  --shadow-lg: 0 18px 50px #0b2f2233;
  --radius: 16px;
}
:root[data-theme="dark"] {
  --primary: #0a3b2c;
  --primary-2: #2fb398;
  --primary-3: #34d399;
  --soft: #123a2e;
  --gold: #e2b254;
  --gold-soft: #3b2f13;
  --gold-ink: #f3d596;
  --red: #f87171;
  --red-soft: #431a1a;
  --ink: #e8f0ec;
  --ink-2: #c9d6d0;
  --muted: #93a69c;
  --line: #2a3a33;
  --bg: #0e1613;
  --card: #16211c;
  --th: #1c2a24;
  --paper: #171e19;
  --paper-line: #4a4227;
  --input: #111a16;
  --shadow: 0 1px 2px #0005, 0 6px 18px #0005;
  --shadow-lg: 0 18px 50px #0008;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.65 "Cairo", "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 24px; font-weight: 800; margin: 0; letter-spacing: -.2px; }
h2 { font-size: 17px; font-weight: 800; margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-2); }
.ico { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* Connexion */
.login { min-height: 100%; display: grid; grid-template-columns: 1.15fr 1fr; background: var(--card); }
.login-hero {
  background: var(--pattern), linear-gradient(155deg, #0b4f3a, #0f766e 70%, #12996b);
  color: #fff; display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; padding: 40px;
}
.login-logo { width: 96px; height: 96px; border-radius: 28px; background: #ffffff1f; display: grid; place-items: center; margin-bottom: 20px; border: 1px solid #ffffff33; }
.login-logo .ico { width: 54px; height: 54px; color: #fde7ae; }
.login-hero h1 { font-size: 34px; line-height: 1.3; }
.login-hero p { font-size: 17px; opacity: .85; max-width: 420px; margin: 10px 0 0; }
.login-side { display: flex; align-items: center; justify-content: center; padding: 24px 16px; position: relative; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 26px; margin-bottom: 4px; }
.login-card > p { color: var(--muted); margin: 0 0 20px; }
.lang-switch { position: absolute; top: 16px; inset-inline-end: 16px; }

/* Structure */
.shell { display: flex; min-height: 100%; }
.sidebar {
  width: 268px; flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto; color: #fff;
  background: var(--pattern), linear-gradient(170deg, #0b4f3a, #0a3f30 60%, #083326); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; padding: 6px 8px 16px; line-height: 1.35; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; background: #ffffff1f; display: grid; place-items: center; flex: none; }
.brand-mark .ico { width: 24px; height: 24px; color: #fde7ae; }
.nav-link {
  display: flex; align-items: center; gap: 12px; width: 100%; color: #e2f2ea; text-decoration: none; padding: 9px 12px;
  border-radius: 11px; border: 0; background: none; cursor: pointer; text-align: start; font-weight: 600; transition: background .15s;
}
.nav-link:hover { background: #ffffff17; color: #fff; }
.nav-link.active { background: #fff; color: #0b4f3a; font-weight: 800; box-shadow: 0 4px 12px #0003; }
.nav-link .badge { margin-inline-start: auto; }
.nav-spacer { flex: 1; min-height: 12px; }
.nav-user { border-top: 1px solid #ffffff26; margin-top: 8px; padding: 10px 8px 2px; font-size: 14px; }
.nav-user b { display: block; }
.nav-user span { opacity: .75; font-size: 13px; }
.badge { background: var(--gold); color: #1d1503; border-radius: 99px; padding: 0 8px; font-size: 13px; font-weight: 800; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none; background: linear-gradient(120deg, #0b4f3a, #0f766e); color: #fff; padding: 10px 16px;
  align-items: center; gap: 12px; position: sticky; top: 0; z-index: 5; box-shadow: 0 2px 10px #0003;
}
.topbar b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 24px; max-width: 1240px; width: 100%; margin-inline: auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; flex: 0 1 260px; margin: 0; }
.bottom-nav { display: none; }

/* Cartes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.welcome {
  background: var(--pattern), linear-gradient(120deg, #0b4f3a, #0f766e 65%, #12996b); color: #fff; border-radius: 20px;
  padding: 22px 24px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.welcome h1 { font-size: 26px; }
.welcome p { margin: 4px 0 0; opacity: .9; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); min-width: 0; }
.stat-ico { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex: none; background: var(--soft); color: var(--primary-2); }
.stat.gold .stat-ico { background: var(--gold-soft); color: var(--gold); }
.stat.red .stat-ico { background: var(--red-soft); color: var(--red); }
.stat b { display: block; font-size: 23px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.stat span { color: var(--muted); font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 2px; }
.section-title { margin: 6px 0 12px; }

/* Graphiques */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 22px; border-bottom: 1px solid var(--line); }
.chart-col { flex: 1; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; }
.chart-bar { width: min(100%, 34px); background: var(--primary-3); border-radius: 4px 4px 0 0; }
.chart-col:hover .chart-bar { background: var(--primary-2); }
.chart-col::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% - 18px); background: var(--ink); color: var(--card);
  font-size: 13px; padding: 2px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; z-index: 2;
}
.chart-col:hover::after, .chart-col:focus::after { opacity: 1; }
.chart-axis { display: flex; gap: 6px; margin-top: 4px; }
.chart-axis span { flex: 1; min-width: 0; text-align: center; font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; }
details.data-view { margin-top: 8px; font-size: 14px; color: var(--muted); }
details.data-view summary { cursor: pointer; }
.usage { display: grid; gap: 10px; }
.usage-row span { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border: 1px solid transparent;
  border-radius: 11px; padding: 8px 16px; cursor: pointer; min-height: 42px; transition: filter .15s, transform .05s;
}
:root[data-theme="dark"] .btn { background: linear-gradient(135deg, #0f766e, #12996b); }
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost, :root[data-theme="dark"] .btn.ghost { background: var(--card); color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--soft); filter: none; }
.btn.danger, :root[data-theme="dark"] .btn.danger { background: var(--card); color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red-soft); filter: none; }
.btn.small { padding: 3px 11px; min-height: 34px; font-size: 14px; border-radius: 9px; }
.btn.full { width: 100%; }
.btn.on-dark, :root[data-theme="dark"] .btn.on-dark { background: #ffffff1f; border-color: #ffffff40; color: #fff; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.menu-btn { background: #ffffff1f; border: 0; color: #fff; border-radius: 10px; padding: 7px; cursor: pointer; display: grid; }

/* Formulaires */
label.field { display: block; margin-bottom: 11px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; padding: 8px 12px; border: 1.5px solid var(--line); border-radius: 11px;
  background: var(--input); color: var(--ink); min-height: 44px; font-size: 16px; font-weight: 500; margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary-3); box-shadow: 0 0 0 3px #12996b2e; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--primary-3); outline-offset: 2px; }
textarea { min-height: 96px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.error { background: var(--red-soft); color: var(--red); padding: 9px 13px; border-radius: 11px; margin-bottom: 12px; font-weight: 700; }
.note { background: var(--gold-soft); color: var(--gold-ink); padding: 9px 13px; border-radius: 11px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.empty .ico { width: 42px; height: 42px; display: block; margin: 0 auto 8px; opacity: .5; }

/* Tableaux */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: start; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--th); font-size: 13.5px; font-weight: 800; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--soft) 45%, transparent); }
tr:last-child td { border-bottom: 0; }
.tag { display: inline-block; padding: 1px 11px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--soft); color: var(--primary-2); }
.tag.warn { background: var(--gold-soft); color: var(--gold-ink); }
.tag.bad { background: var(--red-soft); color: var(--red); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 6px 16px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.tab.active { background: var(--primary-2); border-color: var(--primary-2); color: #fff; }
:root[data-theme="dark"] .tab.active { color: #06241c; }

/* Personnes */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.person { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.person:hover { border-color: var(--primary-3); transform: translateY(-2px); }
.person b { display: block; font-size: 17px; font-weight: 800; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 20px; background: var(--soft); color: var(--primary-2); }
.avatar.f { background: var(--gold-soft); color: var(--gold-ink); }
.bar { background: var(--line); border-radius: 99px; height: 10px; overflow: hidden; margin: 8px 0 4px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary-2), var(--primary-3)); border-radius: 99px; }

/* Plan du Coran */
.sura-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; margin-top: 10px; }
.sura-cell { aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--th); color: var(--muted); }
.sura-cell.part { background: #a7e3c9; color: #0b3a2a; }
.sura-cell.full { background: var(--primary-2); color: #fff; }
:root[data-theme="dark"] .sura-cell.full { color: #06241c; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }

/* Presences */
.att-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.att-row:last-child { border-bottom: 0; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 4px 11px; cursor: pointer; min-height: 38px; font-weight: 700; }
.seg button.on-present { background: var(--soft); border-color: var(--primary-2); color: var(--primary-2); }
.seg button.on-absent { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.seg button.on-late, .seg button.on-excused { background: var(--gold-soft); border-color: var(--gold); color: var(--gold-ink); }

/* Messages */
.message { padding: 13px; border-bottom: 1px solid var(--line); border-radius: 10px; }
.message:last-child { border-bottom: 0; }
.message.unread { background: var(--gold-soft); }
.message-head { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.message p { margin: 4px 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Mushaf */
.mushaf-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.mushaf-bar select, .mushaf-bar input { width: auto; flex: 1 1 120px; margin: 0; }
.mushaf-page {
  background: var(--paper); border: 2px solid var(--gold); outline: 1px solid var(--paper-line); outline-offset: -8px;
  border-radius: 14px; padding: 24px 22px; max-width: 780px; margin: 0 auto 12px; box-shadow: var(--shadow);
}
.mushaf-text { font-family: "Warsh", serif; font-weight: 400; font-size: calc(27px * var(--mushaf-scale, 1)); line-height: 2.3; text-align: justify; margin: 0; }
.sura-title { font-family: "Warsh", serif; font-weight: 400; text-align: center; font-size: 25px; color: var(--primary-2); background: var(--gold-soft); border: 1.5px solid var(--gold); border-radius: 10px; padding: 3px 8px; margin: 8px 0; }
.basmala { font-family: "Warsh", serif; font-weight: 400; text-align: center; font-size: calc(26px * var(--mushaf-scale, 1)); line-height: 2.2; }
.page-no { text-align: center; color: var(--muted); margin-top: 10px; }
.mushaf-page, .mushaf-page * { direction: rtl; }

/* Priere */
.prayer-hero { background: var(--pattern), linear-gradient(130deg, #0b4f3a, #0f766e); color: #fff; border-radius: 20px; padding: 22px; text-align: center; margin-bottom: 16px; box-shadow: var(--shadow); }
.prayer-hero b { display: block; font-size: 40px; font-weight: 800; direction: ltr; line-height: 1.25; }
.prayers { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
.prayer { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px; text-align: center; box-shadow: var(--shadow); }
.prayer.next { border-color: var(--primary-3); box-shadow: 0 0 0 2px var(--primary-3); }
.prayer b { display: block; font-size: 25px; font-weight: 800; direction: ltr; }

/* Fenetres */
.modal-back { position: fixed; inset: 0; background: #06140f99; backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.modal { background: var(--card); border-radius: 18px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; padding: 20px; box-shadow: var(--shadow-lg); }
.modal-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.cred { background: var(--soft); border-radius: 11px; padding: 10px 14px; direction: ltr; text-align: left; font-family: Consolas, monospace; font-size: 18px; overflow-wrap: anywhere; }
.qr { width: 150px; margin: 10px auto; background: #fff; padding: 6px; border-radius: 10px; }
.qr svg { display: block; width: 100%; height: auto; }

#toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); z-index: 30; pointer-events: none; }
#toast div { background: var(--ink); color: var(--card); padding: 9px 18px; border-radius: 11px; font-weight: 700; box-shadow: var(--shadow-lg); }
#print-area { display: none; }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .login-hero { padding: 26px 16px; }
  .login-logo { width: 68px; height: 68px; margin-bottom: 10px; border-radius: 20px; }
  .login-logo .ico { width: 38px; height: 38px; }
  .login-hero h1 { font-size: 23px; }
  .login-hero p { display: none; }
  .sidebar { position: fixed; inset-inline-start: 0; top: 0; bottom: 0; z-index: 15; transition: transform .2s; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  [dir] .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax #0007; }
  .topbar { display: flex; }
  .content { padding: 14px 16px 90px; }
  .form-grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .mushaf-text { font-size: calc(23px * var(--mushaf-scale, 1)); }
  .mushaf-page { padding: 20px 16px; }
  .welcome { padding: 18px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 11px; gap: 9px; }
  .stat-ico { width: 36px; height: 36px; border-radius: 10px; }
  .stat b { font-size: 19px; }

  .bottom-nav {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 14px #0b2f2214;
  }
  .bottom-link {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 2px; color: var(--muted); text-decoration: none;
    font-size: 11.5px; font-weight: 700; border: 0; background: none; cursor: pointer; position: relative; border-radius: 10px; font-family: inherit; line-height: 1.3;
  }
  .bottom-link span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-link.active { color: var(--primary-2); background: var(--soft); }
  .bottom-link .badge { position: absolute; top: 0; inset-inline-end: 22%; font-size: 11px; padding: 0 5px; }

  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border-bottom: 6px solid var(--bg); padding: 8px 0; }
  table.cards tr:last-child { border-bottom: 0; }
  table.cards td { border: 0; padding: 3px 14px; display: flex; justify-content: space-between; gap: 12px; overflow-wrap: anywhere; }
  table.cards td:empty { display: none; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 14px; flex: none; }
  table.cards td.row-actions { justify-content: flex-start; padding-top: 8px; }
  table.cards td.row-actions::before { content: none; }
}

@media print {
  body { background: #fff; color: #000; }
  #app, #modal-root, #toast { display: none; }
  #print-area { display: block; padding: 24px; }
  #print-area table { margin-top: 12px; }
  #print-area th { background: #eee; color: #000; }
  .print-center { text-align: center; }
  .certificate { border: 6px double #a67c1f; padding: 36px 30px; text-align: center; min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
  .certificate h1 { font-size: 40px; color: #0b4f3a; }
  .certificate .who { font-size: 32px; font-weight: 800; }
  .certificate p { font-size: 20px; margin: 0; }
  .sheet-qr { width: 200px; margin: 16px auto; }
  .sheet-qr svg { width: 100%; height: auto; }
}
