/* Layer 3 of 5 — reusable components. No page-specific selectors here. */

/* ---------- Icons ---------- */
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
:dir(rtl) .icon-flip { transform: scaleX(-1); }

/* ---------- Brand mark (V9.0 refined: transparent, single-weight line art, theme-coloured) ---------- */
.brand-mark { width: 32px; height: 32px; flex: none; color: var(--brand-mark); overflow: visible; }
.brand-mark.is-lg { width: 64px; height: 64px; }
.brand-mark.is-xl { width: 88px; height: 88px; }
.brand-mark.is-retired { color: var(--text-3); }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface-hover);
  --btn-fg: var(--text);
  --btn-border: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--control-h); padding: 0 var(--sp-4);
  border-radius: var(--r-sm); border: 1px solid var(--btn-border);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--fs-base); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast), transform var(--dur-instant);
  user-select: none;
}
.btn:hover:not(:disabled) { --btn-bg: var(--surface-active); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: var(--text-on-accent); font-weight: var(--fw-semibold); }
.btn-primary:hover:not(:disabled) { --btn-bg: var(--accent-hover); }
.btn-primary:active:not(:disabled) { --btn-bg: var(--accent-pressed); }
.btn-outline { --btn-bg: transparent; --btn-border: var(--border-strong); }
.btn-outline:hover:not(:disabled) { --btn-bg: var(--surface-hover); }
.btn-ghost { --btn-bg: transparent; }
.btn-ghost:hover:not(:disabled) { --btn-bg: var(--surface-hover); }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); }
.btn-danger:hover:not(:disabled) { --btn-bg: color-mix(in srgb, var(--danger) 20%, transparent); }
.btn-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn-lg { min-height: 44px; padding: 0 var(--sp-6); font-size: var(--fs-md); border-radius: var(--r-md); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--control-h); height: var(--control-h);
  border-radius: var(--r-sm); color: var(--text-2);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast);
}
.icon-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.icon-btn:active:not(:disabled) { background: var(--surface-active); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--surface-active); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; }
.icon-btn.is-sm { width: 30px; height: 30px; border-radius: var(--r-xs); }
@media (pointer: coarse) {
  .icon-btn { width: var(--tap); height: var(--tap); }
  .icon-btn.is-sm { width: 38px; height: 38px; }
  .btn { min-height: 42px; }
}

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  animation: spin 0.8s linear infinite; flex: none;
}

/* ---------- Form fields ---------- */
.field { display: grid; gap: var(--sp-2); }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.field-hint { font-size: var(--fs-xs); color: var(--text-3); line-height: var(--lh-snug); }
.field-error { font-size: var(--fs-sm); color: var(--danger); }
.input, .textarea, .select {
  width: 100%; min-height: 42px; padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm); border: 1px solid var(--border-control);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 96px; resize: vertical; line-height: var(--lh-snug); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-3); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
.select { appearance: none; padding-inline-end: var(--sp-8);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: left 16px center, left 11px center; background-size: 5px 5px; background-repeat: no-repeat; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-inline-end: 46px; }
.input-group .icon-btn { position: absolute; inset-inline-end: 4px; }

/* Switch — native checkbox with role="switch" for correct semantics. */
.switch {
  appearance: none; position: relative; flex: none; cursor: pointer;
  width: 38px; height: 22px; border-radius: var(--r-pill);
  background: var(--surface-active); border: 1px solid var(--border-strong);
  transition: background-color var(--dur-base) var(--ease-out), border-color var(--dur-base);
}
.switch::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--text-2);
  transition: transform var(--dur-base) var(--ease-spring), background-color var(--dur-base);
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { background: var(--text-on-accent); transform: translateX(-16px); }
:dir(ltr) .switch:checked::after { transform: translateX(16px); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; }
.switch:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* Segmented control (radio group) */
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-sm); background: var(--surface-hover); border: 1px solid var(--border-subtle); flex-wrap: wrap; }
.segmented button {
  min-height: 30px; padding: 0 var(--sp-3); border-radius: var(--r-xs);
  font-size: var(--fs-sm); color: var(--text-2); display: inline-flex; align-items: center; gap: var(--sp-2);
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-1); font-weight: var(--fw-medium); }
:root[data-theme="dark"] .segmented button[aria-checked="true"] { background: var(--surface-active); }

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  min-height: 28px; padding: 0 var(--sp-2) 0 var(--sp-3);
  border-radius: var(--r-pill); border: 1px solid var(--border);
  background: var(--surface-hover); color: var(--text-2);
  font-size: var(--fs-sm); line-height: 1;
}
.chip .icon { width: 15px; height: 15px; }
.chip.is-accent { background: var(--accent-softer); border-color: var(--accent-border); color: var(--accent-text); }
.chip button { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: inherit; }
.chip button:hover { background: var(--surface-active); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: var(--fw-semibold); letter-spacing: 0.01em;
  background: var(--surface-active); color: var(--text-2); white-space: nowrap;
}
.badge.is-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.is-warning { background: var(--warning-soft); color: var(--warning); }
.badge.is-danger { background: var(--danger-soft); color: var(--danger); }
.badge.is-muted { background: transparent; border: 1px solid var(--border); color: var(--text-3); }

