/* ==========================================================================
   Hostyard Design System · UI Primitives
   Buttons, badges, cards, forms, tables, alerts, tabs, modals, stat tiles.
   Legacy class names used by existing JS are aliased onto the same rules.
   ========================================================================== */

/* ---- Buttons ---------------------------------------------------------- */
.btn,
.btn-action-blue,
.btn-action-red,
.btn-action-green,
.btn-action-grey,
.btn-action-primary,
.btn-action-secondary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 1.1rem;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.btn svg,
.btn-action-blue svg,
.btn-action-red svg,
.btn-action-green svg,
.btn-action-grey svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn:hover {
  transform: scale(1.01);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled,
.btn[aria-disabled="true"],
.btn-action-blue:disabled,
.btn-action-red:disabled,
.btn-action-green:disabled,
.btn-action-grey:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-primary,
.btn-action-blue,
.btn-action-primary {
  background: var(--brand-gradient);
  color: var(--text-on-brand);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 6px 20px -8px rgba(59, 130, 246, 0.7);
}

.btn-primary:hover,
.btn-action-blue:hover,
.btn-action-primary:hover {
  background: linear-gradient(135deg, var(--brand-400) 0%, var(--brand-600) 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 10px 28px -8px rgba(59, 130, 246, 0.85);
}

.btn-secondary,
.btn-action-grey,
.btn-action-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-1);
  border-color: var(--border-2);
}

.btn-secondary:hover,
.btn-action-grey:hover,
.btn-action-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border-color: transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-1);
}

.btn-outline-brand {
  background: var(--brand-soft);
  color: var(--brand-400);
  border-color: var(--border-brand-soft);
}

.btn-outline-brand:hover {
  background: var(--brand-500);
  color: #fff;
  border-color: var(--brand-500);
}

.btn-danger,
.btn-action-red {
  background: rgba(var(--danger-rgb), 0.1);
  color: var(--danger-300);
  border-color: rgba(var(--danger-rgb), 0.3);
}

.btn-danger:hover,
.btn-action-red:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  box-shadow: 0 8px 20px -8px rgba(var(--danger-rgb), 0.7);
}

.btn-danger-solid {
  background: var(--danger);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.08);
}

.btn-danger-solid:hover {
  background: #dc2626;
}

.btn-success,
.btn-action-green {
  background: rgba(var(--success-rgb), 0.1);
  color: var(--success-300);
  border-color: rgba(var(--success-rgb), 0.3);
}

.btn-success:hover,
.btn-action-green:hover {
  background: var(--success);
  color: #052e16;
  border-color: var(--success);
}

.btn-warning {
  background: rgba(var(--warning-rgb), 0.1);
  color: var(--warning-300);
  border-color: rgba(var(--warning-rgb), 0.3);
}

.btn-warning:hover {
  background: var(--warning);
  color: #1c1002;
  border-color: var(--warning);
}

.btn-warning-solid {
  background: var(--warning);
  color: #1c1002;
}

.btn-warning-solid:hover {
  background: #fbbf24;
}

.btn-discord {
  background: var(--discord);
  color: #fff;
}

.btn-discord:hover {
  background: var(--discord-hover);
  box-shadow: 0 8px 24px -8px rgba(var(--discord-rgb), 0.8);
}

.btn-white {
  background: #fff;
  color: #0b0d12;
}

.btn-white:hover {
  background: #e2e8f0;
}

.btn-sm {
  min-height: 34px;
  padding: 0 0.85rem;
  font-size: var(--fs-xs);
  border-radius: var(--r-sm);
}

