/* Cherkun Ops v2 reusable controls, tables and states. */

html body.executive-ui:not(.ui-lab-shell) :where(input, select, textarea) {
  min-height: var(--ops-control) !important;
  border: 1px solid var(--ops-line-strong) !important;
  background: var(--ops-surface) !important;
  color: var(--ops-ink) !important;
  padding: 10px 12px !important;
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
}

body.executive-ui:not(.ui-lab-shell) textarea { min-height: 96px; resize: vertical; }

body.executive-ui:not(.ui-lab-shell) :where(input, select, textarea):focus {
  border-color: var(--ops-accent) !important;
  box-shadow: 0 0 0 3px rgba(var(--ops-accent-rgb), .16) !important;
  outline: 0;
}

body.executive-ui:not(.ui-lab-shell) :where(label, .form-label) {
  color: var(--ops-muted);
  font-size: 12px;
  font-weight: 700;
}

html body.executive-ui:not(.ui-lab-shell) :where(.button, button.button, a.button) {
  min-height: var(--ops-control) !important;
  justify-content: center;
  border: 1px solid var(--ops-line-strong) !important;
  background: var(--ops-surface) !important;
  box-shadow: none !important;
  color: var(--ops-ink) !important;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .01em;
}

/* WCAG 2.2 target size for legacy and v2 controls. */
html body.executive-ui:not(.ui-lab-shell) :where(
  button:not(.mobile-nav-backdrop):not(.command-palette-backdrop),
  [role="button"],
  summary
) {
  min-height: var(--ops-control) !important;
}

body.executive-ui:not(.ui-lab-shell) :where(
  .shell-icon-button,
  .mobile-nav-toggle,
  .sidebar-command-tools button
) {
  min-width: var(--ops-control);
}

body.executive-ui:not(.ui-lab-shell) :where(.button, button.button, a.button):hover {
  border-color: var(--ops-accent) !important;
  background: var(--ops-surface-2) !important;
}

html body.executive-ui:not(.ui-lab-shell) :where(.button.primary, button.primary, a.button.primary) {
  border-color: var(--ops-accent) !important;
  background: var(--ops-accent) !important;
  color: #fff !important;
}

html body.executive-ui[data-ui-theme="dark"]:not(.ui-lab-shell) :where(.button.primary, button.primary, a.button.primary) {
  color: #101012 !important;
}

body.executive-ui:not(.ui-lab-shell) :where(.button.danger, button.danger) {
  border-color: var(--ops-critical) !important;
  color: var(--ops-critical) !important;
}

body.executive-ui:not(.ui-lab-shell) :where(.button.warning, button.warning) {
  border-color: var(--ops-warning) !important;
  color: var(--ops-warning) !important;
}

html body.executive-ui:not(.ui-lab-shell) .button.small { min-height: var(--ops-control) !important; }

body.executive-ui:not(.ui-lab-shell) :focus-visible {
  outline: 3px solid rgba(var(--ops-accent-rgb), .38) !important;
  outline-offset: 2px;
}

body.executive-ui:not(.ui-lab-shell) .table-scroll {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--ops-line) !important;
  background: var(--ops-surface);
}

body.executive-ui:not(.ui-lab-shell) table {
  width: 100%;
  border-collapse: collapse;
}

body.executive-ui:not(.ui-lab-shell) :where(th, td) {
  border-bottom: 1px solid var(--ops-line) !important;
  padding: 12px 10px !important;
  text-align: left;
  vertical-align: middle;
}

body.executive-ui:not(.ui-lab-shell) th {
  background: var(--ops-surface-2) !important;
  color: var(--ops-muted) !important;
  font-family: var(--ops-mono);
  font-size: 10px !important;
  letter-spacing: .08em;
  text-transform: uppercase;
}

body.executive-ui:not(.ui-lab-shell) tbody tr:hover td { background: var(--ops-surface-2) !important; }

body.executive-ui:not(.ui-lab-shell) .status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--ops-line);
  background: var(--ops-surface-2);
  padding: 4px 8px;
  color: var(--ops-muted);
  font-family: var(--ops-mono);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

body.executive-ui:not(.ui-lab-shell) .status.ok { border-color: var(--ops-ready); color: var(--ops-ready); }
body.executive-ui:not(.ui-lab-shell) .status.warn { border-color: var(--ops-warning); color: var(--ops-warning); }
body.executive-ui:not(.ui-lab-shell) .status.bad { border-color: var(--ops-critical); color: var(--ops-critical); }

body.executive-ui:not(.ui-lab-shell) :where(.notice, .flash) {
  border: 1px solid var(--ops-line) !important;
  border-left-width: 4px !important;
  background: var(--ops-surface) !important;
  color: var(--ops-ink) !important;
  padding: 14px 16px;
}

