/*
 * molecules.css: menu · tooltip · tabs (underlined) · segmented switch ·
 * pill toggles · drawer · dialog · toast · table · card · empty state ·
 * list row · note · section · form row. Behaviour lives in js/ui.js.
 */

/* ---------- dropdown menu / listbox / popover ---------- */
.menu {
  position: fixed;
  z-index: 80;
  min-width: 168px;
  max-height: min(420px, calc(100vh - 16px));
  overflow-y: auto;
  padding: 6px;
  border-radius: var(--r-lg);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: 0 0 0 1px var(--menu-ring), 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  font-size: 14px;
  line-height: 20px;
  animation: menu-in 0.1s ease-out;
}
/* the quieter menu used for field pickers (hairline edge, soft lift) */
.menu--soft {
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 0 0 1px var(--om-card-edge), var(--om-menu-shadow);
}
@keyframes menu-in {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}
.menu__label {
  padding: 8px 10px 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  color: var(--om-ink-soft);
}
.menu__sep {
  height: 1px;
  margin: 6px -6px;
  background: var(--border);
}
.menu__item {
  position: relative;
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-block: 8px;
  padding-inline: 10px 12px;
  border-radius: var(--r-md);
  text-align: start;
  cursor: default;
  user-select: none;
}
.menu--soft .menu__item {
  border-radius: 8px;
  padding-block: 9px;
  padding-inline: 12px 36px;
  font-size: 14.5px;
}
.menu__item svg {
  width: 16px;
  height: 16px;
}
.menu__item:hover,
.menu__item:focus-visible,
.menu__item[data-active="true"] {
  background: var(--accent);
  box-shadow: none;
}
.menu--soft .menu__item:hover,
.menu--soft .menu__item:focus-visible,
.menu--soft .menu__item[data-active="true"] {
  background: var(--om-select);
}
.menu__item[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}
.menu__item--danger {
  color: var(--destructive);
}
.menu__item--danger:hover,
.menu__item--danger:focus-visible {
  background: color-mix(in srgb, var(--destructive) 10%, transparent);
}
.menu__item--check {
  padding-inline-end: 36px;
}
.menu__check {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
}
.menu__item-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 3px;
  line-height: 1.25;
}
/* an item with a second line gets a little more room */
.menu__item:has(.menu__item-sub) {
  padding-block: 10px;
}
.menu__item:has(.menu__item-sub) > svg {
  align-self: flex-start;
  margin-top: 1px;
}
.menu__item-sub {
  font-size: 12.5px;
  color: var(--om-ink-soft);
}
.menu__trail {
  margin-inline-start: auto;
  font-size: 12px;
  color: var(--om-ink-soft);
}

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 90;
  max-width: 280px;
  padding: 6px 12px;
  border-radius: var(--r-md);
  background: var(--tooltip);
  color: var(--tooltip-ink);
  font-size: 12px;
  line-height: 16px;
  /* a tooltip that lists things shows one per line */
  white-space: pre-line;
  pointer-events: none;
  animation: menu-in 0.1s ease-out;
}

/* a longer tooltip: several lines, bold labels */
.tooltip--rich {
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  line-height: 20px;
}
.tooltip--rich b {
  font-weight: 600;
}

/* ---------- underlined tabs ---------- */
.tabs {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 32px;
  padding: 3px;
}
.tab {
  position: relative;
  height: 25px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  line-height: 22.5px;
  white-space: nowrap;
  color: color-mix(in srgb, var(--om-ink) 60%, transparent);
  transition: color 0.15s ease;
}
.tab:hover {
  color: var(--om-ink);
}
.tab[aria-selected="true"] {
  color: var(--om-ink);
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: -5px;
  height: 2px;
  background: var(--om-ink);
}
.tabs--sm .tab {
  font-size: 14.5px;
}

/* ---------- segmented switch (two or three exclusive choices) ---------- */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  padding: 4px;
  border-radius: 10px;
  background: var(--om-soft-2);
}
.segmented__opt {
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--om-ink-soft);
}
.segmented__opt:hover {
  color: var(--om-ink);
}
.segmented__opt[aria-checked="true"] {
  border-color: var(--om-field-2-edge);
  background: var(--om-field-2);
  color: var(--om-ink);
}

