/* Ijarat Admin
   All colours are tokens – swap the values in :root to apply the brand theme. */
:root {
  --color-primary: #0A5BD8;
  --color-primary-hover: #084BB5;
  --color-on-primary: #ffffff;

  --color-bg: #EEF4FD;
  --color-surface: #ffffff;
  --color-surface-2: #EAF2FE;
  --color-border: #D6E2F3;
  --color-text: #0F1E3D;
  --color-text-muted: #66748A;

  --color-success: #1a7f45;  --color-success-bg: #e5f5ec;
  --color-warning: #8a5a00;  --color-warning-bg: #fff4d6;
  --color-danger:  #c42b2b;  --color-danger-bg:  #fde8e8;
  --color-neutral: #4a5565;  --color-neutral-bg: #eceff3;

  --sidebar-bg: #0B1B3A;
  --sidebar-text: #C3D2EA;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, .1);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 20px rgba(10, 60, 140, .08);
  --font: "Plus Jakarta Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --focus: 0 0 0 3px color-mix(in srgb, var(--color-primary) 35%, transparent);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--color-text); background: var(--color-bg); }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
hr { border: 0; border-top: 1px solid var(--color-border); margin: 1.25rem 0; }
code { font-family: var(--mono); background: var(--color-surface-2); padding: .1rem .35rem; border-radius: 4px; }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--sidebar-bg); color: var(--sidebar-text); padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .5rem 1rem; }
.brand:hover { text-decoration: none; }
.brand small { font-weight: 400; opacity: .7; }
.brand-center { justify-content: center; color: var(--color-text); padding-bottom: 1.25rem; }
.sidebar nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .7rem; min-height: 44px; border-radius: var(--radius-sm); color: var(--sidebar-text); }
.sidebar nav a:hover { background: var(--sidebar-active-bg); text-decoration: none; }
.sidebar nav a.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 600; }
.nav-section { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; opacity: .6; padding: 1.25rem .7rem .4rem; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: var(--color-surface); border-bottom: 1px solid var(--color-border); position: sticky; top: 0; z-index: 5; }
.page-title { font-size: 1.2rem; margin: 0; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: .5rem; }
.topbar-user form { margin: 0; }
.menu-toggle { display: none; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

/* ---------- Building blocks ---------- */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.stack > * + * { margin-top: 1rem; }
.mt { margin-top: 1rem; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
.grid-2 > .card, .grid-2 > .stack > .card { margin-bottom: 0; }
.grid-2 + .card { margin-top: 1.25rem; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.muted { color: var(--color-text-muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.center { text-align: center; }
.num { text-align: end; font-variant-numeric: tabular-nums; }
.empty { color: var(--color-text-muted); text-align: center; padding: 2rem 1rem; margin: 0; }
.text-danger { color: var(--color-danger) !important; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; }
.tile { display: flex; flex-direction: column; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--color-text); box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--color-primary); text-decoration: none; }
.tile-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--color-text-muted); font-size: .9rem; }
.tile-attention { border-inline-start: 4px solid var(--color-warning); }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-success { color: var(--color-success); background: var(--color-success-bg); }
.badge-warning { color: var(--color-warning); background: var(--color-warning-bg); }
.badge-danger  { color: var(--color-danger);  background: var(--color-danger-bg); }
.badge-neutral { color: var(--color-neutral); background: var(--color-neutral-bg); }

.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { color: var(--color-success); background: var(--color-success-bg); }
.alert-warning { color: var(--color-warning); background: var(--color-warning-bg); }
.alert-error   { color: var(--color-danger);  background: var(--color-danger-bg); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .65rem; text-align: start; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--color-surface-2); }
td.actions { white-space: nowrap; }
tr.selected { background: var(--color-surface-2); }
.grid-2-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
td.actions form { display: inline; }
td input:not([type=checkbox]), td select { min-width: 8rem; }

details dt, .details dt { color: var(--color-text-muted); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0; }
.details dd { margin: 0; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); background: var(--color-surface-2); }
.gallery img.main { grid-column: span 2; grid-row: span 2; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border); }
.tabs a { padding: .6rem 1rem; color: var(--color-text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--color-primary); border-color: var(--color-primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--color-text); }