.btn-lg {
  min-height: 48px;
  padding: 0 1.6rem;
  font-size: var(--fs-md);
  border-radius: var(--r-lg);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.btn-icon.btn-sm {
  width: 34px;
}

.btn-link {
  min-height: auto;
  padding: 0;
  background: none;
  border: none;
  color: var(--brand-400);
  font-weight: 600;
}

.btn-link:hover {
  color: var(--brand-300);
  text-decoration: underline;
  transform: none;
}

.btn.is-loading {
  color: transparent !important;
  pointer-events: none;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

/* ---- Badges / pills ---------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.7rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border-2);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}

.badge-brand {
  background: var(--brand-soft);
  color: var(--brand-300);
  border-color: var(--border-brand-soft);
}

.badge-success {
  background: rgba(var(--success-rgb), 0.1);
  color: var(--success-300);
  border-color: rgba(var(--success-rgb), 0.25);
}

.badge-danger {
  background: rgba(var(--danger-rgb), 0.1);
  color: var(--danger-300);
  border-color: rgba(var(--danger-rgb), 0.25);
}

.badge-warning {
  background: rgba(var(--warning-rgb), 0.1);
  color: var(--warning-300);
  border-color: rgba(var(--warning-rgb), 0.25);
}

.badge-purple {
  background: rgba(var(--purple-rgb), 0.1);
  color: var(--purple-300);
  border-color: rgba(var(--purple-rgb), 0.25);
}

.badge-cyan {
  background: rgba(var(--cyan-rgb), 0.1);
  color: var(--cyan-300);
  border-color: rgba(var(--cyan-rgb), 0.25);
}

.badge-neutral {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-3);
}

.badge-square {
  border-radius: var(--r-sm);
}

.badge-lg {
  padding: 0.4rem 0.9rem;
  font-size: var(--fs-xs);
}

/* Status dot */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-4);
  flex-shrink: 0;
}

.dot-success { background: var(--success); box-shadow: 0 0 8px rgba(var(--success-rgb), 0.7); }
.dot-danger { background: var(--danger); box-shadow: 0 0 8px rgba(var(--danger-rgb), 0.7); }
.dot-warning { background: var(--warning); box-shadow: 0 0 8px rgba(var(--warning-rgb), 0.7); }
.dot-brand { background: var(--brand-500); box-shadow: 0 0 8px rgba(var(--brand-rgb), 0.7); }
.dot-pulse { animation: pulseDot 1.6s ease-in-out infinite; }

/* ---- Cards ------------------------------------------------------------ */
.card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.card-hover:hover {
  border-color: var(--border-3);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-raised {
  background: var(--surface-2);
}

.card-flat {
  box-shadow: none;
}

.card-brand {
  border-color: var(--border-brand-soft);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.06) 0%, var(--surface-1) 60%);
}

.card-sm {
  padding: var(--sp-4);
  border-radius: var(--r-lg);
}

.card-lg {
  padding: var(--sp-8);
  border-radius: var(--r-2xl);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-1);
}

.card-title svg {
  width: 18px;
  height: 18px;
  color: var(--brand-400);
  flex-shrink: 0;
}

.card-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-3);
  margin-top: 0.2rem;
}

.card-divider {
  height: 1px;
  background: var(--border-1);
  margin: var(--sp-5) 0;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border-1);
}

.card-inset {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5);
}

/* Icon tile (small colored square with an icon) */
.icon-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  border: 1px solid var(--border-brand-soft);
  color: var(--brand-400);
  flex-shrink: 0;
}

.icon-tile svg {
  width: 20px;
  height: 20px;
}

.icon-tile-sm { width: 32px; height: 32px; border-radius: var(--r-sm); }
.icon-tile-sm svg { width: 16px; height: 16px; }
.icon-tile-lg { width: 56px; height: 56px; border-radius: var(--r-lg); }
.icon-tile-lg svg { width: 26px; height: 26px; }
.icon-tile-success { background: rgba(var(--success-rgb), 0.1); border-color: rgba(var(--success-rgb), 0.2); color: var(--success); }
.icon-tile-danger { background: rgba(var(--danger-rgb), 0.1); border-color: rgba(var(--danger-rgb), 0.2); color: var(--danger); }
.icon-tile-warning { background: rgba(var(--warning-rgb), 0.1); border-color: rgba(var(--warning-rgb), 0.2); color: var(--warning); }
.icon-tile-purple { background: rgba(var(--purple-rgb), 0.1); border-color: rgba(var(--purple-rgb), 0.2); color: var(--purple); }
.icon-tile-cyan { background: rgba(var(--cyan-rgb), 0.1); border-color: rgba(var(--cyan-rgb), 0.2); color: var(--cyan); }
.icon-tile-neutral { background: rgba(255, 255, 255, 0.04); border-color: var(--border-2); color: var(--text-3); }
.icon-tile-discord { background: rgba(var(--discord-rgb), 0.12); border-color: rgba(var(--discord-rgb), 0.25); color: var(--discord); }

/* ---- Stat tile -------------------------------------------------------- */
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: var(--sp-5);
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
}

.stat-tile-label {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-4);
}

.stat-tile-value {
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: var(--tracking-tight);
  color: var(--text-1);
  line-height: 1.1;
}

