/* سِجِل — نظام التصميم.
   عربي أولاً، من اليمين لليسار، ومصمّم للجوال قبل الشاشة الكبيرة.
   لوحة الألوان: حبر أزرق غامق + ذهب كويتي هادئ، وألوان حالة واضحة
   تنقرأ بلمحة عين تحت شمس الظهر. */

:root {
  --ink: #0b111c;
  --ink-2: #121a2a;
  --surface: #161f31;
  --surface-2: #1c2740;
  --line: #24314c;
  --text: #eef3fb;
  --muted: #93a2bd;
  --gold: #e5bb6a;
  --gold-soft: rgba(229, 187, 106, 0.14);
  --red: #f2615c;
  --orange: #f59f4b;
  --amber: #f2cd5c;
  --green: #4cc38a;
  --blue: #5aa9e6;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --nav-height: 68px;
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--text);
  font-family: "SF Arabic", "Geeza Pro", "Noto Kufi Arabic", "Dubai", "Tahoma", system-ui, -apple-system, sans-serif;
  direction: rtl;
  min-height: 100%;
  overscroll-behavior-y: none;
}

body {
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
  background-image:
    radial-gradient(1200px 500px at 100% -10%, rgba(229, 187, 106, 0.10), transparent 60%),
    radial-gradient(900px 400px at 0% 0%, rgba(90, 169, 230, 0.08), transparent 55%);
  background-attachment: fixed;
}

a { color: var(--gold); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* ————— الهيكل ————— */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  background: rgba(11, 17, 28, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 800;
}

.topbar .brand .mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--gold), #b8863a);
  color: #21160a;
  font-size: 1.1rem;
  box-shadow: 0 6px 18px rgba(229, 187, 106, 0.25);
}

.topbar .spacer { flex: 1; }

.icon-button {
  position: relative;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.05rem;
}
.icon-button:active { transform: scale(0.96); }
.icon-button .badge {
  position: absolute; top: -6px; inset-inline-start: -6px;
  min-width: 20px; height: 20px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--red);
  color: #fff; font-size: 0.7rem; font-weight: 700;
}

main { padding: 16px 16px 24px; max-width: 980px; margin: 0 auto; }

