/*
 * The shared building blocks every screen uses (made by the files in js/ui/):
 * buttons, badges, alerts, panels, forms, tables, pop-ups, menus, tabs, messages, loading/empty states.
 * The look follows design/new-look-mockup.html: white cards on a light grey page, rounded controls, soft badges.
 */

/* ─── Buttons ─── */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-on-accent);
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 2px rgb(15 23 42 / 6%);
  transition: background var(--transition-fast), border-color var(--transition-fast), filter var(--transition-fast), opacity var(--transition-fast);
}
.btn:hover:not(:disabled) {
  filter: brightness(0.95);
}
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
.btn-md {
  padding: 8px 16px;
}
.btn-success {
  background: var(--color-success);
  border-color: var(--color-success);
}
.btn-success:hover:not(:disabled) {
  background: var(--color-success-strong);
  border-color: var(--color-success-strong);
  filter: none;
}
/* Default: the quiet, white button (Cancel, Close, Change…). */
.btn-default {
  background: var(--color-control);
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn-default:hover:not(:disabled) {
  background: var(--color-surface-sunken);
  filter: none;
}
.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-warning {
  background: var(--color-warning);
  border-color: var(--color-warning);
}
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-info {
  background: var(--color-info);
  border-color: var(--color-info);
}
.btn-link {
  padding-inline: 0;
  background: transparent;
  box-shadow: none;
  color: var(--color-primary);
}
.btn-link:hover:not(:disabled) {
  text-decoration: underline;
}
.btn .spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgb(255 255 255 / 45%);
  border-top-color: var(--color-on-accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.btn-default .spinner {
  border-color: var(--color-border);
  border-top-color: var(--color-text-subtle);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Badges: soft colour with dark text ─── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-success {
  background: var(--color-success-soft);
  color: var(--color-success-strong);
  box-shadow: inset 0 0 0 1px rgb(120 205 81 / 35%);
}
.badge-warning {
  background: var(--color-warning-soft);
  color: #b45309;
  box-shadow: inset 0 0 0 1px rgb(245 158 11 / 35%);
}
.badge-danger {
  background: var(--color-danger-soft);
  color: #b91c1c;
  box-shadow: inset 0 0 0 1px rgb(239 68 68 / 30%);
}
.badge-primary {
  background: var(--color-primary-soft);
  color: #4338ca;
  box-shadow: inset 0 0 0 1px rgb(99 102 241 / 30%);
}
.badge-info {
  background: var(--color-info-soft);
  color: #0369a1;
  box-shadow: inset 0 0 0 1px rgb(14 165 233 / 30%);
}
.badge-default {
  background: var(--color-default-soft);
  color: #475569;
  box-shadow: inset 0 0 0 1px rgb(148 163 184 / 35%);
}

/* ─── Alerts ─── */
.alert {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: var(--space-4);
  padding: 12px var(--space-4);
  border: 1px solid;
  border-left-width: 4px;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}
.alert-title {
  font-weight: 600;
}
.alert-info {
  border-color: rgb(14 165 233 / 35%);
  border-left-color: var(--color-info);
  background: var(--color-info-soft);
  color: #075985;
}
.alert-success {
  border-color: rgb(120 205 81 / 40%);
  border-left-color: var(--color-success);
  background: var(--color-success-soft);
  color: #3f6b23;
}
.alert-warning {
  border-color: rgb(245 158 11 / 35%);
  border-left-color: var(--color-warning);
  background: var(--color-warning-soft);
  color: #92400e;
}
.alert-danger {
  border-color: rgb(239 68 68 / 30%);
  border-left-color: var(--color-danger);
  background: var(--color-danger-soft);
  color: #991b1b;
}

/* ─── Panels: white cards ─── */
.panel {
  margin-bottom: var(--space-5);
  border-radius: var(--radius-card);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 56px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-row-line);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}
.panel-title {
  color: var(--color-text-strong);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.panel-body {
  padding: 20px;
}
.panel-flush {
  padding: 0;
}
/* A flush panel's last table keeps the card's rounded bottom corners. */
.panel-flush > .table-wrap:last-child,
.panel-flush > .table-wrap:last-child .table-scroll {
  border-radius: 0 0 var(--radius-card) var(--radius-card);
}

/* ─── Page heading (breadcrumbs and title) ─── */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 4px;
  padding: 0;
  list-style: none;
  color: var(--color-text-muted);
  font-size: var(--font-size-xs);
}
.crumbs li + li::before {
  content: "/";
  margin-right: 6px;
}
.crumbs a:hover {
  color: var(--color-text);
}
.page-title {
  color: var(--color-text-strong);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-actions {
  display: flex;
  gap: var(--space-2);
}

/* ─── Forms ─── */
.form-grid {
  display: grid;
  gap: var(--space-4) 20px;
  align-items: start;
}
.cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 1100px) {
  .cols-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .cols-4,
  .cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .cols-6,
  .cols-4,
  .cols-3,
  .cols-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field-wide {
  grid-column: 1 / -1;
}
.field-label {
  color: #334155;
  font-size: var(--font-size-sm);
  font-weight: 500;
}
.field-required {
  color: var(--color-danger);
}
.control {
  width: 100%;
  min-height: var(--control-height);
  padding: 7px 12px;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  background: var(--color-control);
  color: var(--color-text-strong);
  font-size: var(--font-size-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.control::placeholder {
  color: var(--color-text-muted);
}
.control:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgb(120 205 81 / 22%);
  outline: none;
}
.control[aria-invalid="true"] {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 3px rgb(239 68 68 / 12%);
}
.control:disabled {
  background: var(--color-default-soft);
  color: var(--color-text-muted);
  cursor: not-allowed;
}
.control[readonly] {
  background: var(--color-surface-sunken);
}
select.control {
  padding-right: 32px;
}
textarea.control {
  min-height: 72px;
  resize: vertical;
}
.field-hint {
  color: var(--color-text-subtle);
  font-size: var(--font-size-xs);
}
.field-message {
  color: var(--color-danger);
  font-size: var(--font-size-xs);
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-size-sm);
  cursor: pointer;
}
.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-success);
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: 20px;
}
.form-actions-start {
  justify-content: flex-start;
}

/* ─── Tables ─── */
.table-wrap {
  width: 100%;
}
.table-scroll {
  width: 100%;
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface-raised);
}
.table th {
  padding: 11px 14px;
  border-bottom: 1px solid var(--color-table-head-border);
  background: var(--color-table-head);
  color: var(--color-text-subtle);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-row-line);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  vertical-align: middle;
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover td {
  background: var(--color-table-row-hover);
}
.table tfoot td {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-sunken);
  font-weight: 600;
}
.table .align-end {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table .align-center {
  text-align: center;
}
.table tr.clickable {
  cursor: pointer;
}
.table tr.clickable:focus-visible td {
  outline: 2px solid var(--color-border-focus);
  outline-offset: -2px;
}
.table tr.selected td {
  background: var(--color-success-soft);
}
.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.sort-idle {
  opacity: 0.35;
}
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: 12px 20px;
  border-top: 1px solid var(--color-row-line);
  color: var(--color-text-subtle);
  font-size: var(--font-size-sm);
}
.pager button {
  padding: 5px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-control);
  cursor: pointer;
}
.pager button:hover:not(:disabled) {
  background: var(--color-surface-sunken);
}
.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ─── Loading, empty and error states ─── */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 36px var(--space-4);
  color: var(--color-text-subtle);
  text-align: center;
}
.state-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--color-default-soft);
  color: var(--color-default);
}
.state-error .state-icon {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.state-title {
  margin: 0;
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-strong);
}
.state-detail {
  max-width: 520px;
  margin: 0;
  font-size: var(--font-size-sm);
}
.spinner-large {
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-success);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.spinner-wrap {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* ─── Pop-up windows ─── */
.modal {
  width: min(100% - 32px, var(--modal-width, 640px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-modal);
  color: var(--color-text);
}
.modal::backdrop {
  background: rgb(15 23 42 / 50%);
  backdrop-filter: blur(2px);
}
.modal-sm {
  --modal-width: 420px;
}
.modal-md {
  --modal-width: 640px;
}
.modal-lg {
  --modal-width: 960px;
}
.modal-content {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 16px 20px;
  border-top: 4px solid var(--color-success);
  border-bottom: 1px solid var(--color-row-line);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: var(--color-control);
  color: var(--color-text-strong);
}
.modal-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
}
.modal-close {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-subtle);
  cursor: pointer;
}
.modal-close:hover {
  background: var(--color-default-soft);
  color: var(--color-text-strong);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 14px 20px;
  border-top: 1px solid var(--color-row-line);
  border-radius: 0 0 var(--radius-card) var(--radius-card);
  background: var(--color-surface-sunken);
}