/* ---------- Popover / menu ---------- */
.popover {
  position: fixed; z-index: var(--z-popover);
  min-width: 220px; max-width: min(460px, calc(100vw - 16px));
  max-height: min(70vh, 560px); overflow: auto; overscroll-behavior: contain;
  padding: var(--sp-1);
  border-radius: var(--r-md);
  background: var(--surface-3); color: var(--text);
  box-shadow: var(--shadow-3);
  animation: pop-in var(--dur-base) var(--ease-out);
  transform-origin: var(--origin, bottom center);
}
.popover.is-closing { animation: fade-in var(--dur-fast) reverse forwards; }
.menu-label { padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: var(--fs-xs); color: var(--text-3); font-weight: var(--fw-medium); }
.menu-sep { height: 1px; margin: var(--sp-1) var(--sp-2); background: var(--border-subtle); }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  min-height: 38px; padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm); color: var(--text); font-size: var(--fs-base);
  text-decoration: none; text-align: start;
}
.menu-item .icon { color: var(--text-2); }
.menu-item:hover, .menu-item[data-active="true"] { background: var(--surface-hover); }
.menu-item:focus-visible { outline-offset: -2px; }
.menu-item[aria-disabled="true"], .menu-item:disabled { opacity: 0.5; }
.menu-item.is-danger, .menu-item.is-danger .icon { color: var(--danger); }
.menu-item .menu-meta { margin-inline-start: auto; color: var(--text-3); font-size: var(--fs-xs); }
.menu-item-text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.menu-item-text small { color: var(--text-3); font-size: var(--fs-xs); line-height: var(--lh-snug); }
@media (pointer: coarse) { .menu-item { min-height: var(--tap); } }

/* ---------- Dialog (centered) ---------- */
.layer {
  position: fixed; inset: 0; z-index: var(--z-dialog);
  display: grid; place-items: center; padding: var(--sp-4);
  padding-bottom: max(var(--sp-4), var(--safe-bottom));
}
.layer-scrim { position: absolute; inset: 0; background: var(--overlay); animation: fade-in var(--dur-base) var(--ease-out); }
.dialog {
  position: relative; width: min(100%, 460px); max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  border-radius: var(--r-lg); background: var(--surface-2); color: var(--text);
  box-shadow: var(--shadow-3);
  animation: pop-in var(--dur-base) var(--ease-out);
}
.dialog.is-wide { width: min(100%, 720px); }
.dialog-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-2); }
.dialog-head h2 { font-size: var(--fs-lg); flex: 1; }
.dialog-body { padding: var(--sp-2) var(--sp-5) var(--sp-4); overflow: auto; color: var(--text-2); line-height: var(--lh-snug); display: grid; gap: var(--sp-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5) var(--sp-5); flex-wrap: wrap; }
.layer.is-closing .layer-scrim, .layer.is-closing .dialog, .layer.is-closing .sheet { animation-direction: reverse; animation-fill-mode: forwards; animation-duration: var(--dur-fast); }

