/* ==========================================================================
   uklu polish layer: Lucide icon sizing + calm surface/typography cleanup.
   Loaded after every inline <style> in index.html, so it is the single place
   to adjust (or revert) this pass. Visual only: no layout logic, no JS hooks.
   Phone rules stay inside (max-width: 640px) and never undo the earlier
   phone fixes (2x2 KPI grid, working-hours modal, WhatsApp templates).
   ========================================================================== */

/* ── 1. Icons: one stroke spec everywhere, consistent sizes per context ── */
svg.dp-icon {
  flex-shrink: 0;
  overflow: visible;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Navigation: 20px (desktop sidebar, phone bottom bar, phone "more" sheet) */
#app-sidebar nav svg.dp-icon,
#app-sidebar nav .nav-icon-wrap svg { width: 20px !important; height: 20px !important; }
.mnav-ico svg.dp-icon,
.msheet-ico svg.dp-icon { width: 20px !important; height: 20px !important; }

/* Header icon buttons (search, bell, theme, chair call, TV): 18px */
header button svg.dp-icon:is(.w-4, .w-5, .w-6) { width: 18px !important; height: 18px !important; }

/* Buttons and fields: 16px for small glyphs, 18px for medium ones */
:is(#app-view, #modal-root) button svg.dp-icon:is(.w-3, .w-3\.5, .w-4) { width: 16px !important; height: 16px !important; }
:is(#app-view, #modal-root) button svg.dp-icon:is(.w-5, .w-6) { width: 18px !important; height: 18px !important; }
:is(#app-view, #modal-root) .relative > svg.dp-icon.absolute:is(.w-4, .w-5) { width: 16px !important; height: 16px !important; }

/* Icon tiles in cards (KPI cards, stat bento cards, section headers): 22px */
:is(#app-view, #modal-root) :is(div, span):is(.w-9.h-9, .w-10.h-10, .w-11.h-11, .w-12.h-12)[class*="rounded"] > svg.dp-icon:not(.animate-spin) {
  width: 22px !important;
  height: 22px !important;
}
#app-view [id^="kpi-card-"] svg.dp-icon:not(.w-3):not(.w-3\.5) { width: 22px !important; height: 22px !important; }

/* Tiny inline glyphs inside pills keep their optical size and sit on the text line */
#app-view span[class*="px-"][class*="py-"] > svg.dp-icon { vertical-align: -2px; }

/* ── 2. Typography: Arabic is never letter-spaced ── */
html table th,
html:not(.dark) table th,
html.dark table th { letter-spacing: 0 !important; }
:is(.tracking-tighter, .tracking-tight, .tracking-wide, .tracking-wider, .tracking-widest):not(input):not([dir="ltr"]):not(#tv-clock-time) {
  letter-spacing: 0 !important;
}
#app-view span[class*="px-"][class*="py-"][class*="rounded"],
#modal-root span[class*="px-"][class*="py-"][class*="rounded"],
#app-view .btn-insert-var,
#app-view [class*="badge"] { letter-spacing: 0 !important; }

/* Numeric (mono) styling must not break Arabic words: Plus Jakarta Sans has no Arabic
   glyphs, so Arabic falls back to the app font (Almarai) instead of a monospace face.
   Latin digits keep Plus Jakarta Sans + tabular figures, exactly as before. */
.font-mono,
[id*="count"],
[id*="amount"],
[id*="total"],
[id*="price"],
table td.font-mono,
input[type="number"],
input[type="tel"],
input[type="date"] {
  font-family: "Plus Jakarta Sans", var(--app-font, "Almarai"), "Almarai", monospace !important;
}

/* Pills / badges: one rhythm (line height, weight) so rows of chips align */
#app-view span[class*="px-"][class*="py-"][class*="rounded-full"],
#app-view span[class*="px-"][class*="py-"][class*="rounded-md"],
#modal-root span[class*="px-"][class*="py-"][class*="rounded-full"] {
  line-height: 1.5;
  font-weight: 600;
}

/* ── 3. Toggle switches: soft iOS size, 44 x 24, every inline-styled switch ── */
[role="switch"][style*="border-radius"]:not(.ob-switch) {
  width: 44px !important;
  min-width: 44px !important;
  height: 24px !important;
  min-height: 24px !important;
  padding: 3px !important;
  box-sizing: border-box !important;
  border-radius: 999px !important;
  flex-shrink: 0;
  align-items: center !important;
  transition: background-color var(--uk-dur-base, 220ms) var(--uk-ease, ease) !important;
}
[role="switch"][style*="border-radius"]:not(.ob-switch) > span[aria-hidden="true"] {
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  margin: 0 !important;
  border-radius: 999px !important;
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.18), 0 1px 1px rgba(24, 24, 27, 0.06) !important;
  transition: transform var(--uk-dur-base, 220ms) var(--uk-ease, ease) !important;
}
/* RTL: thumb at the start (right) edge = ON */
[role="switch"][style*="border-radius"][aria-checked="true"]:not(.ob-switch) > span[aria-hidden="true"] { transform: translateX(0) !important; }
[role="switch"][style*="border-radius"][aria-checked="false"]:not(.ob-switch) > span[aria-hidden="true"] { transform: translateX(-20px) !important; }
[role="switch"][style*="border-radius"]:not(.ob-switch):focus-visible { outline: none !important; box-shadow: var(--uk-focus-ring) !important; }
html.dark [role="switch"][style*="border-radius"][aria-checked="false"]:not(.ob-switch) { background-color: #3a3e42 !important; }
/* the value read-out next to a switch ("ON"/"OFF" in mono) is redundant with the switch itself */
#settings-root span.font-mono:has(+ [role="switch"]) { display: none !important; }

/* Tailwind peer toggles (e.g. add-procedure modal): the thumb starts at right:2px, and
   translate-x-full pushed it OFF the track in RTL. Keep the RTL convention: ON = thumb at the start (right). */
#proc-modal-active + div::after { transform: translateX(-20px) !important; }
#proc-modal-active:checked + div::after { transform: translateX(0) !important; }

/* Onboarding switch: same 44 x 24 visual, tap area stays 44px tall */
.ob-switch { width: 44px !important; }
.ob-switch::before { height: 24px !important; margin-top: -12px !important; }
.ob-switch span { width: 18px !important; height: 18px !important; margin-top: -9px !important; inset-inline-start: 3px !important; }
.ob-switch[aria-checked="true"] span { inset-inline-start: 23px !important; }

/* The pill rule span[class*="rounded-full"] { display: inline-flex !important } outranked .hidden,
   so hidden loading spinners (e.g. "إضافة الإجراء") were always visible. Hidden means hidden. */
span.hidden[class*="rounded-full"] { display: none !important; }

/* ── 4. Surfaces: calm cards, one radius, hairline borders, soft shadow ── */
html:not(.dark) #app-view :is(div, section, article).bg-white.rounded-2xl.border:not([class*="shadow-lg"]):not([class*="shadow-xl"]) {
  border-color: var(--uk-border) !important;
}
html:not(.dark) #app-view :is(div, section, article).bg-white.rounded-2xl.border.shadow-sm {
  box-shadow: 0 1px 2px rgba(24, 24, 27, 0.04) !important;
}

/* Buttons: icon + label always centred with an even gap */
:is(#app-view, #modal-root) button:has(> svg.dp-icon):has(> span) { align-items: center; }

/* ── 5. Settings hub (#settings) ── */
/* section menu: equal-height cards, soft hover, no lift */
#settings-hub-menu > button {
  align-items: center;
  transition: border-color var(--uk-dur-fast, 120ms) ease, box-shadow var(--uk-dur-base, 220ms) ease, background-color var(--uk-dur-fast, 120ms) ease !important;
}
#settings-hub-menu > button:hover {
  border-color: var(--uk-border-strong) !important;
  box-shadow: 0 4px 14px rgba(24, 24, 27, 0.06) !important;
  transform: none !important;
}
#settings-hub-menu > button:focus-visible { outline: none; box-shadow: var(--uk-focus-ring) !important; }
#settings-hub-menu .hub-ico {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--uk-brand-soft) !important; color: var(--uk-brand) !important;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#settings-hub-menu .hub-chev { color: var(--uk-text-subtle); transition: transform var(--uk-dur-base, 220ms) var(--uk-ease, ease); }
#settings-hub-menu > button:hover .hub-chev { transform: translateX(-3px); color: var(--uk-brand); }
#settings-hub-menu .hub-title { font-size: 14px; font-weight: 700; color: var(--uk-text); line-height: 1.5; }
#settings-hub-menu .hub-desc { font-size: 12px; color: var(--uk-text-subtle); line-height: 1.6; }
html.dark #settings-hub-menu > button { background: var(--uk-surface) !important; border-color: var(--uk-border) !important; }
html.dark #settings-hub-menu > button:hover { border-color: var(--uk-border-strong) !important; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35) !important; }