/* ─── Drop-down menus ─── */
.menu-root {
  position: relative;
  display: inline-flex;
}
.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: var(--z-menu);
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-menu);
}
.menu-start {
  right: auto;
  left: 0;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  text-align: left;
  cursor: pointer;
}
.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--color-default-soft);
  outline: none;
}
.menu-item:disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* ─── Tabs ─── */
.tab-list {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 12px;
  border-bottom: 1px solid var(--color-border);
}
.tab {
  padding: 11px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--color-text-subtle);
  font-size: var(--font-size-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover {
  color: var(--color-text-strong);
}
.tab[aria-selected="true"] {
  border-bottom-color: var(--color-success);
  color: var(--color-text-strong);
  font-weight: 600;
}
.tab-panel {
  padding-top: var(--space-4);
}

/* ─── Messages in the corner ─── */
.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(400px, calc(100vw - 32px));
}
.toast {
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-menu);
  color: var(--color-on-accent);
  font-size: var(--font-size-sm);
  font-weight: 500;
  animation: toast-enter 160ms ease-out;
}
.toast-success {
  background: var(--color-success-strong);
}
.toast-danger {
  background: var(--color-danger);
}
.toast-info {
  background: var(--color-ink);
}

@keyframes toast-enter {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* ─── Label / value lists (summaries) ─── */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px 20px;
  margin: 0;
}
.facts div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.facts dt {
  color: var(--color-text-subtle);
  font-size: var(--font-size-xs);
}
.facts dd {
  margin: 0;
  color: var(--color-text-strong);
  font-size: var(--font-size-sm);
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ─── Access Denied Screen (Image 2 style) ─── */
.access-denied-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height, 60px) - 60px);
  padding: 40px 24px;
  background: #ffffff;
  border-radius: 16px;
  margin: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}

