/* ============================================================
   VASAP Design System — Components
   All colors via tokens. No hardcoded hex/rgb in this file.
   ============================================================ */

/* ============================================================
   App shell — header
   ============================================================ */
.ds-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 48px;
  padding: 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
}
.ds-header__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-bold);
  font-size: var(--fs-md);
  color: var(--text);
  letter-spacing: 0.4px;
}
.ds-header__brand-mark {
  color: var(--primary);
}
.ds-header__divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}
.ds-header__title {
  font-size: var(--fs-base);
  color: var(--text-2);
  font-weight: var(--fw-medium);
}
.ds-header__spacer { flex: 1; }
.ds-header__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.ds-header__user {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  font-size: var(--fs-sm);
  color: var(--text-2);
}

/* ============================================================
   App shell — sidebar (56px icon rail)
   ============================================================ */
.ds-sidebar {
  width: 56px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-3) 0;
  gap: var(--sp-1);
  position: sticky;
  top: 48px;
  height: calc(100vh - 48px);
  z-index: var(--z-sidebar);
}
.ds-sidebar__item {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  color: var(--text-3);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--motion-fast) var(--easing), color var(--motion-fast) var(--easing);
}
.ds-sidebar__item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.ds-sidebar__item--active {
  color: var(--primary);
  background: var(--primary-soft);
}
.ds-sidebar__item--active::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: var(--r-pill);
}

/* ============================================================
   Cards / panels
   ============================================================ */
.ds-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.ds-card-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-base);
  font-weight: var(--fw-semi);
  color: var(--text);
  background: var(--surface);
}
.ds-card-head__icon {
  color: var(--text-2);
  font-size: 18px;
}
.ds-card-head__title { flex: 1; }
.ds-card-head__actions {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.ds-card-body {
  padding: var(--sp-4);
}
.ds-card-body--flush {
  padding: 0;
}
.ds-card-foot {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  background: var(--surface-sunken);
}

/* ============================================================
   Buttons
   ============================================================ */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: var(--btn-h);
  min-width: var(--btn-h);
  padding: 0 var(--pad-x);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background var(--motion-fast) var(--easing),
              border-color var(--motion-fast) var(--easing),
              color var(--motion-fast) var(--easing);
}
.ds-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-3);
}
.ds-btn:active:not(:disabled) {
  background: var(--surface-sunken);
}
.ds-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.ds-btn .material-symbols-outlined {
  font-size: 18px;
}

.ds-btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.ds-btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.ds-btn-primary:active:not(:disabled) {
  background: var(--primary-hover);
}

.ds-btn-success {
  background: var(--st-ok);
  border-color: var(--st-ok);
  color: #fff;
}
.ds-btn-success:hover:not(:disabled) { filter: brightness(0.92); }

.ds-btn-danger {
  background: var(--st-crit);
  border-color: var(--st-crit);
  color: #fff;
}
.ds-btn-danger:hover:not(:disabled) { filter: brightness(0.92); }

.ds-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.ds-btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.ds-btn-sm {
  height: var(--btn-h-sm);
  min-width: var(--btn-h-sm);
  padding: 0 var(--sp-2);
  font-size: var(--fs-sm);
}
.ds-btn-icon {
  padding: 0;
  width: var(--btn-h);
  min-width: var(--btn-h);
}
.ds-btn-block { width: 100%; }

/* ============================================================
   Form inputs / fields
   ============================================================ */
.ds-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.ds-field__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ds-field__hint {
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.ds-field__error {
  font-size: var(--fs-xs);
  color: var(--st-crit);
}

.ds-input,
.ds-select,
.ds-textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  transition: border-color var(--motion-fast) var(--easing),
              box-shadow var(--motion-fast) var(--easing);
  outline: none;
}
.ds-textarea {
  height: auto;
  min-height: calc(var(--control-h) * 2.5);
  padding: var(--sp-2) var(--sp-3);
  line-height: 1.5;
  resize: vertical;
}
.ds-input::placeholder,
.ds-textarea::placeholder {
  color: var(--text-3);
}
.ds-input:focus,
.ds-select:focus,
.ds-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.ds-input:disabled,
.ds-select:disabled,
.ds-textarea:disabled {
  background: var(--surface-sunken);
  color: var(--text-disabled);
  cursor: not-allowed;
}
.ds-input--num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Search input with leading icon */
.ds-search {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 100%;
}
.ds-search .material-symbols-outlined {
  position: absolute;
  left: var(--sp-3);
  color: var(--text-3);
  font-size: 18px;
  pointer-events: none;
}
.ds-search .ds-input {
  padding-left: calc(var(--sp-3) + 22px);
}

/* ============================================================
   Tabs
   ============================================================ */
.ds-tabs {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
}
.ds-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-3);
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--motion-fast) var(--easing),
              border-color var(--motion-fast) var(--easing);
}
.ds-tab:hover { color: var(--text); }
.ds-tab--active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.ds-tab__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums;
}
.ds-tab--active .ds-tab__badge {
  background: var(--primary-soft);
  color: var(--primary);
}

