/* ===========================================================
   نظام متابعة النطاقات — Design tokens & core styles
   Palette: deep slate + Saudi-adjacent teal-green primary,
   with the red/amber/green traffic-light kept literal because
   it *is* the domain's own vocabulary (Nitaqat colors).
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800&family=IBM+Plex+Sans+Arabic:wght@400;500;600&display=swap');

:root{
  --ink:            #16202B;
  --ink-soft:       #57657A;
  --bg:             #F3F5F7;
  --surface:        #FFFFFF;
  --surface-2:      #F8FAFB;
  --line:           #E3E8ED;

  --brand:          #0E7C6B;
  --brand-dark:     #0A5F52;
  --brand-tint:     #E4F3EF;

  --red:            #C23B3B;
  --red-tint:       #FBEAEA;
  --amber:          #D98E04;
  --amber-tint:     #FBF1DE;
  --yellow-low:     #D9C24A;
  --green-mid:      #8FBF3F;
  --green-high:     #4E9A4E;
  --platinum:       #2F6FED;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(22,32,43,.06);
  --shadow-md: 0 8px 24px rgba(22,32,43,.08);
  --shadow-lg: 0 20px 48px rgba(22,32,43,.14);

  --font-display: 'Tajawal', sans-serif;
  --font-body: 'IBM Plex Sans Arabic', sans-serif;
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
body{
  direction: rtl;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  min-height:100vh;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4,.display{ font-family: var(--font-display); }
a{ color:inherit; text-decoration:none; }
button{ font-family:inherit; cursor:pointer; }
input,select,textarea{ font-family:inherit; }

::selection{ background: var(--brand-tint); }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration:.001ms !important; transition-duration:.001ms !important; }
}

/* ---------- Layout shells ---------- */
.app-shell{ min-height:100vh; display:flex; flex-direction:column; }

.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 28px; background:var(--surface); border-bottom:1px solid var(--line);
  position:sticky; top:0; z-index:20;
}
.topbar-left{ display:flex; align-items:center; gap:12px; }
.topbar-brand{ display:flex; align-items:center; gap:10px; font-weight:800; font-size:19px; }
.topbar-brand .logo-dot{
  width:12px; height:12px; border-radius:50%; background:var(--brand);
  box-shadow:0 0 0 4px var(--brand-tint);
}
.crumbs{ color:var(--ink-soft); font-size:14px; display:flex; align-items:center; gap:6px; }
.crumbs a:hover{ color:var(--brand); }

.topbar-right{ display:flex; align-items:center; gap:14px; }
.user-chip{
  display:flex; align-items:center; gap:10px; padding:6px 12px; border-radius:999px;
  background:var(--surface-2); border:1px solid var(--line); font-size:14px;
}
.avatar{
  width:30px; height:30px; border-radius:50%; background:var(--brand);
  color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px;
}
.btn-ghost-icon{
  border:1px solid var(--line); background:var(--surface); border-radius:10px;
  width:36px; height:36px; display:flex; align-items:center; justify-content:center;
  color:var(--ink-soft); transition:.15s;
}
.btn-ghost-icon:hover{ border-color:var(--red); color:var(--red); }

main.page{ flex:1; padding:28px; max-width:1280px; margin:0 auto; width:100%; }

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; gap:8px; justify-content:center;
  padding:11px 20px; border-radius:12px; font-weight:600; font-size:14.5px;
  border:1px solid transparent; transition:transform .12s ease, box-shadow .12s ease, background .15s;
}
.btn:active{ transform: scale(.97); }
.btn-primary{ background:var(--brand); color:#fff; box-shadow:0 6px 16px rgba(14,124,107,.25); }
.btn-primary:hover{ background:var(--brand-dark); }
.btn-outline{ background:var(--surface); color:var(--ink); border-color:var(--line); }
.btn-outline:hover{ border-color:var(--brand); color:var(--brand); }
.btn-danger-outline{ background:var(--surface); color:var(--red); border-color:var(--red-tint); }
.btn-danger-outline:hover{ background:var(--red-tint); }
.btn-sm{ padding:7px 14px; font-size:13px; border-radius:9px; }
.btn:disabled{ opacity:.5; cursor:not-allowed; }

/* ---------- Cards ---------- */
.card{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-lg);
  box-shadow:var(--shadow-sm); padding:22px;
}
.card-title{ font-weight:700; font-size:16px; margin:0 0 14px; display:flex; align-items:center; justify-content:space-between; }

