/* ==========================================================================
   عيار / Wealth Meter — Admin dashboard
   Single stylesheet. No build step, no framework, no JS.
   Arabic RTL first. Data-dense operating surface.

   Locked design tokens
   -------------------
   Accent (only decorative colour in the system) : #9a5b00
   Radius scale (the ONLY three radii allowed)   : 2px / 4px / 8px
   Base palette  : neutral zinc/slate — canvas #f4f5f7, surface #ffffff,
                   hairline #e4e7eb, ink #14181d, muted #5c6570
   Danger        : #a3281f — reserved for error state only, never decoration
   ========================================================================== */

:root {
  --canvas: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;

  --ink: #14181d;
  --ink-muted: #5c6570;

  --line: #e4e7eb;
  --line-strong: #d3d8de;

  --accent: #9a5b00;
  --accent-strong: #7a4800;
  --accent-soft: #fdf3e2;
  --accent-ring: rgba(154, 91, 0, 0.38);

  --danger: #a3281f;
  --danger-soft: #fdf1f0;
  --danger-line: #f0cbc8;

  --r-0: 2px;
  --r-1: 4px;
  --r-2: 8px;

  --fs: 0.8125rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* No webfont is fetched: the dashboard must render on a locked-down host with no
   outbound font request. Noto Sans Arabic is declared first, then the Arabic-capable
   system faces that are actually present on Windows/macOS/Linux, then generic. */
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, 'Geeza Pro', 'Arabic Typesetting',
    'Droid Arabic Naskh', system-ui, -apple-system, sans-serif;
  font-size: var(--fs);
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* Every figure in the system is tabular. */
strong,
.num,
td.num,
.metric-value,
input,
table {
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 0.75rem;
  z-index: 20;
}

.skip-link:focus {
  inset-inline-start: 0.5rem;
  top: 0.5rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  padding: 0.75rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: 0.375rem 0.5rem;
  border-radius: var(--r-1);
  border-block-end: 1px solid var(--line);
  padding-block-end: 0.625rem;
}

.brand strong {
  display: block;
  font-size: 0.9375rem;
  letter-spacing: 0;
}

.brand span {
  display: block;
  color: var(--accent);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
  padding: 0.4375rem 0.5rem;
  border-radius: var(--r-1);
  font-weight: 500;
}

.sidebar nav a::before {
  content: '';
  width: 3px;
  align-self: stretch;
  border-radius: var(--r-0);
  background: transparent;
}

.sidebar nav a:hover {
  background: var(--surface-2);
}

.sidebar nav a.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar nav a.active::before {
  background: var(--accent);
}

.nav-meta {
  margin-block-start: auto;
  display: grid;
  gap: 0.5rem;
  border-block-start: 1px solid var(--line);
  padding-block-start: 0.625rem;
}

.nav-user {
  color: var(--ink-muted);
  font-size: 0.6875rem;
  word-break: break-all;
  line-height: 1.4;
}

.content {
  min-width: 0;
  padding: 0.875rem 1rem 1.5rem;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-block-end: 0.75rem;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.page-head .page-meta {
  color: var(--ink-muted);
  font-size: 0.75rem;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    height: auto;
    border-inline-end: 0;
    border-block-end: 1px solid var(--line);
  }

  .nav-meta {
    margin-block-start: 0.5rem;
  }
}

/* ---------- Surfaces ---------- */

.panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
}

.panel {
  padding: 0.625rem 0.75rem;
  margin-block-end: 0.75rem;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-block-end: 0.5rem;
}

.panel-title h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
}

.panel-title .hint {
  color: var(--ink-muted);
  font-size: 0.6875rem;
}

/* ---------- Metrics ---------- */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  overflow: hidden;
  margin-block-end: 0.75rem;
}

.metric {
  border: 0;
  border-radius: 0;
  padding: 0.5rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.metric-label {
  color: var(--ink-muted);
  font-size: 0.6875rem;
  font-weight: 500;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.2;
}

.metric-value.accent {
  color: var(--accent);
}

.metric-foot {
  color: var(--ink-muted);
  font-size: 0.6875rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 0.75rem;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-1);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78125rem;
}