/* ============================================================
   Tables
   ============================================================ */
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}
.ds-table th,
.ds-table td {
  padding: 0 var(--sp-3);
  height: var(--row-h);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ds-table th {
  font-weight: var(--fw-semi);
  color: var(--text-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border-strong);
  position: sticky;
  top: 0;
  z-index: 1;
}
.ds-table tbody tr:hover {
  background: var(--surface-hover);
}
.ds-table tbody tr:last-child td {
  border-bottom: none;
}
.ds-table .num-cell {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.ds-table .center-cell { text-align: center; }

/* ============================================================
   Badges (status)
   ============================================================ */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  height: 22px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  letter-spacing: 0.3px;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.ds-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.ds-badge-ok       { background: var(--st-ok-soft);       color: var(--st-ok);       border-color: transparent; }
.ds-badge-info     { background: var(--st-info-soft);     color: var(--st-info);     border-color: transparent; }
.ds-badge-warn     { background: var(--st-warn-soft);     color: var(--st-warn);     border-color: transparent; }
.ds-badge-degraded { background: var(--st-degraded-soft); color: var(--st-degraded); border-color: transparent; }
.ds-badge-crit     { background: var(--st-crit-soft);     color: var(--st-crit);     border-color: transparent; }
.ds-badge-offline  { background: var(--st-offline-soft);  color: var(--st-offline);  border-color: transparent; }

/* ============================================================
   KPI tile
   ============================================================ */
.ds-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.ds-kpi__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ds-kpi__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-3xl);
  font-weight: var(--fw-semi);
  color: var(--text);
  line-height: 1;
}
.ds-kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums;
}
.ds-kpi__delta--up   { color: var(--st-ok); }
.ds-kpi__delta--down { color: var(--st-crit); }
.ds-kpi__meta {
  font-size: var(--fs-xs);
  color: var(--text-3);
}
.ds-kpi__bar {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  overflow: hidden;
}
.ds-kpi__bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-pill);
}
.ds-kpi__bar-fill--ok       { background: var(--st-ok); }
.ds-kpi__bar-fill--warn     { background: var(--st-warn); }
.ds-kpi__bar-fill--degraded { background: var(--st-degraded); }
.ds-kpi__bar-fill--crit     { background: var(--st-crit); }

/* ============================================================
   Equipment status card (.ds-eq)
   Status conveyed via left bar + badge — never color alone.
   ============================================================ */
.ds-eq {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4) var(--sp-3) calc(var(--sp-4) + 4px);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  overflow: hidden;
}
.ds-eq::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--st-offline);
}
.ds-eq__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.ds-eq__name {
  font-weight: var(--fw-semi);
  color: var(--text);
}
.ds-eq__rows {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-1) var(--sp-3);
  font-size: var(--fs-sm);
}
.ds-eq__row-label { color: var(--text-3); }
.ds-eq__row-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
}

.ds-eq--ok::before       { background: var(--st-ok); }
.ds-eq--info::before     { background: var(--st-info); }
.ds-eq--warn::before     { background: var(--st-warn); }
.ds-eq--degraded::before { background: var(--st-degraded); }
.ds-eq--crit::before     { background: var(--st-crit); }
.ds-eq--offline::before  { background: var(--st-offline); }

/* ============================================================
   Toolbar
   ============================================================ */
.ds-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  flex-wrap: wrap;
}
.ds-toolbar__label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ds-toolbar__sep {
  width: 1px;
  height: 22px;
  background: var(--border);
}
.ds-toolbar__spacer { flex: 1; }

/* ============================================================
   Modal
   ============================================================ */
.ds-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 36, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--sp-4);
}
.ds-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ds-modal-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-weight: var(--fw-semi);
  font-size: var(--fs-md);
}
.ds-modal-head__icon {
  font-size: 22px;
  color: var(--text-2);
}
.ds-modal-head--warn   { background: var(--st-warn-soft); color: var(--st-warn); }
.ds-modal-head--warn   .ds-modal-head__icon { color: var(--st-warn); }
.ds-modal-head--danger { background: var(--st-crit-soft); color: var(--st-crit); }
.ds-modal-head--danger .ds-modal-head__icon { color: var(--st-crit); }
.ds-modal-body {
  padding: var(--sp-4);
  overflow: auto;
  flex: 1;
}
.ds-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
}

/* ============================================================
   Source indicator (data lineage)
   ============================================================ */
.ds-source {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  font-size: var(--fs-xs);
  color: var(--text-2);
  font-weight: var(--fw-medium);
  border: 1px solid var(--border);
}
.ds-source__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--st-ok);
}
.ds-source--stale .ds-source__dot   { background: var(--st-warn); }
.ds-source--offline .ds-source__dot { background: var(--st-offline); }
.ds-source__label {
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}
.ds-source__latency {
  font-family: var(--font-mono);
  color: var(--text-3);
}

/* ============================================================
   Alert / notice (inline)
   ============================================================ */
.ds-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.ds-alert .material-symbols-outlined {
  font-size: 20px;
  flex-shrink: 0;
}
.ds-alert-info     { background: var(--st-info-soft);     color: var(--st-info);     border-color: transparent; }
.ds-alert-warn     { background: var(--st-warn-soft);     color: var(--st-warn);     border-color: transparent; }
.ds-alert-degraded { background: var(--st-degraded-soft); color: var(--st-degraded); border-color: transparent; }
.ds-alert-crit     { background: var(--st-crit-soft);     color: var(--st-crit);     border-color: transparent; }
.ds-alert-ok       { background: var(--st-ok-soft);       color: var(--st-ok);       border-color: transparent; }

/* ============================================================
   Layout helpers
   ============================================================ */
.ds-app {
  display: grid;
  grid-template-columns: 56px 1fr;
  min-height: 100vh;
}
.ds-app--no-sidebar {
  grid-template-columns: 1fr;
}
.ds-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.ds-content {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* Spinner */
@keyframes ds-spin { to { transform: rotate(360deg); } }
.ds-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: ds-spin 0.7s linear infinite;
}

/* Visually-hidden utility (a11y) */
.ds-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
