/* ═══════════════════════════════════════════════════════════════════════════
   05-components.css — UI Components
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: box-shadow var(--duration-normal) var(--ease);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-lg) var(--sp-xl);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.card-body {
  padding: var(--sp-xl);
}

.card-body-flush {
  padding: 0;
}

/* ── KPI Cards ──────────────────────────────────────────────────────────── */
.kpi-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  padding: var(--sp-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  border-top: 3px solid var(--accent);
  transition: border-color var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}

.kpi-card:hover {
  box-shadow: var(--shadow-sm);
}

.kpi-icon {
  display: none;
}

.kpi-text {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  min-width: 0;
}

.kpi-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: 1.1;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  padding: var(--sp-2xs) var(--sp-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-xs);
  line-height: 1.4;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-subtle);
  color: var(--accent);
}

.badge-success {
  background: var(--success-subtle);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-subtle);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-subtle);
  color: var(--danger);
}

.badge-info {
  background: var(--info-subtle);
  color: var(--info);
}

.badge-neutral {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

/* ── Status Dot ─────────────────────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.status-dot.online { background-color: var(--success); }
.status-dot.offline { background-color: var(--danger); }
.status-dot.unknown { background-color: var(--text-tertiary); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  padding: var(--sp-lg) var(--sp-xl);
  border-radius: var(--radius-sm);
  border-left: 3px solid;
  font-size: var(--text-sm);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-md);
}

.alert-success {
  background: var(--success-subtle);
  border-left-color: var(--success);
  color: var(--text-primary);
}

.alert-warning {
  background: var(--warning-subtle);
  border-left-color: var(--warning);
  color: var(--text-primary);
}

.alert-danger {
  background: var(--danger-subtle);
  border-left-color: var(--danger);
  color: var(--text-primary);
}

.alert-info {
  background: var(--info-subtle);
  border-left-color: var(--info);
  color: var(--text-primary);
}

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-overlay);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease);
}

.modal-content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--sp-xl);
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-md);
  padding: var(--sp-lg) var(--sp-xl);
  border-top: 1px solid var(--border-subtle);
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--sp-xl);
  right: var(--sp-xl);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.toast {
  padding: var(--sp-lg) var(--sp-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  min-width: 280px;
  max-width: 400px;
  animation: slideInRight var(--duration-normal) var(--ease);
}

.toast-success { border-left: 3px solid var(--success); }
.toast-danger { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Empty State ────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-4xl) var(--sp-xl);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  text-align: center;
}

.empty-state i {
  font-size: var(--text-2xl);
  opacity: 0.5;
}

/* ── Table Sort ─────────────────────────────────────────────────────────── */
.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--duration-fast) var(--ease);
}

.sortable:hover {
  color: var(--text-primary);
}

.sort-active {
  color: var(--accent) !important;
}

.sort-indicator {
  font-size: var(--text-xs);
  margin-left: var(--sp-xs);
}

/* ── Filter Bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
  width: auto;
  min-width: 140px;
  padding: var(--sp-sm) var(--sp-lg);
  font-size: var(--text-sm);
}

/* ── Sticky Save Bar ────────────────────────────────────────────────────── */
.save-bar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w);
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-md);
  padding: var(--sp-lg) var(--sp-xl);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-sticky);
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease);
}

.save-bar.visible {
  transform: translateY(0);
}

@media (max-width: 767.98px) {
  .save-bar {
    left: 0;
  }
}

/* ── Config Section ─────────────────────────────────────────────────────── */
.config-section {
  padding: var(--sp-xl);
  border-bottom: 1px solid var(--border-subtle);
}

.config-section:last-child {
  border-bottom: none;
}

.config-section-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  margin-bottom: var(--sp-lg);
}

.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-xl);
  padding: var(--sp-md) 0;
}

.config-row + .config-row {
  border-top: 1px solid var(--border-subtle);
}

.config-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: var(--weight-medium);
}

.config-input {
  width: 200px;
  padding: var(--sp-sm) var(--sp-md) !important;
  font-size: var(--text-sm) !important;
  text-align: right;
  font-family: var(--font-mono);
}

/* ── Portal ─────────────────────────────────────────────────────────────── */
.portal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-lg) var(--sp-xl);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.portal-brand {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.portal-content {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-2xl) var(--sp-xl);
}

.portal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-xl);
  margin-bottom: var(--sp-xl);
}

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-xl);
  background: var(--bg-base);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-3xl);
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: var(--text-xl);
  text-align: center;
  margin-bottom: var(--sp-2xl);
}

.login-card .form-group {
  margin-bottom: var(--sp-xl);
}

.login-card label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--sp-sm);
}

.login-card .btn-primary {
  width: 100%;
  padding: var(--sp-lg);
  margin-top: var(--sp-md);
}

.login-error {
  padding: var(--sp-md) var(--sp-lg);
  background: var(--danger-subtle);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-xl);
}

.login-theme-toggle {
  position: fixed;
  top: var(--sp-xl);
  right: var(--sp-xl);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
}

.login-theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

/* ── Chart Containers ───────────────────────────────────────────────────── */
.chart-wrapper {
  position: relative;
  width: 100%;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-lg);
}

.chart-header select {
  width: auto;
  padding: var(--sp-xs) var(--sp-lg) !important;
  font-size: var(--text-xs) !important;
}

/* ── Chart Toolbar (pill tabs) ──────────────────────────────────────────── */
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  padding: var(--sp-2xs);
}

.chart-toolbar-btn {
  padding: var(--sp-xs) var(--sp-lg);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  white-space: nowrap;
}

.chart-toolbar-btn:hover {
  color: var(--text-primary);
}

.chart-toolbar-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Inline Legend ──────────────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--sp-xl);
  flex-wrap: wrap;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

/* ── Responsive Adjustments ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  .kpi-card {
    padding: var(--sp-lg);
  }
  .kpi-value {
    font-size: var(--text-xl);
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-bar input,
  .filter-bar select {
    width: 100%;
    min-width: 0;
  }
  .config-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-sm);
  }
  .config-input {
    width: 100% !important;
    text-align: left !important;
  }
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
}

@media (max-width: 575.98px) {
  .grid-6 {
    grid-template-columns: repeat(2, 1fr);
  }
  th, td {
    padding: var(--sp-sm) var(--sp-md);
    font-size: var(--text-xs);
  }
}