@media (min-width: 641px) {
  #settings-root[data-hub="menu"] #settings-hub-menu { grid-auto-rows: 1fr; }
  #settings-root[data-hub="menu"] #settings-hub-menu > * { margin: 0 !important; }
  #settings-hub-menu > button { height: 100%; min-height: 96px !important; padding: 20px !important; gap: 14px !important; }
}

/* section top bar: back | title | save, one calm row */
#settings-hub-bar { background: var(--uk-surface) !important; }
#settings-hub-bar .hub-bar-row { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
#settings-hub-bar #settings-hub-title {
  flex: 1 1 0%; min-width: 0; margin: 0 !important; padding: 0 !important;
  font-size: 15px; font-weight: 700; color: var(--uk-text); line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#settings-hub-bar #settings-hub-back,
#settings-hub-bar #settings-hub-save {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 12px; font-size: 13px; font-weight: 700; white-space: nowrap; flex-shrink: 0;
}
#settings-hub-bar #settings-hub-back {
  background: transparent !important; color: var(--uk-text-muted) !important; border: 1px solid var(--uk-border) !important;
}
#settings-hub-bar #settings-hub-back:hover { background: var(--uk-surface-subtle) !important; color: var(--uk-text) !important; }
html.dark #settings-hub-bar { border-color: var(--uk-border) !important; }