.view { display: none; animation: rise 0.24s ease; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-title {
  display: flex; align-items: center; gap: 8px;
  margin: 22px 2px 12px;
  font-size: 1rem; color: var(--muted); font-weight: 700;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ————— البطاقات ————— */

.card {
  background: linear-gradient(180deg, var(--surface), var(--ink-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.hero {
  background: linear-gradient(150deg, rgba(229, 187, 106, 0.16), rgba(22, 31, 49, 0.9) 55%);
  border: 1px solid rgba(229, 187, 106, 0.24);
  border-radius: 22px;
  padding: 20px;
  margin-bottom: 18px;
}
.hero .greeting { font-size: 1.35rem; font-weight: 800; }
.hero .date { color: var(--muted); margin-top: 6px; font-size: 0.9rem; }
.hero .headline { margin-top: 14px; font-size: 1rem; line-height: 1.7; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
.stat {
  background: rgba(11, 17, 28, 0.45);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
}
.stat .value { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.stat .label { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.stat.expired .value { color: var(--red); }
.stat.critical .value { color: var(--orange); }
.stat.due .value { color: var(--amber); }
.stat.valid .value { color: var(--green); }

/* ————— بطاقة وثيقة ————— */

.doc {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
  position: relative;
  overflow: hidden;
}
.doc:active { transform: scale(0.99); }
.doc::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px;
  background: var(--line);
}
.doc.state-expired::before { background: var(--red); }
.doc.state-critical::before { background: var(--orange); }
.doc.state-due::before { background: var(--amber); }
.doc.state-valid::before { background: var(--green); }
.doc.state-archived { opacity: 0.55; }

.doc .glyph {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--surface-2);
  font-size: 1.3rem;
}
.doc .body { flex: 1; min-width: 0; }
.doc .title { font-weight: 700; font-size: 1rem; }
.doc .meta { color: var(--muted); font-size: 0.82rem; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.doc .meta span { white-space: nowrap; }
.doc .meta span + span::before { content: "•"; margin-inline-end: 6px; color: var(--line); }
.doc .tail { text-align: center; flex: none; min-width: 74px; }
.doc .tail .days { font-weight: 800; font-size: 0.95rem; }
.doc .tail .chip { font-size: 0.68rem; margin-top: 4px; }

.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid var(--line);
  background: rgba(11, 17, 28, 0.5);
  color: var(--muted);
}
.chip.expired { color: var(--red); border-color: rgba(242, 97, 92, 0.45); background: rgba(242, 97, 92, 0.12); }
.chip.critical { color: var(--orange); border-color: rgba(245, 159, 75, 0.45); background: rgba(245, 159, 75, 0.12); }
.chip.due { color: var(--amber); border-color: rgba(242, 205, 92, 0.4); background: rgba(242, 205, 92, 0.1); }
.chip.valid { color: var(--green); border-color: rgba(76, 195, 138, 0.4); background: rgba(76, 195, 138, 0.1); }
.chip.gold { color: var(--gold); border-color: rgba(229, 187, 106, 0.4); background: var(--gold-soft); }

/* ————— الأدوات ————— */

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
}
.search input { flex: 1; background: none; border: none; outline: none; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filter {
  white-space: nowrap; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 0.82rem; cursor: pointer;
}
.filter.active { background: var(--gold-soft); border-color: rgba(229, 187, 106, 0.5); color: var(--gold); font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 16px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(140deg, var(--gold), #c99a44); color: #201607; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(242, 97, 92, 0.4); }
.btn.small { padding: 7px 11px; font-size: 0.82rem; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.fab {
  position: fixed;
  inset-inline-end: 18px;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 18px);
  width: 58px; height: 58px; border-radius: 20px;
  background: linear-gradient(140deg, var(--gold), #c99a44);
  color: #201607; border: none; font-size: 1.7rem; font-weight: 300;
  box-shadow: 0 14px 30px rgba(229, 187, 106, 0.32);
  cursor: pointer; z-index: 25;
}

/* ————— التنقل السفلي ————— */

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(11, 17, 28, 0.9);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  background: none; border: none; cursor: pointer;
  padding: 10px 4px 12px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 0.68rem;
}
.tabbar button .ico { font-size: 1.2rem; }
.tabbar button.active { color: var(--gold); }

/* ————— النماذج ————— */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 13px;
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 13px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: rgba(229, 187, 106, 0.55); }
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { font-size: 0.75rem; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.switch:last-child { border-bottom: none; }
.switch .text { flex: 1; }
.switch .text b { display: block; font-size: 0.95rem; }
.switch .text small { color: var(--muted); font-size: 0.78rem; line-height: 1.6; display: block; margin-top: 3px; }
.toggle {
  width: 50px; height: 30px; border-radius: 999px; flex: none;
  border: 1px solid var(--line); background: var(--ink-2);
  position: relative; cursor: pointer; transition: background 0.16s ease;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; inset-inline-end: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--muted); transition: transform 0.16s ease, background 0.16s ease;
}
.toggle.on { background: rgba(76, 195, 138, 0.22); border-color: rgba(76, 195, 138, 0.5); }
.toggle.on::after { background: var(--green); transform: translateX(-20px); }

/* ————— النوافذ ————— */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(4px);
  display: none;
}
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 41;
  max-height: 92vh; overflow-y: auto;
  background: var(--ink-2);
  border-radius: 26px 26px 0 0;
  border-top: 1px solid var(--line);
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: none; }
.sheet .handle { width: 44px; height: 4px; border-radius: 999px; background: var(--line); margin: 8px auto 14px; }
.sheet h2 { font-size: 1.15rem; margin-bottom: 4px; }
.sheet .subtitle { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(var(--nav-height) + 84px); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 16px; box-shadow: var(--shadow);
  transform: translateY(24px); opacity: 0; pointer-events: none;
  transition: all 0.2s ease; text-align: center; font-size: 0.9rem;
}
.toast.show { transform: none; opacity: 1; }
.toast.error { border-color: rgba(242, 97, 92, 0.5); color: #ffd7d5; }
.toast.success { border-color: rgba(76, 195, 138, 0.5); }

/* ————— تفاصيل الوثيقة ————— */

.detail-head { text-align: center; padding: 6px 0 16px; }
.detail-head .glyph { font-size: 2.6rem; }
.detail-head h2 { margin-top: 8px; }
.detail-head .sub { color: var(--muted); font-size: 0.88rem; margin-top: 6px; }
.detail-head .ring { margin: 14px auto 0; display: inline-flex; }

.rows { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.row:last-child { border-bottom: none; }
.row .k { color: var(--muted); font-size: 0.85rem; }
.row .v { font-weight: 600; text-align: end; font-size: 0.9rem; }

.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 16px 0; }
.impact {
  background: rgba(242, 97, 92, 0.1);
  border: 1px solid rgba(242, 97, 92, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 0.86rem; line-height: 1.7;
}

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.gallery a {
  display: block; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; text-align: center; font-size: 0.72rem; color: var(--muted); padding: 6px;
}
.gallery img { width: 100%; height: 100%; object-fit: cover; }

.timeline-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline-item .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); margin-top: 6px; flex: none; }

/* ————— الرسم البياني ————— */

.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; margin-top: 14px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.bars .bar .fill { width: 100%; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, var(--gold), rgba(229, 187, 106, 0.25)); min-height: 3px; }
.bars .bar .tag { font-size: 0.62rem; color: var(--muted); white-space: nowrap; }

.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty .big { font-size: 2.6rem; }
.empty p { margin: 10px 0 0; line-height: 1.8; }

.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; direction: ltr; unicode-bidi: embed; font-size: 0.78rem; word-break: break-all; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.copybox .mono { flex: 1; }

.tool-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.tool-row:last-child { border-bottom: none; }
.tool-row .info { flex: 1; min-width: 0; }
.tool-row .info b { font-size: 0.9rem; }
.tool-row .info small { display: block; color: var(--muted); font-size: 0.76rem; margin-top: 3px; line-height: 1.55; }
.tool-row .name { font-size: 0.68rem; color: var(--gold); direction: ltr; text-align: right; }

.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.type-card {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 11px 8px; text-align: center; cursor: pointer; font-size: 0.78rem;
}
.type-card.active { border-color: var(--gold); background: var(--gold-soft); }
.type-card .ico { font-size: 1.35rem; display: block; margin-bottom: 5px; }

/* ————— الدخول ————— */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .mark {
  width: 62px; height: 62px; border-radius: 20px; margin: 0 auto 16px;
  display: grid; place-items: center; font-size: 1.9rem;
  background: linear-gradient(140deg, var(--gold), #b8863a); color: #21160a;
  box-shadow: 0 14px 34px rgba(229, 187, 106, 0.3);
}
.login-card h1 { text-align: center; font-size: 1.5rem; }
.login-card .tag { text-align: center; color: var(--muted); margin: 8px 0 22px; font-size: 0.88rem; line-height: 1.7; }

@media (min-width: 760px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .actions { grid-template-columns: repeat(4, 1fr); }
  .sheet { inset-inline: 50%; transform: translate(50%, 100%); max-width: 620px; border-radius: 26px; bottom: 24px; }
  .sheet.open { transform: translate(50%, 0); }
}
