:root {
  --ink: #1b2038;
  --paper: #f1f3f9;
  --surface: #ffffff;
  --line: #d9ddea;
  --muted: #5f6783;
  --action: #3346d3;
  --action-ink: #ffffff;
  --scheduled: #c97a10;
  --published: #0f7d6b;
  --failed: #c2372f;
  --scheduled-bg: #fdf1dc;
  --published-bg: #def3ee;
  --failed-bg: #fbe4e2;
  --radius: 10px;
  --font: "Readex Pro", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8eaf6; --paper: #12152a; --surface: #1b2040; --line: #323860; --muted: #a0a7c6;
    --action: #8795ff; --action-ink: #10132a;
    --scheduled: #f0b254; --published: #58cdb8; --failed: #ff8a80;
    --scheduled-bg: #3a2e14; --published-bg: #133831; --failed-bg: #431d1a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-weight: 400; line-height: 1.7;
  display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); min-height: 100vh;
}
body.bare { display: block; }
a { color: var(--action); }
h1, h2 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 600; }
h2 { font-size: 1.05rem; font-weight: 600; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.lead { max-width: 60ch; margin-top: -.5rem; }
:focus-visible { outline: 3px solid var(--action); outline-offset: 2px; border-radius: 4px; }

/* ---------- التنقل ---------- */
.nav {
  background: var(--ink); color: var(--paper); padding: 1.5rem 1rem;
  display: flex; flex-direction: column; gap: .25rem; position: sticky; top: 0; height: 100vh;
}
@media (prefers-color-scheme: dark) { .nav { background: #0b0e20; color: var(--ink); } }
.brand { font-size: 1.9rem; font-weight: 700; color: inherit; text-decoration: none; margin: 0 .5rem 1.25rem; letter-spacing: -.01em; }
.nav-new {
  background: var(--paper); color: #1b2038; text-decoration: none; font-weight: 600;
  padding: .6rem .9rem; border-radius: var(--radius); text-align: center; margin-bottom: 1rem;
}
@media (prefers-color-scheme: dark) { .nav-new { background: var(--action); color: var(--action-ink); } }
.nav-link { color: inherit; opacity: .72; text-decoration: none; padding: .5rem .75rem; border-radius: 8px; }
.nav-link:hover, .nav-link.on { opacity: 1; background: rgba(255, 255, 255, .1); }
.nav-out { margin-top: auto; padding: 0 .75rem; }
.nav .linkish { color: inherit; opacity: .7; }

.main { padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; min-width: 0; max-width: 76rem; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.back { font-size: .85rem; text-decoration: none; }
.back::before { content: "→ "; }

/* ---------- عناصر عامة ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.panel > h2 { margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.btn {
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  padding: .55rem 1.1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--action); border-color: var(--action); color: var(--action-ink); }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--action); }
.btn-danger { color: var(--failed); }
.btn-small { padding: .3rem .7rem; font-size: .85rem; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--action); cursor: pointer; text-decoration: underline; }
.linkish.danger { color: var(--failed); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.stack { display: grid; gap: 1rem; }

.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > span:first-child { font-size: .88rem; font-weight: 500; }
.field-inline { grid-template-columns: auto 1fr; align-items: center; gap: .75rem; }
input[type=text], input[type=password], input[type=datetime-local], select, textarea {
  font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: 8px; padding: .55rem .7rem; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.8; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--action); outline-offset: 0; border-color: var(--action); }
.check { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--action); flex: none; }
.checks-row { display: flex; flex-wrap: wrap; gap: .1rem 1.1rem; margin-bottom: .75rem; font-size: .9rem; }
.copy { display: flex; gap: .5rem; }
.ok-tag { color: var(--published); font-weight: 500; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid; }
.flash ul { margin: .3rem 0 0; padding-inline-start: 1.2rem; }
.flash p { margin: .4rem 0 0; }
.flash-ok { background: var(--published-bg); border-color: var(--published); }
.flash-err { background: var(--failed-bg); border-color: var(--failed); }
.hint { background: var(--scheduled-bg); border-radius: 8px; padding: .5rem .75rem; font-size: .88rem; margin: .5rem 0; }

/* علامات المنصات */
.mark { width: 1.35rem; height: 1.35rem; border-radius: 6px; display: inline-grid; place-items: center; flex: none;
  color: #fff; font: 700 .68rem/1 Arial, sans-serif; direction: ltr; }
.mark-facebook { background: #1877f2; } .mark-facebook::after { content: "f"; font-size: .9rem; }
.mark-instagram { background: #d62976; } .mark-instagram::after { content: "IG"; }
.mark-tiktok { background: #111; box-shadow: inset 0 0 0 1px #555; } .mark-tiktok::after { content: "TT"; }
.mark-x { background: #000; box-shadow: inset 0 0 0 1px #555; } .mark-x::after { content: "X"; font-size: .8rem; }

/* ---------- الجدول: خط الرحلات ---------- */
.tabs { display: flex; gap: .25rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .25rem; }
.tab { padding: .3rem .95rem; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: .92rem; white-space: nowrap; }
.tab b { font-weight: 500; font-variant-numeric: tabular-nums; margin-inline-start: .15rem; }
.tab.on { background: var(--ink); color: var(--paper); }
.tab-alert:not(.on) { color: var(--failed); }

.board { display: grid; grid-template-columns: minmax(0, 1fr) 17.5rem; gap: 2.5rem; align-items: start; }
.day { margin-bottom: 2.25rem; }
.day-head { font-size: 1rem; font-weight: 500; color: var(--muted); padding-bottom: .6rem; display: flex; gap: .6rem; align-items: baseline; }
.day-rel { color: var(--ink); font-weight: 700; font-size: 1.3rem; }
.rail { list-style: none; margin: 0; padding: 0; }
.stop { display: grid; grid-template-columns: 6rem minmax(0, 1fr); position: relative; }
.stop-time {
  font-size: 1.6rem; font-weight: 300; font-variant-numeric: tabular-nums; direction: ltr; text-align: right;
  line-height: 1; padding-top: 1.15rem; letter-spacing: -.02em;
}
/* السكة والنقطة */
.stop::before { content: ""; position: absolute; inset-inline-start: 6rem; top: 0; bottom: 0; width: 2px; background: var(--line); }
.stop:first-child::before { top: 1.5rem; }
.stop:last-child::before { bottom: calc(100% - 1.5rem); }
.stop:only-child::before { display: none; }
.stop::after {
  content: ""; position: absolute; inset-inline-start: calc(6rem - 6px); top: 1.2rem; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--scheduled);
}
.stop.is-published::after { background: var(--published); border-color: var(--published); }
.stop.is-failed::after { background: var(--failed); border-color: var(--failed); }
.stop.is-publishing::after { border-color: var(--action); }
.stop.is-published .stop-time { color: var(--muted); }
.stop-body {
  display: flex; gap: .9rem; align-items: flex-start; text-decoration: none; color: inherit;
  margin: .35rem 0 .35rem 0; margin-inline-start: 1.6rem; padding: .8rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.stop-body:hover { border-color: var(--ink); }
.stop.is-failed .stop-body { border-color: var(--failed); }
.stop-main { min-width: 0; display: grid; gap: .5rem; flex: 1; }
.stop-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.thumb { width: 3.6rem; height: 3.6rem; border-radius: 8px; object-fit: cover; flex: none; background: var(--paper); overflow: hidden; display: grid; place-items: center; }
.thumb-video { position: relative; }
.thumb-video video { width: 100%; height: 100%; object-fit: cover; }
.thumb-video::after { content: ""; position: absolute; border: .5rem solid transparent; border-inline-start: .8rem solid #fff; border-inline-end: 0; filter: drop-shadow(0 0 3px rgba(0,0,0,.6)); transform: scaleX(-1); }
.thumb-text { color: var(--muted); font-size: .8rem; border: 1px dashed var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; padding: .15rem .55rem .15rem .2rem; padding-inline: .2rem .6rem; border-radius: 999px; background: var(--scheduled-bg); }
.chip .mark { width: 1.15rem; height: 1.15rem; border-radius: 50%; font-size: .55rem; }
.chip .mark::after { font-size: .55rem; }
.chip-state { color: var(--scheduled); font-weight: 500; }
.chip-published { background: var(--published-bg); } .chip-published .chip-state { color: var(--published); }
.chip-failed { background: var(--failed-bg); } .chip-failed .chip-state { color: var(--failed); }
.chip-publishing .chip-state { color: var(--action); }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 2.5rem 1.5rem; text-align: center; }
.empty h2 { font-size: 1.25rem; margin-bottom: .4rem; }
.empty p { color: var(--muted); margin: 0 auto 1.1rem; max-width: 44ch; }

/* الشهر */
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; position: sticky; top: 1.5rem; }
.month-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.month-head a { text-decoration: none; font-size: 1.4rem; line-height: 1; padding: .1rem .6rem; border-radius: 6px; color: var(--ink); transform: scaleX(-1); }
.month-head a:hover { background: var(--paper); }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dow { font-size: .7rem; color: var(--muted); padding-bottom: .2rem; }
.cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 8px; text-decoration: none; color: var(--ink); font-size: .85rem; font-variant-numeric: tabular-nums; position: relative; }
.cell:hover { background: var(--paper); }
.cell.out { color: var(--muted); opacity: .45; }
.cell.today { box-shadow: inset 0 0 0 2px var(--ink); font-weight: 700; }
.cell.picked { background: var(--ink); color: var(--paper); }
.cell i { position: absolute; bottom: 2px; font-style: normal; font-size: 0; width: 6px; height: 6px; border-radius: 50%; background: var(--scheduled); }
.cell.has-published i { background: var(--published); }
.cell.has-failed i { background: var(--failed); }
.legend { list-style: none; display: flex; gap: 1rem; padding: 0; margin: .9rem 0 0; font-size: .78rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .35rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-scheduled { background: var(--scheduled); } .dot-published { background: var(--published); } .dot-failed { background: var(--failed); }

/* ---------- منشور جديد ---------- */
.composer { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.composer-main { display: grid; gap: 1.25rem; }
.meters { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.5rem 0 1rem; min-height: 1.6rem; }
.meter { font-size: .8rem; padding: .1rem .6rem; border-radius: 999px; background: var(--paper); font-variant-numeric: tabular-nums; }
.meter.over { background: var(--failed-bg); color: var(--failed); font-weight: 600; }
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.25rem; text-align: center; cursor: pointer; position: relative; }
.drop:hover, .drop.over { border-color: var(--action); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop-hint small { display: block; color: var(--muted); }
.preview img, .preview video { max-width: 100%; max-height: 16rem; border-radius: 8px; display: block; margin: 0 auto .4rem; }
.reuse { display: flex; align-items: center; gap: .75rem; margin-bottom: .6rem; font-size: .9rem; }
.reuse img, .reuse video { width: 3.6rem; height: 3.6rem; object-fit: cover; border-radius: 8px; }
.plat { border: 0; border-top: 1px solid var(--line); margin: 0; padding: .9rem 0 .5rem; min-width: 0; }
.plat:first-of-type { border-top: 0; padding-top: 0; }
.plat legend { font-weight: 600; display: flex; align-items: center; gap: .5rem; padding: 0; float: inline-start; width: 100%; margin-bottom: .4rem; }
.plat legend + * { clear: both; }
.plat-more { margin-top: .6rem; padding-inline-start: 1.6rem; }
.plat-warn { color: var(--failed); font-size: .85rem; margin: .3rem 0 0; }
.plat-text { margin-bottom: .25rem; }

/* ---------- تفاصيل منشور ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.detail-media img, .detail-media video { width: 100%; border-radius: 8px; display: block; }
.target { border: 1px solid var(--line); border-inline-start: 4px solid var(--scheduled); border-radius: 8px; padding: .8rem 1rem; margin-bottom: .8rem; }
.target-published { border-inline-start-color: var(--published); }
.target-failed { border-inline-start-color: var(--failed); }
.target header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.state { margin-inline-start: auto; font-size: .82rem; font-weight: 600; color: var(--scheduled); }
.state-published { color: var(--published); } .state-failed { color: var(--failed); } .state-publishing { color: var(--action); }
.target-text { white-space: pre-line; margin: 0 0 .4rem; }
.target p { margin: .3rem 0; }
.target-error { color: var(--failed); background: var(--failed-bg); border-radius: 8px; padding: .5rem .75rem; font-size: .9rem; }
.detail-form > h2 { margin-top: 1.25rem; }
.detail-form > h2:first-of-type { margin-top: 0; }

/* ---------- الحسابات والإعدادات ---------- */
.connect { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.connect .panel { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; }
.connect .panel p { margin: 0; flex: 1; font-size: .9rem; }
.connect .panel > h2 { margin: 0; }
.accounts { list-style: none; margin: 0; padding: 0; }
.accounts li { display: flex; align-items: center; gap: .75rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.accounts li:first-child { border-top: 0; }
.acc-name { display: grid; flex: 1; min-width: 0; line-height: 1.4; }
.settings { display: grid; gap: 1.25rem; max-width: 44rem; }
.settings .panel p { margin: 0 0 1rem; }


/* ---------- الدخول والصفحات القانونية ---------- */
.login { max-width: 22rem; margin: 14vh auto 0; }
.login-brand { font-size: 3.5rem; font-weight: 700; letter-spacing: -.02em; }
.login .muted { margin: .25rem 0 1.5rem; }
.legal { max-width: 65ch; margin: 3rem auto; }
.legal h2 { margin-top: 1.5rem; }

/* ---------- الهاتف ---------- */
@media (max-width: 60rem) {
  .board, .composer, .detail { grid-template-columns: minmax(0, 1fr); }
  .month { position: static; }
  .connect { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 46rem) {
  body { display: block; padding-bottom: 4.2rem; }
  .nav { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; align-items: center; justify-content: space-around; padding: .45rem .5rem; z-index: 10; gap: .25rem; }
  .brand, .nav-out { display: none; }
  .nav-new { margin: 0; order: 2; padding: .5rem .8rem; }
  .nav-link { padding: .45rem .6rem; font-size: .9rem; }
  .main { padding: 1.25rem 1rem 2rem; }
  h1 { font-size: 1.4rem; }
  .stop { grid-template-columns: 4.4rem minmax(0, 1fr); }
  .stop-time { font-size: 1.2rem; }
  .stop::before { inset-inline-start: 4.4rem; }
  .stop::after { inset-inline-start: calc(4.4rem - 6px); }
  .stop-body { margin-inline-start: 1.1rem; }
  .tabs { width: 100%; justify-content: space-between; }
}
@media (prefers-reduced-motion: no-preference) {
  .stop.is-publishing::after { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { transform: scale(1.35); } }
}
