/* ==========================================================================
   Blink Dashboard — dashboard.css
   Client-facing dashboard for monitoring gateway, tasks, and security events.
   Uses design tokens from tokens.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Page-Level Overrides
   -------------------------------------------------------------------------- */

body {
  cursor: auto;
}

/* --------------------------------------------------------------------------
   1. Connection Bar
   -------------------------------------------------------------------------- */

.dash-connection {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  margin-top: 70px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.dash-connection__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
}

.dash-connection input,
.dash-input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast);
}

.dash-connection input:focus {
  outline: none;
  border-color: var(--brand-accent);
}

.dash-connection input::placeholder {
  color: var(--text-muted);
}

.dash-connection button {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-5);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--bg-dark);
  background: var(--brand-accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity var(--duration-fast);
}

.dash-connection button:hover {
  opacity: 0.85;
}

.dash-connection button:active {
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   2. Status Dot (Connection Indicator)
   -------------------------------------------------------------------------- */

.dash-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #8B8272;
  transition: background var(--duration-fast);
}

.dash-status-dot--connected {
  background: #22c55e;
}

.dash-status-dot--error {
  background: #ef4444;
}

.dash-status-dot--disconnected {
  background: #8B8272;
}

/* --------------------------------------------------------------------------
   3. Tab Bar
   -------------------------------------------------------------------------- */

.dash-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
}

.dash-tabs button,
.dash-tab {
  position: relative;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast);
}

.dash-tabs button:hover,
.dash-tab:hover {
  color: var(--text-primary);
}

.dash-tabs button.active,
.dash-tab.active,
.dash-tabs button[aria-selected="true"] {
  color: var(--text-primary);
  font-weight: 600;
  border-bottom-color: var(--brand-accent);
}

/* --------------------------------------------------------------------------
   4. Empty State
   -------------------------------------------------------------------------- */

.dash-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 480px;
  margin: var(--space-8) auto;
  padding: var(--space-6);
  text-align: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.dash-empty[hidden] {
  display: none;
}

.dash-empty__icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  color: var(--text-muted);
  opacity: 0.5;
}

.dash-empty h3 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dash-empty p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   5. Panel Container
   -------------------------------------------------------------------------- */

.dash-panel {
  padding: var(--space-4) var(--space-6);
}