/* ---------- Establishment grid (landing) ---------- */
.est-grid{
  display:grid; grid-template-columns:repeat(auto-fill, minmax(280px,1fr)); gap:18px; margin-top:22px;
}
.est-card{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-lg);
  padding:20px; box-shadow:var(--shadow-sm); cursor:pointer; position:relative; overflow:hidden;
  transition:transform .18s ease, box-shadow .18s ease; opacity:0; transform:translateY(10px);
  animation: rise .5s ease forwards;
}
.est-card:hover{ transform:translateY(-4px); box-shadow:var(--shadow-lg); border-color:var(--brand); }
.est-card:hover .est-arrow{ transform:translateX(-4px); }
@keyframes rise{ to{ opacity:1; transform:translateY(0); } }

.est-card-top{ display:flex; align-items:flex-start; justify-content:space-between; gap:10px; }
.est-badge{
  font-size:12px; font-weight:700; padding:5px 10px; border-radius:999px; white-space:nowrap;
}
.est-name{ font-weight:700; font-size:16.5px; margin:14px 0 4px; line-height:1.4; }
.est-cr{ color:var(--ink-soft); font-size:13px; margin-bottom:16px; }

.mini-scale{ height:6px; border-radius:999px; background:var(--line); overflow:hidden; margin-bottom:10px; position:relative; }
.mini-scale > span{
  position:absolute; inset:0; border-radius:999px; transform-origin:right center;
  transform:scaleX(0); animation: fillbar 1s .15s ease forwards;
}
@keyframes fillbar{ to{ transform:scaleX(var(--pct)); } }

.est-meta-row{ display:flex; justify-content:space-between; font-size:12.5px; color:var(--ink-soft); }
.est-arrow{ display:flex; margin-top:14px; align-items:center; gap:6px; font-size:13px; font-weight:600; color:var(--brand); transition:.15s; }

/* ---------- Stat row ---------- */
.stat-row{ display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin:20px 0; }
.stat-card{ background:var(--surface); border:1px solid var(--line); border-radius:var(--radius-md); padding:16px 18px; }
.stat-label{ font-size:12.5px; color:var(--ink-soft); margin-bottom:8px; }
.stat-value{ font-size:24px; font-weight:800; font-family:var(--font-display); }
.stat-value.count-up{ display:inline-block; }