.stat-tile-value small,
.stat-tile-value .unit {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-3);
  margin-left: 0.2rem;
}

.stat-tile-meta {
  font-size: var(--fs-xs);
  color: var(--text-3);
}

/* ---- Key/value list --------------------------------------------------- */
.kv {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.kv-label {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-4);
}

.kv-value {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-1);
  overflow-wrap: anywhere;
}

.kv-value.mono {
  font-family: var(--font-mono);
  color: var(--brand-400);
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-5) var(--sp-8);
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border-1);
  font-size: var(--fs-sm);
}

.kv-row:last-child {
  border-bottom: none;
}

.kv-row .kv-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-3);
}

.kv-row .kv-value {
  font-size: var(--fs-sm);
  text-align: right;
}

/* ---- Progress bars ---------------------------------------------------- */
.progress {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--r-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: var(--r-full);
  background: var(--brand-500);
  box-shadow: 0 0 10px rgba(var(--brand-rgb), 0.5);
  transition: width 0.5s var(--ease-out);
}

.progress-fill.success { background: var(--success); box-shadow: 0 0 10px rgba(var(--success-rgb), 0.5); }
.progress-fill.warning { background: var(--warning); box-shadow: 0 0 10px rgba(var(--warning-rgb), 0.5); }
.progress-fill.danger { background: var(--danger); box-shadow: 0 0 10px rgba(var(--danger-rgb), 0.5); }
.progress-fill.purple { background: var(--purple); box-shadow: 0 0 10px rgba(var(--purple-rgb), 0.5); }
.progress-fill.cyan { background: var(--cyan); box-shadow: 0 0 10px rgba(var(--cyan-rgb), 0.5); }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-3);
  margin-bottom: 0.4rem;
}

.progress-header .val {
  color: var(--text-1);
  font-family: var(--font-mono);
}

/* ---- Forms ------------------------------------------------------------ */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
  min-width: 0;
}

.field-label,
.field > label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.field-hint {
  font-size: var(--fs-xs);
  color: var(--text-4);
}

.field-error {
  font-size: var(--fs-xs);
  color: var(--danger-300);
}

.input,
.select,
.textarea,
.form-control,
.form-input-new,
.admin-search-bar,
.custom-input-box,
.hy-input {
  width: 100%;
  min-height: 44px;
  padding: 0.7rem 1rem;
  background: var(--surface-input);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: 1.4;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.input:hover,
.select:hover,
.textarea:hover,
.form-control:hover,
.form-input-new:hover,
.admin-search-bar:hover,
.custom-input-box:hover,
.hy-input:hover {
  border-color: var(--border-3);
}

.input:focus,
.select:focus,
.textarea:focus,
.form-control:focus,
.form-input-new:focus,
.admin-search-bar:focus,
.custom-input-box:focus,
.hy-input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.2);
  background: var(--bg-1);
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.form-input-new:disabled,
.input[readonly] {
  opacity: 0.6;
  cursor: not-allowed;
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: var(--lh-body);
}

.select,
select.input,
select.form-input-new,
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.select option,
select.input option,
select.form-input-new option,
select.form-control option {
  background: var(--surface-2);
  color: var(--text-1);
}

.input-sm {
  min-height: 36px;
  padding: 0.4rem 0.75rem;
  font-size: var(--fs-xs);
}

.input-mono {
  font-family: var(--font-mono);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-right: 2.75rem;
}

.input-group .input-icon-btn {
  position: absolute;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  color: var(--text-4);
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.input-group .input-icon-btn:hover {
  color: var(--text-1);
  background: rgba(255, 255, 255, 0.06);
}

.input-inline {
  display: flex;
  gap: var(--sp-2);
  align-items: stretch;
}

.input-inline .input {
  flex: 1;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-4);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

/* Checkbox */
.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm);
  color: var(--text-3);
  line-height: 1.45;
}

.checkbox input[type="checkbox"],
.auth-checkbox {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border: 1px solid var(--border-3);
  border-radius: var(--r-xs);
  background: var(--surface-input);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.checkbox input[type="checkbox"]::before,
.auth-checkbox::before {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transition: transform var(--dur-fast) var(--ease);
}

.checkbox input[type="checkbox"]:checked,
.auth-checkbox:checked {
  background: var(--brand-500);
  border-color: var(--brand-500);
}

.checkbox input[type="checkbox"]:checked::before,
.auth-checkbox:checked::before {
  transform: rotate(-45deg) translate(1px, -1px) scale(1);
}

.checkbox a {
  color: var(--brand-400);
  font-weight: 600;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-2);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.switch-track::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-3);
  transition: transform var(--dur) var(--ease-out), background-color var(--dur) var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--brand-soft-2);
  border-color: var(--brand-500);
}

