.card-ui {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.card-ui-soft {
  background: linear-gradient(160deg, var(--bg-elevated), var(--bg-soft));
}

.card-ui-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.card-ui-body {
  padding: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}

.metric-label {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.btn-ui {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  font-weight: 700;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-ui:hover {
  background: var(--bg-soft);
}

.btn-ui-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-ui-primary:hover {
  filter: brightness(0.96);
}

.btn-ui-danger {
  color: var(--danger);
}

.form-ui,
.subtle-input,
.form-control,
input.form-control,
select.form-control,
textarea.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  padding: 9px 11px;
  font-size: 14px;
}

input::placeholder,
select option {
  color: var(--text-subtle);
}

.form-ui:focus,
.subtle-input:focus,
.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary) !important;
  outline: none;
  box-shadow: none;
}

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 65%, transparent);
  outline-offset: 2px;
}

.form-ui::placeholder,
.subtle-input::placeholder,
.form-control::placeholder {
  color: var(--text-subtle);
}

.table-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
}

table.dtable,
table.table {
  margin: 0 !important;
  color: var(--text);
}

table.dtable thead th,
table.table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}

table.dtable td,
table.table td {
  border-color: var(--border);
  vertical-align: middle;
  font-size: 13px;
}

table.dtable tbody tr:hover,
table.table tbody tr:hover {
  background: var(--bg-soft);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 11px;
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.status-pill.ok .dot {
  background: var(--success);
}

.status-pill.bad .dot {
  background: var(--danger);
}

.status-pill.unk .dot {
  background: var(--text-subtle);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 24, 0.45);
  backdrop-filter: blur(3px);
  z-index: 2500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-box {
  width: 100%;
  max-width: 460px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
}

.modal-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
  border-radius: 8px;
  border: 1px solid var(--border) !important;
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  min-height: 32px;
}

/* Bootstrap/DataTables dark theme overrides */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] input.form-control,
html[data-theme="dark"] select.form-control,
html[data-theme="dark"] textarea.form-control,
html[data-theme="dark"] .dataTables_wrapper input,
html[data-theme="dark"] .dataTables_wrapper select {
  background-color: var(--bg-elevated) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] table.dataTable,
html[data-theme="dark"] table.dtable,
html[data-theme="dark"] table.table {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] table.dataTable thead th,
html[data-theme="dark"] table.dtable thead th,
html[data-theme="dark"] table.table thead th {
  background: var(--bg-soft) !important;
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] table.dataTable tbody td,
html[data-theme="dark"] table.dtable tbody td,
html[data-theme="dark"] table.table tbody td {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] table.dataTable tbody tr:hover td,
html[data-theme="dark"] table.dtable tbody tr:hover td,
html[data-theme="dark"] table.table tbody tr:hover td {
  background: var(--bg-soft) !important;
}

html[data-theme="dark"] .dataTables_wrapper {
  color: var(--text);
}

/* Neutralize Bootstrap table-dark in dark mode - use theme vars instead */
html[data-theme="dark"] .table-dark thead th {
  background: var(--bg-soft) !important;
  color: var(--text-muted) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] .table-dark tbody td {
  background: var(--bg-elevated) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] .table-dark tbody tr:hover td {
  background: var(--bg-soft) !important;
}

html[data-theme="dark"] .table-responsive {
  background: transparent;
}

/* Bootstrap button dark theme overrides */
html[data-theme="dark"] .btn-primary {
  background-color: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}

html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn-outline-secondary {
  background-color: var(--bg-elevated) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}

html[data-theme="dark"] .form-label,
html[data-theme="dark"] label {
  color: var(--text) !important;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
  color: var(--text-muted) !important;
  font-size: 12px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: 8px !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  background: var(--bg-elevated) !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary-soft) !important;
  color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.mobile-bottom-nav {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 40;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-elevated);
  display: none;
  justify-content: space-around;
  padding: 8px;
}

.mobile-bottom-nav a {
  color: var(--text-muted);
  text-decoration: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.mobile-bottom-nav a.active {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Utility compatibility for pages still using Tailwind-like classes */
.hidden { display: none !important; }
.block { display: block; }
.inline-flex { display: inline-flex; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.space-y-3 > * + * { margin-top: .75rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.25rem; }
.p-6 { padding: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-1 { margin-top: .25rem; }
.mt-6 { margin-top: 1.5rem; }
.w-full, .w-100 { width: 100%; }
.text-sm { font-size: 14px; }
.text-xs { font-size: 12px; }
.text-lg { font-size: 18px; }
.rounded-lg { border-radius: 10px; }
.border-b { border-bottom: 1px solid var(--border); }
.border { border: 1px solid var(--border); }
.font-bold { font-weight: 700; }
.text-end { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }

@media (max-width: 1024px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .mobile-bottom-nav {
    display: flex;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