/* ---------- pill toggles (multi choice, e.g. Works on) ---------- */
.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--om-field-2-edge);
  border-radius: var(--r-pill);
  background: var(--om-field-2);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--om-ink-soft);
}
.pill svg {
  width: 16px;
  height: 16px;
}
.pill[aria-pressed="true"] {
  border-color: var(--om-ink);
  background: transparent;
  color: var(--om-ink);
}
.pill:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- drawer (right side) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.1);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease-out;
}
@keyframes fade-in {
  from { opacity: 0; }
}
.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  z-index: 71;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  background: var(--om-plain);
  border-inline-start: 1px solid var(--om-tray-edge);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  font-size: 14px;
  line-height: 20px;
  animation: drawer-in 0.25s ease-out;
}
@keyframes drawer-in {
  from { transform: translateX(100%); }
}
[dir="rtl"] .drawer {
  animation-name: drawer-in-rtl;
}
@keyframes drawer-in-rtl {
  from { transform: translateX(-100%); }
}
.drawer__head {
  position: relative;
  flex: none;
  padding: 20px 28px;
  border-bottom: 1px solid var(--om-tray-edge);
}
.drawer__title {
  padding-inline-end: 32px;
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 600;
  line-height: 25.7px;
  letter-spacing: -0.02em;
}
.drawer__close {
  position: absolute;
  top: 16px;
  inset-inline-end: 16px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--om-ink);
  opacity: 0.8;
}
.drawer__close:hover {
  opacity: 1;
  background: var(--om-select);
}
/* UI.multiSelect: a checkbox before each choice; the menu stays open while ticking */
.menu--checks .menu__item {
  gap: 10px;
}
.menu__box {
  flex: none;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  border: 1px solid var(--ag-dot);
  background: var(--ag-card);
  color: var(--ag-dark-ink);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.menu__box svg {
  width: 10px;
  height: 10px;
  visibility: hidden;
}
.menu--checks [aria-checked="true"] .menu__box {
  background: var(--ag-dark);
  border-color: var(--ag-dark);
}
.menu--checks [aria-checked="true"] .menu__box svg {
  visibility: visible;
}

/* a drawer opened from another (an action from Add an action): Back before the title */
.drawer__head--back {
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer__back {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-inline-start: -6px;
  border-radius: 9px;
  background: var(--ag-hover);
  color: var(--ag-ink-2);
  transition: color 0.15s ease, background 0.15s ease;
}
.drawer__back:hover {
  color: var(--ag-ink);
  background: var(--om-select);
}
.drawer__back svg {
  width: 16px;
  height: 16px;
}
.drawer__close svg {
  width: 16px;
  height: 16px;
}
.drawer__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 28px;
}
/* the body's parts keep their height and the body scrolls; without this a part
   with overflow: hidden (a rounded list) shrinks to fit and its rows vanish */
.drawer__body > * {
  flex-shrink: 0;
}
.drawer__foot {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 28px;
  border-top: 1px solid var(--om-tray-edge);
}
.drawer__foot .btn--primary {
  padding: 0 20px;
}
/* one labelled block in a drawer: label, control, then a hint or an error */
.dfield {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dfield > .label {
  line-height: 20px;
}
.dfield__group-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--om-ink-soft);
}
/* a grouped list of rows (Add an action, Import from library) */
.group-list {
  overflow: hidden;
  border: 1px solid var(--om-field-2-edge);
  border-radius: 12px;
  background: var(--om-field-2);
}
.group-list > * + * {
  border-top: 1px solid var(--om-tray-edge);
}
.group-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-align: start;
  transition: background 0.15s ease;
}
.group-row:hover,
.group-row:focus-visible {
  background: var(--om-select);
  box-shadow: none;
}
.group-row:disabled {
  pointer-events: none;
}

/* ---------- confirm dialog ---------- */
/* a solid card: round icon, the question and one plain sentence, then the
   buttons on the same surface. A destructive confirm is solid red. */