.pager { display: flex; align-items: center; gap: .5rem; justify-content: flex-end; padding-top: 1rem; }
.pager .muted { margin-inline-end: auto; }
.pager .pages { display: flex; flex-wrap: wrap; gap: .3rem; }
.pager .page { min-width: 36px; min-height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; text-decoration: none; font-weight: 600; }
.pager a.page:hover { background: var(--color-surface-muted, #EEF3FB); }
.pager .page.current { background: var(--color-primary); color: #fff; }
.pager .gap { padding: 0 .2rem; color: var(--color-text-muted); align-self: center; }
.filters .actions { display: flex; gap: .5rem; }
.filters .field-sm { min-width: 140px !important; }
.prompt { text-align: center; padding: 2.5rem 1rem; color: var(--color-text-muted); }
.prompt strong { display: block; color: var(--color-text); font-size: 1.05rem; margin-bottom: .25rem; }

/* ---------- Message thread (admin view) ---------- */
.thread { display: flex; flex-direction: column; gap: .6rem; }
.msg { max-width: 85%; padding: .6rem .8rem; border-radius: var(--radius); background: var(--color-surface-2); }
.msg-owner { align-self: flex-end; background: #e4eefc; }
.msg-deleted { border: 1px dashed var(--color-danger); background: var(--color-danger-bg); }
.msg-meta { font-size: .8rem; color: var(--color-text-muted); display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-bottom: .2rem; }
.msg-edits { margin-top: .4rem; font-size: .85rem; }
.msg-edits summary { cursor: pointer; color: var(--color-primary); }
.msg:target { outline: 2px solid var(--color-warning); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label, .field legend { font-weight: 600; font-size: .9rem; }
.help { margin: 0; font-size: .85rem; color: var(--color-text-muted); }
input, select, textarea { font: inherit; color: inherit; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: .55rem .7rem; min-height: 40px; width: 100%; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--color-primary); }
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; box-shadow: var(--focus); }
.input-sm { max-width: 10rem; }
td .input-xs, .input-xs { width: 5rem; min-width: 0 !important; }
td .input-coord { width: 6.5rem; min-width: 0 !important; }
fieldset { border: 0; padding: 0; margin: 0; }
.checks label { display: flex; align-items: center; gap: .5rem; font-weight: 400; min-height: 32px; }
.field-switch label { display: flex; align-items: center; gap: .6rem; font-weight: 600; cursor: pointer; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 180px; }
.inline-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.inline-form .field { flex: 1 1 180px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; padding: .55rem 1rem; min-height: 40px; border-radius: 999px; border: 1px solid transparent; cursor: pointer; transition: background-color .15s, border-color .15s; text-decoration: none !important; white-space: nowrap; }
.btn-sm { padding: .3rem .7rem; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-surface-2); }
.btn-ghost { background: transparent; color: var(--color-text); }
.btn-ghost:hover { background: var(--color-surface-2); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }

/* ---------- Auth ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 2rem; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .menu-toggle { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s ease-out; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .topbar { padding: .6rem 1rem; }
  .topbar-user .muted { display: none; }
  .content { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* RTL ready for the Arabic version */
[dir=rtl] .sidebar { inset: 0 0 0 auto; }
@media (max-width: 800px) { [dir=rtl] .sidebar { transform: translateX(100%); } }

/* ---------- Dashboard charts ---------- */
.grid-halves { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-halves > .card { margin-bottom: 0; }
.chart { margin: .5rem 0 0; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--color-border); stroke-width: 1; }
.chart .axis { fill: var(--color-text-muted); font-size: 11px; }
.chart .bar { fill: var(--color-primary); }
.chart .hit { fill: transparent; }
.chart .col:hover .bar { fill: var(--color-primary-hover); }
.chart .col:hover .hit { fill: var(--color-surface-2); }
.chart-table { margin-top: .5rem; font-size: .85rem; }
.chart-table summary { cursor: pointer; color: var(--color-text-muted); }
.chart-table table { margin-top: .5rem; }
.breakdown { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.breakdown li { display: grid; grid-template-columns: minmax(80px, 9rem) 1fr 3.5rem; align-items: center; gap: .6rem; }
.bd-label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-track { height: 10px; background: var(--color-surface-2); border-radius: 999px; overflow: hidden; }
.bd-bar { display: block; height: 100%; background: var(--color-primary); border-radius: 999px; }
.bd-value { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }
