:root {
  --green: #0F6E56;
  --green-dark: #0A5240;
  --green-soft: #DCEFE7;
  --orange: #E8772E;
  --orange-soft: #FBE7D6;
  --orange-ink: #8A4A12;
  --cream: #FBF6EE;
  --card: #FFFFFF;
  --text: #1F2A26;
  --muted: #5E655F;
  --border: #E4DACB;
  --warn-bg: #FFF4D6;
  --warn-ink: #6B4E00;
  --error: #B3261E;
  --error-soft: #FDE2E0;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--cream); color: var(--text); font-family: 'Cairo', system-ui, sans-serif; font-size: 15px; }
[hidden] { display: none !important; }
a { color: var(--green); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.4; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 4px 0; }

/* الدخول */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-logo { width: 72px; height: 72px; margin: 0 auto; }
.login-card label { text-align: right; display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.turnstile { min-height: 0; display: flex; justify-content: center; }

input, select, textarea { font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text); }
textarea { min-height: 70px; resize: vertical; }

.btn { font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer; background: #EEEAE3; color: var(--text); }
.btn.primary { background: var(--green); color: #fff; }
.btn.orange { background: var(--orange); color: #fff; }
.btn.danger { background: var(--error); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* الهيكل */
.shell { display: flex; min-height: 100vh; }
.side { width: 230px; background: var(--green-dark); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; padding: 18px 16px; font-weight: 800; font-size: 20px; flex-wrap: wrap; }
.brand img { width: 34px; height: 34px; background: #fff; border-radius: 10px; padding: 3px; }
.brand small { width: 100%; font-size: 12px; font-weight: 600; opacity: .7; }
#nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; overflow-y: auto; flex: 1; }
#nav a { color: #fff; text-decoration: none; padding: 9px 12px; border-radius: 10px; display: flex; align-items: center; gap: 6px; font-weight: 600; }
#nav a:hover { background: rgba(255,255,255,.08); }
#nav a.active { background: rgba(255,255,255,.16); }
.count { margin-inline-start: auto; background: var(--orange); color: #fff; border-radius: 99px; padding: 0 8px; font-size: 12px; }
.side-foot { padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.side-foot .btn { color: #fff; border-color: rgba(255,255,255,.3); }
.main { flex: 1; padding: 22px; min-width: 0; }

/* كروت وجداول */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 26px; font-weight: 800; color: var(--green-dark); }
.stat span { color: var(--muted); font-weight: 600; }
.stat.alert b { color: var(--orange); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.section { margin-top: 20px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: right; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #F6F0E6; font-size: 13px; color: var(--muted); white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #FDFaf4; }
.pill { display: inline-block; border-radius: 99px; padding: 1px 10px; font-size: 12px; font-weight: 700; background: #EEEAE3; color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--green-soft); color: var(--green-dark); }
.pill.wait { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--error-soft); color: var(--error); }
.pill.review { background: var(--orange-soft); color: var(--orange-ink); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs button.active { background: var(--green); color: #fff; }

/* الصور والفيديو */
.media { display: flex; gap: 8px; flex-wrap: wrap; }
.media img, .media video { width: 160px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: #eee; cursor: zoom-in; }
.media video { cursor: default; }
.thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; background: #eee; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 50; cursor: zoom-out; }
.lightbox img, .lightbox video { max-width: 94vw; max-height: 92vh; border-radius: 10px; }

/* الحركة */
.feed { display: flex; flex-direction: column; gap: 8px; }
.event { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.event.new { border-color: var(--orange); box-shadow: 0 0 0 2px var(--orange-soft); }
.event .when { margin-inline-start: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.event b { display: block; }

/* الشات */
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; padding: 8px; background: #F6F0E6; border-radius: 12px; }
.bubble { max-width: 75%; padding: 6px 10px; border-radius: 12px; background: #fff; }
.bubble.b { align-self: flex-end; background: var(--green-soft); }
.bubble small { display: block; color: var(--muted); font-size: 11px; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 10px; }
.bars div { flex: 1; background: var(--green); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars div:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; right: 50%; transform: translateX(50%); background: var(--text); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }

.toasts { position: fixed; bottom: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 14px; border-radius: 12px; max-width: 340px; box-shadow: 0 6px 20px rgba(0,0,0,.2); cursor: pointer; }
.toast b { display: block; }

.empty { text-align: center; color: var(--muted); padding: 30px; }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  #nav { flex-direction: row; overflow-x: auto; padding-bottom: 8px; }
  #nav a { white-space: nowrap; }
  .side-foot { flex-direction: row; }
  .main { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
}