.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 71;
  width: calc(100% - 32px);
  max-width: 440px;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  border-radius: 20px;
  background: var(--om-plain);
  box-shadow: 0 0 0 1px var(--om-card-edge), var(--om-menu-shadow);
  animation: dialog-in 0.1s ease-out;
}
@keyframes dialog-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
}
.dialog__head {
  display: grid;
  grid-template-columns: 44px 1fr;
  column-gap: 16px;
  row-gap: 6px;
}
.dialog__icon {
  grid-row: span 2;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--om-soft-2);
}
.dialog__icon svg {
  width: 20px;
  height: 20px;
}
/* danger: the icon stays on the grey disc, only the mark is red */
.dialog--danger .dialog__icon {
  color: var(--ag-danger);
}
.dialog__title {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.02em;
}
.dialog__text {
  font-size: 14.5px;
  line-height: 24px;
  color: var(--om-ink-soft);
}
.dialog__foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.dialog__foot .btn {
  height: 40px;
  padding: 0 20px;
}
.dialog__foot .btn--other {
  margin-inline: -12px auto;
}
.dialog--danger .dialog__foot [data-yes],
.ap-skin .dialog--danger .dialog__foot [data-yes] {
  background: var(--ag-danger);
  color: var(--ag-on-colour);
}
.dialog--danger .dialog__foot [data-yes]:hover,
.ap-skin .dialog--danger .dialog__foot [data-yes]:hover {
  background: var(--ag-danger-hover);
}
.overlay--dialog {
  background: var(--overlay);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
@media (max-width: 639px) {
  .dialog__head {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .dialog__icon {
    grid-row: auto;
  }
  .dialog__foot {
    flex-direction: column-reverse;
    align-items: stretch;
  }
}

/* ---------- modal (UI.modal): a centred panel the caller fills ---------- */
.modal {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 71;
  transform: translate(-50%, -50%);
  animation: dialog-in 0.12s ease-out;
}

/* ---------- toast ---------- */
/* notifications sit at the top centre of the screen */
.toaster {
  position: fixed;
  z-index: 95;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(356px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--popover);
  color: var(--popover-foreground);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  line-height: 19.5px;
  animation: toast-in 0.25s ease-out;
}
:lang(ar) .toast {
  font-family: "Noto Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
}
.toast__text {
  flex: 1;
  min-width: 0;
}
.toast__action {
  height: 24px;
  padding: 0 8px;
  border-radius: 4px;
  background: var(--om-ink);
  color: var(--popover);
  font-size: 12px;
  font-weight: 500;
}
.toast--error {
  color: var(--destructive);
}

/* ---------- card, table, empty ---------- */
.card {
  position: relative;
  border: 1px solid var(--om-card-edge);
  border-radius: 14px;
  background: var(--om-card);
}
.card--lg {
  border-radius: 20px;
}
/* positioned, so screen-reader-only text inside stays inside the scroll box */
.table-frame {
  position: relative;
  overflow-x: auto;
}
.table {
  width: 100%;
  font-size: 15px;
  line-height: 22.5px;
}
.table th {
  height: 48px;
  padding: 0 8px;
  text-align: start;
  font-weight: 500;
  white-space: nowrap;
  color: var(--om-ink-soft);
}
.table td {
  padding: 16px 8px;
  vertical-align: middle;
}
.table tr {
  border-bottom: 1px solid var(--om-tray-edge);
}
.table tbody tr:last-child {
  border-bottom: 0;
}
.table th:first-child,
.table td:first-child {
  padding-inline-start: 24px;
}
.table th:last-child,
.table td:last-child {
  padding-inline-end: 24px;
}
/* the compact table inside build steps */
.table--compact {
  font-size: 14.5px;
  line-height: 20px;
}
.table--compact th {
  height: 40px;
  font-size: 13px;
  color: var(--om-nav-ink);
}
.table--compact td {
  padding: 12px 8px;
}
.table--compact th:first-child,
.table--compact td:first-child {
  padding-inline-start: 16px;
}
.table--compact th:last-child,
.table--compact td:last-child {
  padding-inline-end: 12px;
}
.table tr[data-href] {
  cursor: pointer;
}
.table tr[data-href]:hover {
  background: var(--om-select);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 24px;
  border-radius: 14px;
  text-align: center;
}
.empty--dashed {
  border: 1px dashed var(--om-tray-edge);
}
.empty__icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--muted);
}
.empty__title {
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 600;
  line-height: 24px;
  letter-spacing: -0.02em;
}
.empty__text {
  max-width: 384px;
  font-size: 13px;
  line-height: 20px;
  color: var(--om-ink-soft);
}
.empty__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ---------- list rows and notes ---------- */
.list-row {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--om-tray-edge);
}
.list-row:last-child {
  border-bottom: 0;
}
.note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 14px;
  line-height: 20px;
  color: var(--om-ink-soft);
}
.note > svg {
  margin-top: 2px;
  width: 16px;
  height: 16px;
}

/* ---------- build-step sections and rows ---------- */
.section {
  display: flex;
  flex-direction: column;
  max-width: 768px;
  padding: 28px 0;
  border-top: 1px solid var(--om-tray-edge);
}
.section:first-child {
  border-top: 0;
  padding-top: 0;
}
.section--wide {
  max-width: none;
}
.section__head {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}
.section__action {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
}
.frow {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
}
.frow__text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.frow__control {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.section__info {
  width: 24px;
  height: 24px;
  margin-inline-start: -6px;
  display: inline-grid;
  place-items: center;
  color: var(--om-ink-soft);
  border-radius: var(--r-pill);
}
.section__info:hover {
  color: var(--om-ink);
}
