:root {
  --cream: #F6EFE3; --paper: #FFFBF4; --navy: #1E2A47; --navy-2: #3A4766; --muted: #7A7F8E;
  --coral: #E07A5F; --coral-soft: #F7DDD4; --green: #2F7D5B; --green-soft: #DCEFE5;
  --amber: #A86B12; --amber-soft: #F6E7C8; --red: #B4412F; --red-soft: #F6D9D3;
  --line: #E6DCCB; --radius: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--cream); color: var(--navy); font: 15px/1.6 'Tajawal', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--coral); }
h1, h2, h3 { margin: 0; font-weight: 800; line-height: 1.3; text-wrap: balance; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 16px; }
.muted { color: var(--muted); }
.quran { font-family: 'Amiri', serif; font-weight: 700; font-size: 17px; line-height: 1.9; }

/* layout */
.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--navy); color: #EDE6DA; padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand img { width: 40px; height: 40px; border-radius: 50%; background: var(--cream); }
.brand b { font-size: 20px; font-weight: 800; display: block; line-height: 1.1; }
.brand small { color: #B8B2A6; font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: #D9D2C5; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.on { background: var(--coral); color: #fff; }
.nav svg { width: 20px; height: 20px; flex: none; }
.side .foot { margin-top: auto; padding: 8px; font-size: 13px; color: #B8B2A6; }
.side .foot button { background: none; border: 0; color: #B8B2A6; cursor: pointer; padding: 0; text-decoration: underline; }
main { padding: 26px max(16px, env(safe-area-inset-right, 0px)) 90px max(16px, env(safe-area-inset-left, 0px)); max-width: 1120px; width: 100%; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* cards & bits */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 800; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: var(--amber-soft); color: var(--amber); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.info { background: var(--coral-soft); color: #9A4A34; }
.pill.dim { background: #EEE7DA; color: var(--navy-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-weight: 500; }
.banner.warn { background: var(--amber-soft); color: #6E4608; }
.banner.bad { background: var(--red-soft); color: #7C2A1E; }
.banner .btn { margin-inline-start: auto; }

.btn { border: 1px solid var(--line); background: var(--paper); color: var(--navy); text-decoration: none; display: inline-block; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 500; transition: background .15s, transform .1s; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:hover { background: #F3EBDD; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--coral); border-color: var(--coral); color: #fff; }
.btn.primary:hover { background: #D66D52; }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=time], input[type=number], input[type=tel], select, textarea {
  width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--coral); box-shadow: 0 0 0 3px var(--coral-soft); }
textarea { min-height: 90px; resize: vertical; line-height: 1.7; }
label.f { display: grid; gap: 5px; font-size: 14px; font-weight: 500; }
label.f small { color: var(--muted); font-weight: 400; }
.form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: 0; }
.switch input { width: 42px; height: 24px; accent-color: var(--coral); }
.err { color: var(--red); font-size: 13px; min-height: 1em; }

/* today */
.today { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; }
.phone { width: 100%; aspect-ratio: 9 / 16; border-radius: 16px; background: #000; object-fit: cover; display: block; max-width: 100%; }
.today .meta { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.caption { white-space: pre-wrap; background: #fff; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; overflow-wrap: anywhere; }
.week { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; }
.wday { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-size: 13px; }
.wday b { display: block; font-size: 14px; margin-top: 2px; }
.logs { display: grid; gap: 0; }
.logs .l { display: grid; grid-template-columns: 92px 18px minmax(0, 1fr); gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.logs .l:last-child { border-bottom: 0; }
.logs .t { color: var(--muted); font-size: 12px; direction: ltr; text-align: end; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal .wd { text-align: center; color: var(--muted); font-size: 13px; font-weight: 500; }
.cell { background: #fff; border: 1px solid var(--line); border-radius: 12px; min-height: 112px; padding: 7px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; text-align: start; position: relative; }
.cell:hover { border-color: var(--coral); }
.cell.out { visibility: hidden; }
.cell.today { outline: 2px solid var(--coral); outline-offset: 1px; }
.cell .num { font-weight: 800; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.cell img { width: 100%; height: 46px; object-fit: cover; border-radius: 7px; }
.cell .tt { font-size: 12px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cell.empty { background: transparent; border-style: dashed; color: var(--muted); }
.cell .st { width: 9px; height: 9px; border-radius: 50%; }
.st.pending { background: #C9BFAE; } .st.posted { background: var(--green); } .st.dry { background: #7FA9C9; }
.st.skipped { background: var(--amber); } .st.failed { background: var(--red); } .st.sending { background: var(--coral); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--coral-soft); color: #9A4A34; align-self: flex-start; }
.tag.وطنية { background: #D7EBDD; color: #1F6B45; }
.tag.جمعة { background: #E4E0F3; color: #4B3F8C; }
.tag.رمضان { background: #F6E7C8; color: #7A4E0C; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* library */
.lib { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; text-align: start; padding: 0; }
.pcard:hover { border-color: var(--coral); }
.pcard img { width: 100%; aspect-ratio: 9 / 12; object-fit: cover; display: block; }
.pcard .b { padding: 10px; display: grid; gap: 4px; font-size: 13px; }
.pcard .b b { font-size: 15px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(30, 42, 71, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.sheet { background: var(--paper); border-radius: 18px; width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; }
.sheet .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.x { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.split { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 18px; }

/* whatsapp */
.code { font: 800 34px/1 ui-monospace, monospace; letter-spacing: 6px; direction: ltr; text-align: center; background: #fff; border: 2px dashed var(--coral); border-radius: 14px; padding: 18px; }
.qr { width: 260px; max-width: 100%; border-radius: 12px; background: #fff; padding: 8px; display: block; margin: auto; }
ol.steps { margin: 0; padding-inline-start: 20px; display: grid; gap: 6px; }

/* stats */
.chart { width: 100%; height: 180px; display: block; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
td, th { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: start; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.scroll { overflow-x: auto; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; display: grid; gap: 16px; text-align: center; }
.login img { width: 84px; height: 84px; margin: auto; border-radius: 50%; }

.toast { position: fixed; bottom: 86px; inset-inline: 0; margin: auto; width: max-content; max-width: calc(100% - 32px); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 500; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; top: auto; inset-inline: 0; height: auto; flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); z-index: 40; overflow-x: auto; }
  .brand, .side .foot { display: none; }
  .nav { display: flex; gap: 2px; width: 100%; justify-content: space-between; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; flex: 1; justify-content: center; }
  main { padding-top: 18px; }
  .banner { font-size: 14px; padding: 9px 12px; gap: 8px; margin-bottom: 10px; flex-wrap: nowrap; }
  .banner .btn { flex: none; }
  .today, .split { grid-template-columns: 1fr; }
  .today video, .split video { max-width: 240px; margin: auto; }
  .cal { gap: 4px; }
  .cell { min-height: 74px; padding: 4px; }
  .cell img, .cell .tag { display: none; }
  .cell .tt { font-size: 10.5px; }
  .cal .wd { font-size: 11px; }
}