/* ---------- Bottom sheet (mobile menus) ---------- */
.layer.is-sheet { place-items: end stretch; padding: 0; }
.sheet {
  position: relative; width: 100%; max-height: min(88vh, 88dvh);
  display: flex; flex-direction: column;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface-2); box-shadow: var(--shadow-3);
  padding-bottom: var(--safe-bottom);
  animation: sheet-in var(--dur-panel) var(--ease-out);
  touch-action: pan-y;
}
.sheet-grip { display: grid; place-items: center; height: 26px; cursor: grab; touch-action: none; flex: none; }
.sheet-grip::before { content: ""; width: 38px; height: 4px; border-radius: 4px; background: var(--border-strong); }
.sheet-head { display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4) var(--sp-2); }
.sheet-head h2 { flex: 1; font-size: var(--fs-md); }
.sheet-body { overflow: auto; overscroll-behavior: contain; padding: 0 var(--sp-2) var(--sp-4); }
.sheet.is-dragging { transition: none; animation: none; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: var(--z-toast); inset-inline: 0; bottom: calc(var(--sp-6) + var(--safe-bottom));
  display: grid; justify-items: center; gap: var(--sp-2); pointer-events: none; padding: 0 var(--sp-4);
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3); max-width: min(520px, 100%);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-3);
  font-size: var(--fs-base); line-height: var(--lh-snug); pointer-events: auto;
  animation: rise-in var(--dur-base) var(--ease-out);
}
.toast .icon { width: 18px; height: 18px; }
.toast[data-type="error"] { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast[data-type="error"] { color: #1c0b08; }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--dur-base), transform var(--dur-base); }
.toast button { color: inherit; font-weight: var(--fw-semibold); text-decoration: underline; }

/* ---------- Cards, lists, empty & loading states ---------- */
.card { border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border-subtle); }
.empty-state {
  display: grid; justify-items: center; text-align: center; gap: var(--sp-3);
  padding: var(--sp-12) var(--sp-6); color: var(--text-2);
}
.empty-state .empty-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: var(--r-md); background: var(--surface-hover); color: var(--text-3); }
.empty-state h3 { font-size: var(--fs-md); color: var(--text); }
.empty-state p { max-width: 36ch; font-size: var(--fs-sm); line-height: var(--lh-snug); }
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-active) 50%, var(--surface-hover) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.notice {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--surface-hover); border: 1px solid var(--border-subtle);
  color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh-snug);
}
.notice.is-warning { background: var(--warning-soft); color: var(--text); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.notice.is-danger { background: var(--danger-soft); color: var(--text); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.notice .icon { flex: none; margin-top: 1px; }
.notice.is-warning .icon { color: var(--warning); }
.notice.is-danger .icon { color: var(--danger); }

/* ---------- Model glyph tile ---------- */
.model-glyph {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: var(--r-sm);
  background: var(--accent-softer); color: var(--accent-text);
  border: 1px solid var(--accent-border);
}
.model-glyph .icon { width: 18px; height: 18px; stroke-width: 1.6; }
.model-glyph.is-retired { background: var(--surface-hover); color: var(--text-3); border-color: var(--border); }
.model-glyph.is-sm { width: 22px; height: 22px; border-radius: var(--r-xs); }
.model-glyph.is-sm .icon { width: 14px; height: 14px; }

/* ---------- Energy indicator (shared by Fikr Control and its trigger) ---------- */
.energy { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.energy i { display: block; width: 3px; border-radius: 2px; background: var(--border-strong); transition: background-color var(--dur-base), height var(--dur-base) var(--ease-out); }
.energy i:nth-child(1) { height: 30%; } .energy i:nth-child(2) { height: 44%; } .energy i:nth-child(3) { height: 58%; }
.energy i:nth-child(4) { height: 72%; } .energy i:nth-child(5) { height: 86%; } .energy i:nth-child(6) { height: 100%; }
.energy i.is-on { background: linear-gradient(to top, var(--energy-1), var(--energy-2)); }
.energy.is-auto i { background: var(--accent-border); animation: energy-breathe 2.4s var(--ease-in-out) infinite; }
.energy.is-auto i:nth-child(2) { animation-delay: 0.12s; } .energy.is-auto i:nth-child(3) { animation-delay: 0.24s; }
.energy.is-auto i:nth-child(4) { animation-delay: 0.36s; } .energy.is-auto i:nth-child(5) { animation-delay: 0.48s; } .energy.is-auto i:nth-child(6) { animation-delay: 0.6s; }
@keyframes energy-breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border-subtle); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; min-height: 40px; padding: 0 var(--sp-3);
  color: var(--text-2); font-size: var(--fs-base); white-space: nowrap;
  display: inline-flex; align-items: center; gap: var(--sp-2);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); font-weight: var(--fw-medium); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: var(--sp-2); bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