@media (min-width: 641px) {
  #settings-hub-bar { box-shadow: 0 1px 2px rgba(24, 24, 27, 0.04); padding: 10px 12px !important; }
  html.dark #settings-hub-bar { box-shadow: none; }
}

/* sections inside an open group: even spacing between cards */
#settings-root:not([data-hub="menu"]) [data-hub-group] + [data-hub-group] { margin-top: 20px; }

/* ── 6. Phones (<= 640px): only additive touches ── */
@media (max-width: 640px) {
  #settings-hub-menu > button { min-height: 72px !important; padding: 14px !important; }
  #settings-hub-bar #settings-hub-back,
  #settings-hub-bar #settings-hub-save { min-height: 44px; padding: 0 12px; }
  #settings-hub-bar .hub-bar-row { gap: 8px; }
  #settings-hub-bar .hub-save-long { display: none; }
}

/* Inventory cards on phones: the quantity cell's long label + the 217px stepper did not fit one
   row, so the "+" button was clipped. Let that cell wrap and give the stepper its own full-width line. */
@media (max-width: 639px) {
  #app-view table[data-cards] td:has(> div > .btn-quick-increase) { flex-wrap: wrap; row-gap: 8px; }
  #app-view table[data-cards] td > div:has(> .btn-quick-increase) {
    display: flex !important; width: 100%; justify-content: space-between; box-sizing: border-box;
  }
}

@media (prefers-reduced-motion: reduce) {
  #settings-hub-menu .hub-chev,
  [role="switch"][style*="border-radius"]:not(.ob-switch),
  [role="switch"][style*="border-radius"]:not(.ob-switch) > span[aria-hidden="true"] { transition: none !important; }
}