/* ---------- Alert banner ---------- */
.alert-banner{
  display:flex; align-items:center; gap:12px; padding:16px 20px; border-radius:var(--radius-md);
  margin-bottom:20px; font-weight:600; font-size:14.5px; animation: pulse-in .4s ease;
}
.alert-banner.red{ background:var(--red-tint); color:var(--red); border:1px solid #F1C6C6; }
.alert-banner.green{ background:var(--brand-tint); color:var(--brand-dark); border:1px solid #C9E9E1; }
@keyframes pulse-in{ from{ opacity:0; transform:translateY(-6px); } to{ opacity:1; transform:translateY(0); } }

/* ---------- Nitaqat spectrum (signature element) ---------- */
.nitaqat-panel{ display:grid; grid-template-columns: 1.1fr 1.4fr; gap:24px; }
@media (max-width: 900px){ .nitaqat-panel{ grid-template-columns:1fr; } }

.gauge-wrap{ display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; padding:10px 0; }
.gauge-level-label{ font-weight:800; font-size:18px; }
.gauge-pct{ font-size:13px; color:var(--ink-soft); }

.spectrum{ position:relative; padding-top:26px; }
.spectrum-track{
  height:14px; border-radius:999px; display:flex; overflow:hidden; box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}
.spectrum-seg{ flex:1; position:relative; }
.spectrum-labels{ display:flex; margin-top:8px; }
.spectrum-labels span{ flex:1; text-align:center; font-size:11.5px; color:var(--ink-soft); }
.spectrum-marker{
  position:absolute; top:-2px; transform:translateX(50%);
  display:flex; flex-direction:column; align-items:center; transition: right 1s cubic-bezier(.2,.8,.2,1);
}
.spectrum-marker .pin{
  width:0; height:0; border-left:7px solid transparent; border-right:7px solid transparent;
  border-top:10px solid var(--ink);
}
.spectrum-marker .tag{
  background:var(--ink); color:#fff; font-size:11.5px; font-weight:700; padding:3px 8px;
  border-radius:6px; margin-bottom:4px; white-space:nowrap;
}

.next-level-box{
  margin-top:18px; background:var(--surface-2); border:1px dashed var(--line); border-radius:var(--radius-md);
  padding:14px 16px; font-size:13.5px; color:var(--ink-soft);
}
.next-level-box b{ color:var(--ink); }

/* ---------- Editable badges / toggles ---------- */
.editable-row{ display:flex; align-items:center; justify-content:space-between; padding:12px 0; border-bottom:1px solid var(--line); }
.editable-row:last-child{ border-bottom:none; }
.editable-row .label{ font-size:14px; color:var(--ink-soft); }
.editable-row .value{ font-weight:700; font-size:14.5px; display:flex; align-items:center; gap:8px; }

.pill{ font-size:12px; font-weight:700; padding:4px 10px; border-radius:999px; }
.pill.ok{ background:var(--brand-tint); color:var(--brand-dark); }
.pill.bad{ background:var(--red-tint); color:var(--red); }
.pill.warn{ background:var(--amber-tint); color:var(--amber); }
.pill.neutral{ background:var(--surface-2); color:var(--ink-soft); border:1px solid var(--line); }

.icon-btn{ border:none; background:none; color:var(--ink-soft); padding:4px; border-radius:6px; }
.icon-btn:hover{ color:var(--brand); background:var(--surface-2); }

/* ---------- Table ---------- */
.table-wrap{ overflow-x:auto; }
table.data-table{ width:100%; border-collapse:collapse; font-size:14px; }
table.data-table th{
  text-align:right; padding:12px 14px; color:var(--ink-soft); font-weight:600; font-size:13px;
  border-bottom:2px solid var(--line); white-space:nowrap;
}
table.data-table td{ padding:12px 14px; border-bottom:1px solid var(--line); white-space:nowrap; }
table.data-table tbody tr{ transition:background .12s; }
table.data-table tbody tr:hover{ background:var(--surface-2); }

.chip-status{ font-size:12px; font-weight:700; padding:4px 9px; border-radius:8px; display:inline-flex; align-items:center; gap:5px; }
.chip-status::before{ content:''; width:6px; height:6px; border-radius:50%; }
.chip-status.ok{ background:var(--brand-tint); color:var(--brand-dark); } .chip-status.ok::before{ background:var(--brand); }
.chip-status.soon{ background:#EEF2FF; color:#4C5FD5; } .chip-status.soon::before{ background:#4C5FD5; }
.chip-status.urgent{ background:var(--amber-tint); color:var(--amber); } .chip-status.urgent::before{ background:var(--amber); }
.chip-status.expired{ background:var(--red-tint); color:var(--red); } .chip-status.expired::before{ background:var(--red); }
.chip-status.na{ background:var(--surface-2); color:var(--ink-soft); } .chip-status.na::before{ background:var(--ink-soft); }

.table-toolbar{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px; flex-wrap:wrap; }
.search-input{
  padding:10px 14px; border:1px solid var(--line); border-radius:10px; min-width:220px; background:var(--surface);
}
.search-input:focus, input:focus, select:focus, textarea:focus{ outline:2px solid var(--brand-tint); border-color:var(--brand); }

/* ---------- Modal ---------- */
.modal-overlay{
  position:fixed; inset:0; background:rgba(22,32,43,.45); display:flex; align-items:center; justify-content:center;
  z-index:100; opacity:0; animation: fade-in .18s ease forwards; padding:20px;
}
@keyframes fade-in{ to{ opacity:1; } }
.modal-box{
  background:var(--surface); border-radius:var(--radius-lg); padding:26px; max-width:480px; width:100%;
  box-shadow:var(--shadow-lg); transform:translateY(14px) scale(.98); animation: modal-in .22s ease forwards;
  max-height:88vh; overflow-y:auto;
}
@keyframes modal-in{ to{ transform:translateY(0) scale(1); } }
.modal-title{ font-weight:800; font-size:18px; margin-bottom:18px; }
.form-group{ margin-bottom:14px; }
.form-group label{ display:block; font-size:13px; color:var(--ink-soft); margin-bottom:6px; }
.form-group input, .form-group select{
  width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:var(--surface-2); font-size:14px;
}
.form-group .switch-row{ display:flex; align-items:center; justify-content:space-between; background:var(--surface-2); padding:10px 12px; border-radius:10px; }
.modal-actions{ display:flex; gap:10px; margin-top:20px; }
.modal-actions .btn{ flex:1; }

.switch{ position:relative; width:44px; height:24px; }
.switch input{ opacity:0; width:0; height:0; }
.switch .track{ position:absolute; inset:0; background:var(--line); border-radius:999px; transition:.2s; }
.switch .track::after{ content:''; position:absolute; width:18px; height:18px; border-radius:50%; background:#fff; top:3px; right:3px; transition:.2s; box-shadow:0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track{ background:var(--brand); }
.switch input:checked + .track::after{ transform:translateX(-20px); }

/* ---------- Toast ---------- */
.toast-stack{ position:fixed; bottom:22px; left:50%; transform:translateX(-50%); z-index:200; display:flex; flex-direction:column; gap:8px; align-items:center; }
.toast{
  background:var(--ink); color:#fff; padding:12px 18px; border-radius:12px; font-size:14px; box-shadow:var(--shadow-lg);
  animation: toast-in .25s ease, toast-out .25s ease 2.6s forwards;
}
.toast.error{ background:var(--red); }
.toast.success{ background:var(--brand-dark); }
@keyframes toast-in{ from{ opacity:0; transform:translateY(10px); } to{ opacity:1; transform:translateY(0); } }
@keyframes toast-out{ to{ opacity:0; transform:translateY(-6px); } }

/* ---------- Loading ---------- */
.skeleton{ background:linear-gradient(90deg,var(--line) 25%,#EFF2F5 37%,var(--line) 63%); background-size:400% 100%; animation: shimmer 1.4s ease infinite; border-radius:8px; }
@keyframes shimmer{ 0%{ background-position:100% 50%; } 100%{ background-position:0 50%; } }
.spin{ display:inline-block; width:16px; height:16px; border:2px solid rgba(255,255,255,.5); border-top-color:#fff; border-radius:50%; animation: spin 0.7s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg); } }

.empty-state{ text-align:center; padding:60px 20px; color:var(--ink-soft); }
.empty-state .big-icon{ font-size:40px; margin-bottom:10px; }

/* ---------- Utility ---------- */
.flex-between{ display:flex; align-items:center; justify-content:space-between; }
.muted{ color:var(--ink-soft); }
.mt-0{ margin-top:0; } .mb-0{ margin-bottom:0; }
.gap-2{ display:flex; gap:8px; }

/* ---------- Nitaqat calculator (shared by dashboard "add establishment"
   modal and the establishment page's recalculation modal) ---------- */
.grid-2{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.occ-chip{ display:inline-block; background:var(--surface-2); border:1px solid var(--line); border-radius:8px; padding:5px 10px; font-size:12px; margin:0 0 6px 6px; }
.occ-progress-track{ background:var(--surface-2); border-radius:999px; height:8px; overflow:hidden; margin:8px 0; }
.occ-progress-fill{ background:var(--brand); height:100%; transition:width .3s ease; }
.calc-toggle-link{ font-size:12.5px; color:var(--brand); text-decoration:underline; cursor:pointer; display:inline-block; margin-top:6px; }