caption {
  text-align: start;
  color: var(--ink-muted);
  font-size: 0.6875rem;
  padding-block-end: 0.375rem;
}

th,
td {
  text-align: start;
  padding: 0.3125rem 0.5rem;
  border-block-end: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}

thead th {
  background: var(--surface-2);
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  border-block-end: 1px solid var(--line-strong);
}

tbody tr:last-child td {
  border-block-end: 0;
}

tbody tr:hover {
  background: var(--surface-2);
}

td.num,
th.num {
  text-align: end;
}

td.mono,
.mono {
  font-family: 'Cascadia Mono', 'Consolas', ui-monospace, monospace;
  font-size: 0.75rem;
  direction: ltr;
  unicode-bidi: isolate;
}

.row-link {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

.row-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.tag {
  display: inline-block;
  padding: 0.0625rem 0.3125rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-0);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--surface-2);
}

.tag.accent {
  color: var(--accent-strong);
  border-color: var(--accent-ring);
  background: var(--accent-soft);
}

.muted {
  color: var(--ink-muted);
}

.note {
  color: var(--ink-muted);
  font-size: 0.6875rem;
  margin: 0 0 0.5rem;
}

.table-note {
  color: var(--ink-muted);
  font-size: 0.6875rem;
  margin: 0 0 0.5rem;
}

/* ---------- Pager ---------- */

.pager {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-block-start: 0.5rem;
  flex-wrap: wrap;
}

.pager-count {
  color: var(--ink-muted);
  font-size: 0.6875rem;
}

/* ---------- Forms / buttons ---------- */

.field {
  display: grid;
  gap: 0.1875rem;
  margin-block-end: 0.625rem;
}

.field label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ink-muted);
}

input[type='email'],
input[type='password'],
input[type='text'],
select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  padding: 0.375rem 0.5rem;
  min-height: 34px;
  width: 100%;
}

input::placeholder {
  color: #8a929b;
}

input:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent-ring);
  outline-offset: 0;
}

input[aria-invalid='true'] {
  border-color: var(--danger);
}

.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  min-height: 34px;
  border-radius: var(--r-1);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-sm {
  min-height: 28px;
  padding: 0.1875rem 0.5rem;
  font-size: 0.75rem;
}

.btn[aria-disabled='true'],
.btn.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.btn-block {
  width: 100%;
}

.inline-form {
  display: inline;
}

/* ---------- States ---------- */

.state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  padding: 0.875rem 1rem;
  text-align: center;
}

.state h2 {
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
}

.state p {
  margin: 0;
  color: var(--ink-muted);
}

.state.is-danger {
  border-style: solid;
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.state.is-danger p {
  color: #7a1e17;
}

.state.is-setup {
  border-style: solid;
  border-color: var(--accent-ring);
  background: var(--accent-soft);
  text-align: start;
}

.state.is-setup h2 {
  color: var(--accent-strong);
}

.state.is-empty {
  background: var(--surface);
}

/* Skeleton: painted server-side before the Firestore read resolves. */
.skeleton {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 0.625rem 0.75rem;
  margin-block-end: 0.75rem;
}

.skeleton-row {
  display: flex;
  gap: 0.625rem;
  align-items: center;
  padding-block: 0.3125rem;
}

.skeleton-bar {
  height: 10px;
  border-radius: var(--r-0);
  background: linear-gradient(90deg, #eceef1 0%, #f6f7f9 50%, #eceef1 100%);
  background-size: 200% 100%;
  animation: skeleton-sweep 1.15s ease-in-out infinite;
}

@keyframes skeleton-sweep {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-bar {
    animation: none;
  }
}

/* ---------- Alerts ---------- */

.alert {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  padding: 0.5rem 0.625rem;
  margin-block-end: 0.75rem;
  background: var(--surface);
}

.alert.is-danger {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: #7a1e17;
}

.alert strong {
  display: block;
  font-size: 0.8125rem;
}

/* ---------- Login ---------- */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-panel {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 1.125rem 1.25rem 1rem;
}

.login-panel h1 {
  margin: 0.875rem 0 0.125rem;
  font-size: 1rem;
}

.login-panel .lede {
  margin: 0 0 0.875rem;
  color: var(--ink-muted);
  font-size: 0.75rem;
}

.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 700;
  color: var(--ink);
}

.login-brand::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: var(--r-0);
  background: var(--accent);
}