.switch input:checked + .switch-track::before {
  transform: translateX(20px);
  background: var(--brand-400);
  box-shadow: 0 0 8px rgba(var(--brand-rgb), 0.6);
}

.switch input:focus-visible + .switch-track {
  box-shadow: var(--ring);
}

/* Segmented control / pill tabs */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-2);
  border-radius: var(--r-full);
}

.segmented-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
  padding: 0 1.1rem;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.segmented-btn:hover {
  color: var(--text-1);
}

.segmented-btn.active {
  background: var(--brand-500);
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(var(--brand-rgb), 0.7);
}

.segmented-square {
  border-radius: var(--r-md);
}

.segmented-square .segmented-btn {
  border-radius: var(--r-sm);
}

/* Chip filter tabs (used by dashboard filter tabs) */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
  padding: 0 0.95rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border-2);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.chip:hover {
  color: var(--text-1);
  border-color: var(--border-3);
  background: rgba(255, 255, 255, 0.05);
}

.chip.active {
  color: var(--brand-300);
  background: var(--brand-soft);
  border-color: var(--border-brand);
}

/* Underline tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border-1);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1.1rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
  transition: color var(--dur) var(--ease);
}

.tab:hover {
  color: var(--text-1);
}

.tab.active {
  color: var(--text-1);
}

.tab.active::after {
  content: '';
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand-500);
  box-shadow: 0 0 10px rgba(var(--brand-rgb), 0.6);
}

/* ---- Tables ----------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--fs-sm);
}

.table th {
  padding: 0.85rem 1.1rem;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-4);
  background: rgba(255, 255, 255, 0.015);
  border-bottom: 1px solid var(--border-2);
  white-space: nowrap;
}

.table td {
  padding: 0.95rem 1.1rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-1);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background-color var(--dur) var(--ease);
}

.table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.table td.mono,
.table .mono {
  font-family: var(--font-mono);
}

.table .cell-primary {
  color: var(--text-1);
  font-weight: 600;
}

.table .cell-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.table-empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-4);
  font-size: var(--fs-sm);
}

/* Data list (grid rows that behave like a table, but reflow on mobile) */
.data-list {
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  overflow: hidden;
}

.data-list-head,
.data-list-row {
  display: grid;
  align-items: center;
  gap: var(--sp-4);
  padding: 0.9rem 1.25rem;
}

.data-list-head {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-4);
  background: rgba(255, 255, 255, 0.015);
  border-bottom: 1px solid var(--border-2);
}

.data-list-row {
  border-bottom: 1px solid var(--border-1);
  font-size: var(--fs-sm);
  color: var(--text-2);
  transition: background-color var(--dur) var(--ease);
}

.data-list-row:last-child {
  border-bottom: none;
}

.data-list-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.data-list-row.is-selected {
  background: var(--brand-soft);
}

.data-list-body {
  display: flex;
  flex-direction: column;
}

.data-list-empty {
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-4);
  font-size: var(--fs-sm);
}

.cell-label {
  display: none;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-4);
}

/* Avatar / initials */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--brand-soft);
  border: 1px solid var(--border-brand-soft);
  color: var(--brand-300);
  font-size: var(--fs-sm);
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-round {
  border-radius: 50%;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: var(--fs-lg);
}