.access-denied-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 56px;
  max-width: 1040px;
  width: 100%;
  position: relative;
}

.access-denied-media {
  flex: 1;
  max-width: 480px;
  min-width: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.access-denied-image {
  width: 100%;
  max-width: 460px;
  height: auto;
  display: block;
  object-fit: contain;
}

.access-denied-info {
  flex: 1;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  position: relative;
  z-index: 1;
}

.access-denied-heading {
  margin: 0 0 14px 0;
  font-size: clamp(34px, 4vw, 44px);
  font-weight: 800;
  color: #0b1329;
  line-height: 1.12;
  letter-spacing: -0.025em;
}

.access-denied-badge {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 9999px;
  background: #eceff3;
  color: #334155;
  margin-bottom: 16px;
  letter-spacing: 0.01em;
}

.access-denied-message {
  margin: 0 0 8px 0;
  font-size: 19px;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.35;
}

.access-denied-instructions {
  margin: 0;
  font-size: 14.5px;
  color: #64748b;
  line-height: 1.55;
}

/* Floating decorative elements matching Image 2 */
.access-denied-decor {
  position: absolute;
  pointer-events: none;
  user-select: none;
}
.access-denied-decor svg,
.access-denied-decor-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.decor-key-top-right {
  top: 15px;
  left: 380px;
  width: 44px;
  height: 24px;
  transform: rotate(-35deg);
}

.decor-dot-top-right {
  top: 60px;
  left: 415px;
  width: 10px;
  height: 10px;
}

.decor-star-middle-right {
  top: 140px;
  left: 425px;
  width: 20px;
  height: 20px;
}

.decor-key-bottom-red {
  top: 195px;
  left: 395px;
  width: 44px;
  height: 24px;
  transform: rotate(35deg);
}

.decor-star-bottom-red {
  top: 265px;
  left: 365px;
  width: 18px;
  height: 18px;
}

.decor-sparkle-bottom {
  top: 265px;
  left: 15px;
  width: 26px;
  height: 26px;
}

.decor-dot-bottom {
  top: 280px;
  left: 60px;
  width: 8px;
  height: 8px;
}

.decor-key-bottom-blue {
  top: 265px;
  left: 110px;
  width: 44px;
  height: 24px;
  transform: scaleX(-1) rotate(35deg);
}

@media (max-width: 900px) {
  .access-denied-card {
    flex-direction: column;
    text-align: center;
    gap: 32px;
  }
  .access-denied-info {
    align-items: center;
    text-align: center;
  }
  .access-denied-buttons {
    justify-content: center;
  }
  .access-denied-decor {
    display: none;
  }
}
