:root {
  --red: #bf2435; --red-dark: #9a1b2a; --red-soft: #fbe9eb;
  --sun: #ffda62; --sun-soft: #fff4cc;
  --ink: #241f1a; --muted: #6f665a; --line: #e9e1cf; --bg: #fbf7ee; --card: #fffdf8;
  --ok: #1f7a4d; --ok-soft: #e4f4ea; --warn: #8a5a10; --warn-soft: #fff0d6;
  --radius: 14px; --shadow: 0 1px 2px #3b2a0f0d, 0 6px 18px #3b2a0f0a;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.7 Cairo, Tahoma, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.35; margin: 0; }
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .82rem; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* أزرار وحقول */
.primary, .ghost { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px; border-radius: 10px; font-weight: 700; cursor: pointer; border: 1px solid var(--red); }
.primary { background: var(--red); color: #fff; } .primary:hover:enabled { background: var(--red-dark); }
.ghost { background: transparent; color: var(--red); border-color: var(--line); } .ghost:hover:enabled { border-color: var(--red); }
button:disabled { opacity: .55; cursor: wait; }
.link { background: none; border: 0; padding: 4px 2px; color: var(--red); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: #8f1d2a; }
.field { display: grid; gap: 4px; font-weight: 600; font-size: .9rem; }
.field small { font-weight: 400; color: var(--muted); font-size: .78rem; }
input, select, textarea { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #d9cfba; border-radius: 10px; background: #fff; }
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible { outline: 3px solid #f2a9b2; outline-offset: 1px; }
input:disabled { background: #f5f1e7; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; } .check input { width: 20px; min-height: 20px; }
.stack { display: grid; gap: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; align-items: end; }
.actions, .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.notice { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; border-inline-start: 4px solid; }
.notice.ok { background: var(--ok-soft); border-color: var(--ok); color: #155c39; }
.notice.error { background: var(--red-soft); border-color: var(--red); color: #8f1d2a; }
.note { background: var(--sun-soft); border-radius: 10px; padding: 10px 14px; margin: 14px 0; color: #5a4310; }
.tag { display: inline-block; padding: 1px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; background: #f0ebe0; color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.warn { background: var(--warn-soft); color: var(--warn); }
.warn-text { color: var(--warn); font-size: .88rem; }

/* الدخول */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; background: linear-gradient(160deg, var(--red) 0 34%, var(--bg) 34%); }
.auth-card { width: min(100%, 440px); background: var(--card); border-radius: 20px; padding: 26px 22px; box-shadow: 0 20px 50px #3b0a1022; }
.auth-card .logo { display: block; margin: -62px auto 8px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
.auth-card h1 { text-align: center; font-size: 1.3rem; margin-bottom: 14px; }
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: #f3ecdc; border-radius: 12px; margin-bottom: 16px; }
.switch button { border: 0; background: transparent; border-radius: 9px; min-height: 40px; font-weight: 700; color: var(--muted); cursor: pointer; }
.switch button.on { background: #fff; color: var(--red); box-shadow: var(--shadow); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; font-weight: 600; }

/* الإطار */
.shell { min-height: 100vh; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--red); font-size: 1.1rem; }
.brand img { border-radius: 50%; }
.me-chip { margin-inline-start: auto; display: grid; text-align: end; line-height: 1.3; }
.me-chip small { color: var(--muted); }
.icon-btn { min-height: 40px; padding: 6px 10px; }
.tabs { display: flex; gap: 4px; padding: 8px 16px; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button[aria-current] { background: var(--red-soft); color: var(--red); }
.main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 90px; }
.head { margin: 4px 0 16px; } .head h1 { font-size: 1.45rem; } .head p { margin: 2px 0 0; color: var(--muted); }
.foot { margin-top: 28px; font-size: .75rem; color: var(--muted); text-align: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 2px; }
.card span { color: var(--muted); font-size: .85rem; } .card b { font-size: 1.6rem; } .card small { color: var(--muted); }
.card.alert { border-color: var(--sun); background: var(--sun-soft); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; box-shadow: var(--shadow); }
.panel h2 { font-size: 1.1rem; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.panel h3 { font-size: 1rem; margin: 16px 0 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary h2 { margin: 0; }
details.panel > summary::after { content: "＋"; float: left; color: var(--red); font-weight: 700; }
details.panel[open] > summary { margin-bottom: 12px; } details.panel[open] > summary::after { content: "－"; }
summary::-webkit-details-marker { display: none; }
.edit { border-color: var(--sun); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.toolbar input { flex: 1 1 240px; } .toolbar select { flex: 0 1 180px; }
.preview { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.chips { list-style: none; padding: 0; margin: 8px 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { background: #f3ecdc; border-radius: 20px; padding: 2px 12px; font-size: .85rem; }
.history { margin: 0; padding-inline-start: 20px; }
.empty { text-align: center; color: var(--muted); padding: 20px; }

/* الجداول */
.table { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid #f0e9da; vertical-align: middle; }
th { background: #f8f3e7; font-size: .82rem; color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.inactive td { color: #9a907f; }

.account { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.account .who { display: grid; margin-bottom: 8px; } .account .who small { color: var(--muted); }
.approve { margin-bottom: 4px; }
details.inline > summary { list-style: none; display: inline; }
details.inline[open] { display: block; margin: 8px 0; }
.log { list-style: none; margin: 0; padding: 0; } .log li { padding: 10px 0; border-bottom: 1px solid #f0e9da; }
.log time { display: block; font-size: .78rem; color: var(--muted); }
.profile { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: center; }
.profile .facts { grid-column: 1 / -1; }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--sun); color: var(--red-dark); font-size: 1.6rem; font-weight: 700; }

/* الموبايل: الأقسام تحت والجداول كروت */
@media (max-width: 720px) {
  .me-chip small { display: none; }
  .tabs { position: fixed; bottom: 0; inset-inline: 0; z-index: 6; justify-content: space-around; border-top: 1px solid var(--line); border-bottom: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 14px #3b2a0f10; }
  .tabs button { flex-direction: column; gap: 0; padding: 4px 8px; font-size: .72rem; }
  .main { padding-bottom: 96px; }
  .cards-on-phone thead { display: none; }
  .cards-on-phone, .cards-on-phone tbody, .cards-on-phone tr, .cards-on-phone td { display: block; width: 100%; }
  .cards-on-phone tr { padding: 10px 12px; border-bottom: 1px solid #f0e9da; }
  .cards-on-phone td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; }
  .cards-on-phone td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .82rem; }
  .cards-on-phone td:not([data-label]) { justify-content: flex-start; gap: 16px; }
  .grid { grid-template-columns: 1fr; }
}