/* ---- Alerts ----------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.9rem 1.1rem;
  border-radius: var(--r-md);
  border: 1px solid var(--border-2);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.alert svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert strong {
  color: inherit;
}

.alert-title {
  display: block;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 0.15rem;
}

.alert-body {
  flex: 1;
  min-width: 0;
}

.alert-close {
  margin-left: auto;
  color: inherit;
  opacity: 0.6;
  display: inline-flex;
  padding: 0.2rem;
  border-radius: var(--r-xs);
}

.alert-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.alert-success,
.alert-success .alert-title {
  color: var(--success-300);
}

.alert-success {
  background: rgba(var(--success-rgb), 0.08);
  border-color: rgba(var(--success-rgb), 0.28);
}

.alert-danger,
.alert-danger .alert-title {
  color: var(--danger-300);
}

.alert-danger {
  background: rgba(var(--danger-rgb), 0.08);
  border-color: rgba(var(--danger-rgb), 0.28);
}

.alert-warning,
.alert-warning .alert-title {
  color: var(--warning-300);
}

.alert-warning {
  background: rgba(var(--warning-rgb), 0.08);
  border-color: rgba(var(--warning-rgb), 0.28);
}

.alert-info,
.alert-info .alert-title {
  color: var(--brand-300);
}

.alert-info {
  background: rgba(var(--brand-rgb), 0.08);
  border-color: rgba(var(--brand-rgb), 0.28);
}

/* ---- Empty state ------------------------------------------------------ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-3);
  border: 1px dashed var(--border-3);
  border-radius: var(--r-lg);
}

.empty-state svg {
  width: 36px;
  height: 36px;
  color: var(--text-5);
}

.empty-state h4 {
  font-size: var(--fs-md);
  color: var(--text-2);
}

.empty-state p {
  font-size: var(--fs-sm);
  max-width: 380px;
}

/* ---- Section header (page-level) -------------------------------------- */
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.section-head h2,
.section-head h3 {
  font-size: var(--fs-xl);
  font-weight: 800;
}

.section-head p {
  font-size: var(--fs-sm);
  margin-top: 0.25rem;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: var(--r-full);
  background: var(--brand-soft);
  border: 1px solid var(--border-brand-soft);
  color: var(--brand-300);
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.eyebrow svg {
  width: 12px;
  height: 12px;
}

/* ---- Generic modal overlay (server-rendered modals in views) ------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--surface-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-overlay.open,
.modal-overlay[style*="flex"] {
  display: flex;
}

.modal-panel {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-3);
  border-radius: var(--r-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeIn 0.2s var(--ease-out);
}

.modal-panel.modal-md { max-width: 620px; }
.modal-panel.modal-lg { max-width: 820px; }
.modal-panel.modal-xl { max-width: 1040px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-head h3 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: var(--fs-lg);
  font-weight: 800;
}

.modal-head h3 svg {
  width: 20px;
  height: 20px;
  color: var(--brand-400);
}

.modal-head.is-danger h3 svg,
.modal-head.is-danger h3 {
  color: var(--danger);
}

.modal-body {
  color: var(--text-3);
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.modal-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  color: var(--text-4);
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.modal-x:hover {
  color: var(--text-1);
  background: rgba(255, 255, 255, 0.06);
}

/* ---- Notice bars (impersonation, expiry) -------------------------------- */
.notice-bar {
  position: sticky;
  top: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  font-size: var(--fs-sm);
  font-weight: 600;
  border-bottom: 1px solid transparent;
}

.notice-bar svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.notice-bar-danger {
  background: #e11d48;
  color: #fff;
  border-bottom-color: #be123c;
  box-shadow: 0 4px 20px rgba(225, 29, 72, 0.35);
}

.notice-bar-warning {
  background: rgba(var(--warning-rgb), 0.12);
  color: var(--warning-300);
  border-bottom-color: rgba(var(--warning-rgb), 0.3);
  backdrop-filter: blur(8px);
}

/* ---- Code / terminal block ---------------------------------------------- */
.terminal {
  background: #060709;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 1.25rem;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-3);
  line-height: 1.6;
  overflow-x: auto;
}

.terminal .prompt {
  color: var(--brand-400);
}

.terminal .ok {
  color: var(--success);
}

.terminal .err {
  color: var(--danger);
}

/* ---- Divider with label -------------------------------------------------- */
.divider-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-5);
}

.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-1);
}

/* ---- Responsive primitives ---------------------------------------------- */
@media (max-width: 768px) {
  .form-row,
  .form-row-3,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .data-list-head {
    display: none;
  }

  .data-list-row {
    grid-template-columns: 1fr !important;
    gap: 0.5rem;
    padding: 1rem 1.1rem;
  }

  .data-list-row > * {
    min-width: 0;
  }

  .cell-label {
    display: block;
    margin-bottom: 0.15rem;
  }

  .data-list-row .cell-actions {
    justify-content: flex-start;
    padding-top: 0.5rem;
  }

  .modal-panel {
    padding: 1.25rem;
    border-radius: var(--r-lg);
  }

  .btn,
  .chip,
  .segmented-btn,
  .tab {
    min-height: var(--touch);
  }

  .btn-sm {
    min-height: 40px;
  }

  input:not(.two-factor-input):not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px;
  }
}
