/**
 * ALKARA FLEETFMS — Cost Parameter UI Stylesheet (OFALabs Guidelines)
 * Phase P6.7 Canonical Cost Parameter Migration
 */

/* Design tokens (colors/fonts/radii) are inherited from the global stylesheet
   /_next/static/chunks/1t4aoiqub9ec4.css; local aliases below map page-level
   names onto the global tokens — do not hardcode hex values here. */
:root {
  --c-bg: var(--c-surface);
  --c-card: var(--c-white);
  --c-border-subtle: var(--c-surface2);
  --c-text-main: var(--c-text);
  --c-text-sub: var(--c-sub);
  --c-text-muted: var(--c-muted);
  --c-primary: var(--c-accent);
  --c-primary-hover: var(--c-accent2);
  --c-success: var(--c-loading);
  --c-success-bg: #dcfce7;
  --c-danger: var(--c-error);
  --c-danger-bg: #fee2e2;
  --c-warn: var(--c-dumping);
  --c-warn-bg: #fef9c3;
  --radius-card: var(--radius-md);
  --radius-btn: var(--radius-sm);
  --radius-pill: 99px;
}

.cost-page {
  padding: 24px;
  max-width: 1440px;
  margin: 0 auto;
  font-family: var(--font-sans);
  color: var(--c-text-main);
  background: var(--c-bg);
  min-height: 100vh;
}

/* Header & Status */
.cost-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.cost-title-group h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text-main);
  margin: 0 0 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cost-title-group p {
  font-size: 13px;
  color: var(--c-text-sub);
  margin: 0;
}

.cost-status-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cost-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border: 1px solid transparent;
}

.cost-status-pill[data-tone="live"] {
  background: var(--c-success-bg);
  color: var(--c-success);
  border-color: #bbf7d0;
}

.cost-status-pill[data-tone="reconnecting"] {
  background: var(--c-warn-bg);
  color: var(--c-warn);
  border-color: #fef08a;
}

.cost-status-pill[data-tone="offline"] {
  background: var(--c-danger-bg);
  color: var(--c-danger);
  border-color: #fecaca;
}

.cost-status-pill[data-role="admin"] {
  background: #eff6ff;
  color: var(--c-accent2);
  border-color: #bfdbfe;
}

.cost-status-pill[data-role="engineer"] {
  background: #f5f3ff;
  color: #6d28d9;
  border-color: #ddd6fe;
}

.cost-status-pill[data-role="viewer"] {
  background: var(--c-surface2);
  color: var(--c-queuing);
  border-color: var(--c-border);
}

.cost-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Metrics Grid */
.cost-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.cost-metric-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 16px 20px;
}

.cost-metric-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.cost-metric-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-text-main);
  font-family: var(--font-mono);
}

.cost-metric-sub {
  font-size: 11.5px;
  color: var(--c-text-muted);
  margin-top: 4px;
}

/* Controls Bar */
.cost-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 12px 16px;
  margin-bottom: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.cost-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  padding: 6px 12px;
  min-width: 280px;
}

.cost-search-box input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--c-text-main);
  width: 100%;
}

.cost-category-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cost-filter-btn {
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-sub);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cost-filter-btn:hover {
  background: var(--c-bg);
  color: var(--c-text-main);
}

.cost-filter-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: var(--c-white);
  font-weight: 600;
}

/* Main Layout & Table */
.cost-main-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  margin-bottom: 24px;
}

.cost-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-white);
}

.cost-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cost-action-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-btn);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.cost-btn-primary {
  background: var(--c-primary);
  color: var(--c-white);
}

.cost-btn-primary:hover:not(:disabled) {
  background: var(--c-primary-hover);
}

.cost-btn-primary:disabled {
  background: var(--c-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

.cost-btn-secondary {
  background: var(--c-white);
  border-color: var(--c-border);
  color: var(--c-text-sub);
}

.cost-btn-secondary:hover:not(:disabled) {
  background: var(--c-bg);
  color: var(--c-text-main);
}

.cost-btn-danger {
  background: var(--c-white);
  border-color: #fecaca;
  color: var(--c-danger);
}

.cost-btn-danger:hover {
  background: var(--c-danger-bg);
}

.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.cost-table th {
  background: var(--c-bg);
  color: var(--c-text-sub);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
}

.cost-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border-subtle);
  vertical-align: middle;
}

.cost-table tr:hover {
  background: #fbfcfe;
}

.cost-table tr.dirty-row {
  background: #fffbeb;
}

.cost-param-key {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-main);
}

.cost-param-desc {
  font-size: 12px;
  color: var(--c-text-sub);
  margin-top: 2px;
}

.cost-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cost-number-input {
  width: 130px;
  padding: 6px 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--c-text-main);
  background: var(--c-white);
  text-align: right;
  outline: none;
  transition: border-color 0.15s ease;
}

.cost-number-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 1px var(--c-primary);
}

.cost-number-input.is-dirty {
  border-color: #f59e0b;
  background: #fffdf5;
}

.cost-number-input.is-invalid {
  border-color: var(--c-danger);
  background: #fff5f5;
}

.cost-unit-label {
  font-size: 12px;
  color: var(--c-text-sub);
  font-weight: 500;
}

.cost-delta-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
}

.cost-delta-badge.pos {
  background: var(--c-success-bg);
  color: var(--c-success);
}

.cost-delta-badge.neg {
  background: var(--c-danger-bg);
  color: var(--c-danger);
}

.cost-delta-badge.zero {
  background: var(--c-border-subtle);
  color: var(--c-text-sub);
}

/* Category Badges */
.cost-category-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}

/* Toast Notifications */
.cost-toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.cost-toast {
  padding: 12px 18px;
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  animation: slideInToast 0.2s ease-out;
}

.cost-toast-success {
  background: var(--c-loading);
  color: var(--c-white);
}

.cost-toast-error {
  background: var(--c-error);
  color: var(--c-white);
}

.cost-toast-info {
  background: var(--c-text);
  color: var(--c-white);
}

@keyframes slideInToast {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Audit History Drawer */
.cost-audit-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-top: 24px;
}

.cost-audit-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--c-text-main);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
  .cost-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .cost-page {
    padding: 16px;
  }
  .cost-metrics-grid {
    grid-template-columns: 1fr;
  }
  .cost-controls-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .cost-search-box {
    min-width: 100%;
  }
  .cost-card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .cost-action-group {
    justify-content: flex-end;
  }
  .cost-table {
    display: block;
    overflow-x: auto;
  }
}