/* ---------- Setup checklist ---------- */

.setup-list {
  margin: 0.625rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  overflow: hidden;
}

.setup-list li {
  background: var(--surface);
  padding: 0.4375rem 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  justify-content: space-between;
}

.setup-list code {
  font-family: 'Cascadia Mono', 'Consolas', ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--accent-strong);
  direction: ltr;
}

.setup-list .where {
  color: var(--ink-muted);
  font-size: 0.6875rem;
  text-align: end;
}

.setup-steps {
  margin: 0.625rem 0 0;
  padding-inline-start: 1.125rem;
  color: var(--ink-muted);
  font-size: 0.75rem;
  display: grid;
  gap: 0.25rem;
}

/* ---------- Footer + Hostinger partner plate ---------- */

.dashboard-footer {
  margin-block-start: 1rem;
  padding-block-start: 0.75rem;
  border-block-start: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 0.6875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Credential Plate — outer shell. opacity stays pinned at 1: the badge must be
   visible with CSS alone, so no rule anywhere may gate it on an animation. */
.hostinger-plate {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  padding: 6px;
  border-radius: 20px;
  box-shadow: inset 0 0 0 1px rgba(23, 43, 77, 0.12);
  background: rgba(23, 43, 77, 0.04);
  opacity: 1;
  text-decoration: none;
  transition: transform 700ms cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow 700ms cubic-bezier(0.32, 0.72, 0, 1);
}

/* Credential Plate — inner core. No entry animation, ever.
   Clear space, per pyranext-brand/hostinger-partner/README.md §2 (hard rule, Hostinger
   brand terms): "Clear space around the badge ≥ half the badge height on every side."
   The badge is 34px (§3), so the floor is 17px.
   The machined recess does NOT waive that rule — §3 enumerates the shell's 6px and
   the concentric core radius but grants no exemption, and §2 is the brand-authority
   section. The recess is the mechanism that PROVIDES the clear space:
     core padding 11px + shell padding 6px (+ the shell's 1px ring) = 18px.
   The 17px core gap does the same job on the inline-start side, where the copy block
   sits, so no part of the lockup crowds the badge. */
.hostinger-core {
  display: inline-flex;
  align-items: center;
  gap: 1.0625rem;
  padding: 0.6875rem;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86), 0 1px 2px rgba(23, 43, 77, 0.06);
}

.hostinger-plate:hover {
  transform: translateY(-2px);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}

.hostinger-plate:active {
  transform: scale(0.985);
  transition-duration: 120ms;
}

/* The artwork is never stretched, recoloured or mirrored (logical props only, and
   no transform on the img itself). width: auto, never a fixed width. */
.hostinger-plate img {
  display: block;
  height: 34px;
  min-height: 28px;
  width: auto;
}

/* The print raster is screen-hidden; only @media print reveals it. */
.hostinger-badge-print {
  display: none;
}

.hostinger-copy {
  display: grid;
  gap: 0.0625rem;
  text-align: start;
}

.hostinger-eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-muted);
}

.hostinger-substance {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink);
}

@media print {
  /* Drop the ring, blur and tint; keep the badge and the substance line. */
  .hostinger-plate {
    box-shadow: none;
    background: none;
    padding: 0;
  }

  .hostinger-core {
    box-shadow: none;
    padding: 0;
  }

  .hostinger-badge {
    display: none;
  }

  .hostinger-badge-print {
    display: block;
    width: 22mm;
    height: auto;
    min-height: 8mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
/* ---------- Custom ad manager ---------- */

.alert.is-success {
  border-color: #b9dfc4;
  background: #eaf6ee;
  color: #1c5a30;
}

input[type='url'],
input[type='file'] {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  padding: 0.375rem 0.5rem;
  min-height: 34px;
  width: 100%;
}

input[type='url']:focus-visible,
input[type='file']:focus-visible {
  border-color: var(--accent);
  outline: 2px solid var(--accent-ring);
  outline-offset: 0;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink);
}

.ad-preview {
  display: block;
  max-width: min(100%, 360px);
  max-height: 240px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  margin-block-end: 0.375rem;
}