body.executive-ui:not(.ui-lab-shell) :where(.notice.warning, .flash.warning) { border-left-color: var(--ops-warning) !important; }
body.executive-ui:not(.ui-lab-shell) :where(.notice.error, .flash.error) { border-left-color: var(--ops-critical) !important; }
body.executive-ui:not(.ui-lab-shell) :where(.notice.success, .flash.success) { border-left-color: var(--ops-ready) !important; }

body.executive-ui:not(.ui-lab-shell) details > summary {
  min-height: var(--ops-control);
  cursor: pointer;
}

body.executive-ui:not(.ui-lab-shell) .empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--ops-line-strong);
  background: var(--ops-surface-2);
  padding: 24px;
  color: var(--ops-muted);
  text-align: center;
}

/* Shared dialog and submission UX for admin and worker portals. */
body.ux-dialog-open { overflow: hidden; }

:where(.ux-form-dialog, .ux-confirm-dialog) {
  width: min(760px, calc(100vw - 32px));
  max-height: min(88vh, 920px);
  border: 1px solid var(--ops-line-strong, #c7ccd2);
  border-radius: 2px;
  background: var(--ops-surface, #fff);
  box-shadow: 0 24px 64px rgba(13, 18, 24, .26);
  color: var(--ops-ink, #171a1f);
  margin: auto;
  padding: 0;
}

:where(.ux-form-dialog, .ux-confirm-dialog)::backdrop {
  background: rgba(9, 12, 16, .68);
  backdrop-filter: blur(2px);
}

.ux-form-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.ux-form-dialog-closebar {
  position: sticky;
  z-index: 4;
  top: 0;
  display: flex;
  justify-content: flex-end;
  border-bottom: 1px solid var(--ops-line, #d9dde2);
  background: var(--ops-surface-2, #f4f5f6);
  padding: 8px 12px;
}

.ux-dialog-close,
.flash-dismiss {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--ops-line-strong, #c7ccd2);
  border-radius: 2px;
  background: var(--ops-surface, #fff);
  color: var(--ops-ink, #171a1f);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 750;
}

.ux-form-dialog > .form-drawer-body {
  display: grid;
  gap: 16px;
  max-height: none !important;
  overflow: auto;
  border: 0 !important;
  border-radius: 0 !important;
  background: var(--ops-surface, #fff) !important;
  margin: 0 !important;
  padding: 22px !important;
}

.ux-form-dialog > .form-drawer-body > :is(h1, h2, h3):first-child { margin-top: 0; }
.ux-form-dialog :where(form, fieldset, .form-grid, .stack-form) { min-width: 0; }

.ux-confirm-dialog[open] {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 18px;
  width: min(500px, calc(100vw - 32px));
  padding: 24px;
}

.ux-confirm-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--ops-warning, #b46b08);
  background: color-mix(in srgb, var(--ops-warning, #b46b08) 13%, transparent);
  color: var(--ops-warning, #b46b08);
  font-family: var(--ops-mono, monospace);
  font-size: 18px;
  font-weight: 900;
}

.ux-confirm-dialog[data-tone="danger"] .ux-confirm-icon {
  border-color: var(--ops-critical, #b42318);
  background: color-mix(in srgb, var(--ops-critical, #b42318) 13%, transparent);
  color: var(--ops-critical, #b42318);
}

.ux-confirm-copy h2 { margin: 0 0 8px; font-size: 20px; }
.ux-confirm-copy p { margin: 0; color: var(--ops-muted, #5b6470); line-height: 1.55; }
.ux-confirm-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }

.ux-form-error {
  border: 1px solid var(--ops-critical, #b42318);
  border-left-width: 4px;
  background: color-mix(in srgb, var(--ops-critical, #b42318) 8%, var(--ops-surface, #fff));
  color: var(--ops-critical, #b42318);
  margin: 0 0 12px;
  padding: 11px 13px;
  font-size: 14px;
  font-weight: 750;
}

form.ux-submitting { cursor: progress; }
form.ux-submitting :where(button[type="submit"], input[type="submit"]) { pointer-events: none; }
.ux-submit-pending::after {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  display: inline-block;
  margin-left: 8px;
  vertical-align: -2px;
  animation: ux-submit-spin .7s linear infinite;
}

.flash { position: relative; padding-right: 62px !important; }
.flash-dismiss {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 44px;
  transform: translateY(-50%);
  font-size: 0;
}
.flash-dismiss::before { content: "\00d7"; font-size: 22px; font-weight: 500; }

@keyframes ux-submit-spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  :where(.ux-form-dialog, .ux-confirm-dialog) {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .ux-form-dialog > .form-drawer-body { padding: 16px !important; }
  .ux-confirm-dialog[open] { grid-template-columns: 1fr; gap: 12px; padding: 18px; }
  .ux-confirm-icon { width: 38px; height: 38px; }
  .ux-confirm-actions { grid-column: 1; display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .ux-submit-pending::after { animation: none; }
  :where(.ux-form-dialog, .ux-confirm-dialog)::backdrop { backdrop-filter: none; }
}