.dash-panel[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   6. KPI Grid
   -------------------------------------------------------------------------- */

.dash-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.dash-kpi,
.dash-kpi-card {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  transition: box-shadow var(--duration-fast);
}

.dash-kpi:hover,
.dash-kpi-card:hover {
  box-shadow: var(--shadow-sm);
}

.dash-kpi__label,
.dash-kpi-card__label {
  display: block;
  margin-bottom: var(--space-1);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.dash-kpi__value,
.dash-kpi-card__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.dash-kpi__change {
  display: inline-block;
  margin-top: var(--space-1);
  font-size: 0.8125rem;
  font-weight: 500;
}

.dash-kpi__change--positive {
  color: #22c55e;
}

.dash-kpi__change--negative {
  color: #ef4444;
}

/* --------------------------------------------------------------------------
   7. Generic Card
   -------------------------------------------------------------------------- */

.dash-card {
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.dash-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.dash-card__title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* When title is used without header wrapper */
.dash-card > .dash-card__title {
  margin-bottom: var(--space-4);
}

.dash-card--half {
  flex: 1 1 calc(50% - var(--space-2));
  min-width: 0;
}

/* --------------------------------------------------------------------------
   8. Row Layout (Side-by-Side Cards)
   -------------------------------------------------------------------------- */

.dash-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

/* --------------------------------------------------------------------------
   9. Refresh Button
   -------------------------------------------------------------------------- */

.dash-refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.dash-refresh-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   10. Services Grid
   -------------------------------------------------------------------------- */

.dash-services {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}

.dash-service {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.dash-service__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #8B8272;
}

.dash-service[data-status="ok"] .dash-service__dot {
  background: #22c55e;
}

.dash-service[data-status="degraded"] .dash-service__dot {
  background: #f59e0b;
}

.dash-service[data-status="off"] .dash-service__dot {
  background: #8B8272;
}

.dash-service__name {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   11. Data Table
   -------------------------------------------------------------------------- */

.dash-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dash-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.dash-table thead th {
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.dash-table tbody td {
  padding: var(--space-3);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.dash-table tbody tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.015);
}

.dash-table tbody tr:hover {
  background: rgba(0, 0, 0, 0.03);
}

/* --------------------------------------------------------------------------
   12. Task Status Badges
   -------------------------------------------------------------------------- */

.dash-status {
  display: inline-block;
  padding: 2px var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.dash-status--completed {
  color: #166534;
  background: rgba(34, 197, 94, 0.15);
}

.dash-status--failed {
  color: #991b1b;
  background: rgba(239, 68, 68, 0.15);
}

.dash-status--processing {
  color: #92400e;
  background: rgba(245, 158, 11, 0.15);
  animation: dash-pulse 2s ease-in-out infinite;
}

.dash-status--pending {
  color: #5c5347;
  background: rgba(139, 130, 114, 0.15);
}

@keyframes dash-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* --------------------------------------------------------------------------
   13. Security Events List
   -------------------------------------------------------------------------- */

.dash-events-list {
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.dash-events-list::-webkit-scrollbar {
  width: 6px;
}

.dash-events-list::-webkit-scrollbar-track {
  background: transparent;
}

.dash-events-list::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

.dash-event {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.dash-event:last-child {
  border-bottom: none;
}

.dash-event__time {
  flex-shrink: 0;
  min-width: 80px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.dash-event__severity {
  flex-shrink: 0;
  display: inline-block;
  padding: 1px var(--space-2);
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.dash-event__severity--critical {
  background: #ef4444;
}

.dash-event__severity--high {
  background: #f59e0b;
}

.dash-event__severity--medium {
  background: #eab308;
  color: #1A1A1A;
}

.dash-event__severity--low {
  background: #3b82f6;
}

.dash-event__type {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dash-event__detail {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   14. Error Banner
   -------------------------------------------------------------------------- */

.dash-error {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: 0.875rem;
  color: #991b1b;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
}

.dash-error[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   15. Onboarding Hints
   -------------------------------------------------------------------------- */

.dash-hint-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: var(--space-1);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  cursor: pointer;
  vertical-align: middle;
  transition: color var(--duration-fast), border-color var(--duration-fast), background var(--duration-fast);
  position: relative;
  flex-shrink: 0;
}

.dash-hint-btn:hover {
  color: var(--text-primary);
  border-color: var(--brand-accent);
  background: var(--bg-surface);
}

.dash-hint {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: 280px;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-dark);
  color: var(--text-light);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.5;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.dash-hint::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid var(--bg-dark);
}

.dash-hint-btn.active .dash-hint {
  display: block;
}

/* Align left when hint would overflow right edge */
.dash-hint--left {
  left: 0;
  transform: none;
}
.dash-hint--left::before {
  left: 9px;
  transform: none;
}

/* Align right when hint would overflow left edge */
.dash-hint--right {
  left: auto;
  right: 0;
  transform: none;
}
.dash-hint--right::before {
  left: auto;
  right: 9px;
  transform: none;
}

.dash-hint a {
  color: var(--brand-accent);
  text-decoration: none;
  font-weight: 500;
}

.dash-hint a:hover {
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   16. Chart Containers
   -------------------------------------------------------------------------- */

.dash-chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}

.dash-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* --------------------------------------------------------------------------
   16. Responsive — Tablet (max-width: 1024px)
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .dash-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .dash-card--half {
    flex: 1 1 100%;
  }
}

@media (max-width: 768px) {
  .dash-services {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --------------------------------------------------------------------------
   17. Responsive — Mobile (max-width: 640px)
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .dash-connection {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
  }

  .dash-connection__row {
    flex-direction: column;
    align-items: stretch;
  }

  .dash-connection input,
  .dash-input {
    flex: none;
    width: 100%;
  }

  .dash-connection button {
    width: 100%;
    text-align: center;
  }

  .dash-tabs {
    gap: var(--space-3);
    padding: 0 var(--space-3);
    overflow-x: auto;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
  }

  .dash-tabs button {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .dash-panel {
    padding: var(--space-4);
  }

  .dash-kpis {
    grid-template-columns: 1fr;
  }

  .dash-services {
    grid-template-columns: 1fr;
  }

  .dash-row {
    flex-direction: column;
  }

  .dash-card--half {
    flex: 1 1 100%;
  }

  .dash-table-wrap {
    margin: 0 calc(-1 * var(--space-4));
    padding: 0 var(--space-4);
  }

  .dash-chart-wrap {
    height: 200px;
  }

  .dash-event {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .dash-event__detail {
    flex-basis: 100%;
  }
}

/* --------------------------------------------------------------------------
   19. Panel Navbar Override
   -------------------------------------------------------------------------- */

.navbar.navbar--panel {
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-3) 0;
}

/* --------------------------------------------------------------------------
   20. Panel Eye Logo
   -------------------------------------------------------------------------- */

.nav-logo-link--eye {
  display: flex;
  align-items: center;
}

.nav-eye {
  width: 40px;
  height: 40px;
  object-fit: contain;
  transition: transform var(--duration-normal) var(--ease-spring),
              opacity var(--duration-fast);
}

.nav-logo-link--eye:hover .nav-eye {
  transform: scale(1.1);
  opacity: 0.85;
}

/* --------------------------------------------------------------------------
   21. Calm-Tech Card Animations
   -------------------------------------------------------------------------- */

@keyframes dash-fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dash-kpi-card,
.dash-card {
  animation: dash-fadeIn var(--duration-slow) var(--ease-out) both;
}

.dash-kpi-card:nth-child(1) { animation-delay: 0ms; }
.dash-kpi-card:nth-child(2) { animation-delay: 60ms; }
.dash-kpi-card:nth-child(3) { animation-delay: 120ms; }
.dash-kpi-card:nth-child(4) { animation-delay: 180ms; }
.dash-kpi-card:nth-child(5) { animation-delay: 240ms; }

/* Subtle hover lift on cards */
.dash-card {
  transition: box-shadow var(--duration-normal) var(--ease-out),
              transform var(--duration-normal) var(--ease-out);
}

.dash-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* KPI value count-up feel */
.dash-kpi-card__value {
  transition: color var(--duration-normal);
}

/* --------------------------------------------------------------------------
   22. Chart View Modes (Simple / Detailed)
   -------------------------------------------------------------------------- */

.dash-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.dash-view-toggle {
  display: inline-flex;
  gap: 0;
  margin-left: auto;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.dash-view-btn {
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.dash-view-btn:hover {
  color: var(--text-primary);
}

.dash-view-btn.active {
  background: var(--brand-accent);
  color: var(--bg-dark);
}

/* --------------------------------------------------------------------------
   23. Eye Watermark Detail
   -------------------------------------------------------------------------- */

.dash-empty__icon {
  animation: dash-blink 4s var(--ease-smooth) infinite;
}

@keyframes dash-blink {
  0%, 90%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(0.1); }
}

/* --------------------------------------------------------------------------
   24. Connection Status Animation
   -------------------------------------------------------------------------- */

.dash-status-dot--connected {
  animation: dash-breathe 3s ease-in-out infinite;
}

@keyframes dash-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}
