/* ===========================================================================
 * SecureSense IoT - Dashboard stylesheet
 * Paleta, tipografia y layout segun especificacion del TFM.
 * No se utilizan animaciones decorativas: solo transiciones funcionales.
 * ========================================================================= */

/* --- Fonts ---------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/Inter-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/Inter-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/Inter-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/Inter-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --- Tokens -------------------------------------------------------------- */

:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-elev: #243247;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.12);
  --divider: rgba(148, 163, 184, 0.08);

  --ok: #10b981;
  --warn: #f59e0b;
  --crit: #ef4444;
  --accent: #06b6d4;

  --chart-temp: #f59e0b;
  --chart-hum: #06b6d4;
  --chart-pm: #a78bfa;

  --radius-card: 12px;
  --radius-badge: 6px;
  --radius-btn: 8px;

  --gap: 24px;

  --t-fast: 150ms ease;
  --t-med: 200ms ease;
  --t-slow: 300ms ease;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* --- Reset --------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1,
h2,
p,
ul {
  margin: 0;
  padding: 0;
}

ul {
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- Icons --------------------------------------------------------------- */

.icon-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  color: var(--muted);
  stroke-width: 2;
  flex-shrink: 0;
}
.icon--xs {
  width: 14px;
  height: 14px;
}
.icon--sm {
  width: 18px;
  height: 18px;
}
.icon--brand {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

/* --- Header -------------------------------------------------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 16px 32px;
  min-height: 70px;
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand__text {
  display: flex;
  flex-direction: column;
}
.brand__title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.brand__subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.app-header__meta {
  display: flex;
  align-items: center;
  gap: 20px;
}

.global-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color var(--t-slow);
}
.global-status__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  transition: background-color var(--t-slow);
}
.global-status[data-status="OK"] .global-status__dot {
  background: var(--ok);
}
.global-status[data-status="WARNING"] .global-status__dot {
  background: var(--warn);
}
.global-status[data-status="CRITICAL"] .global-status__dot {
  background: var(--crit);
}
.global-status[data-status="OK"] {
  color: var(--ok);
}
.global-status[data-status="WARNING"] {
  color: var(--warn);
}
.global-status[data-status="CRITICAL"] {
  color: var(--crit);
}

.clock {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.clock__value {
  color: var(--text);
  font-weight: 500;
}

/* --- Main layout --------------------------------------------------------- */

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap) 32px 32px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* --- Sensor cards -------------------------------------------------------- */

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

.sensor-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 24px;
  border-top: 3px solid var(--muted);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-top-color var(--t-slow);
}
.sensor-card[data-status="OK"] {
  border-top-color: var(--ok);
}
.sensor-card[data-status="WARNING"] {
  border-top-color: var(--warn);
}
.sensor-card[data-status="CRITICAL"] {
  border-top-color: var(--crit);
}

.sensor-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sensor-card__title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.sensor-card__name {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.sensor-card__value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
}
.value {
  font-size: 52px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: opacity var(--t-fast);
}
.value.pulse {
  opacity: 0.6;
}
.unit {
  font-size: 20px;
  font-weight: 400;
  color: var(--muted);
}

.sparkline {
  width: 100%;
  height: 40px;
  display: block;
}

.sensor-card__time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --- Badge --------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-badge);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #0b1220;
  background: var(--ok);
  transition: background-color var(--t-slow);
}
.badge .icon {
  color: currentColor;
}
.badge--ok {
  background: var(--ok);
  color: #062b21;
}
.badge--warn {
  background: var(--warn);
  color: #3a2604;
}
.badge--crit {
  background: var(--crit);
  color: #3a0b0b;
}

/* --- Unified chart panel ------------------------------------------------- */

.chart-panel {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 20px 24px 24px;
}
.chart-panel__inner {
  position: relative;
  width: 100%;
  height: 280px;
}

/* --- Bottom panels ------------------------------------------------------- */

.bottom {
  display: grid;
  grid-template-columns: 60% 1fr;
  gap: var(--gap);
}

.log-panel,
.controls-panel {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--divider);
}
.panel-header__title {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- Events log ---------------------------------------------------------- */

.events {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  padding-right: 4px;
}
.events::-webkit-scrollbar {
  width: 8px;
}
.events::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 4px;
}
.events__empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 0;
}

.event {
  display: grid;
  grid-template-columns: 12px 80px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--divider);
  font-size: 13px;
}
.event:last-child {
  border-bottom: 0;
}
.event__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
}
.event[data-status="OK"] .event__dot {
  background: var(--ok);
}
.event[data-status="WARNING"] .event__dot {
  background: var(--warn);
}
.event[data-status="CRITICAL"] .event__dot {
  background: var(--crit);
}
.event__time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.event__message {
  color: var(--text);
}
.event__sensor {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.08);
}

@keyframes event-enter {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.event--new {
  animation: event-enter var(--t-med);
}

/* --- Controls ------------------------------------------------------------ */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--text);
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: background-color var(--t-fast), border-color var(--t-fast);
}
.btn .icon {
  color: var(--accent);
}
.btn:hover,
.btn:focus-visible {
  background-color: color-mix(in srgb, var(--accent) 15%, transparent);
}

.controls__note {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 1024px) {
  .app-header {
    padding: 14px 20px;
  }
  .app-main {
    padding: 20px;
    gap: 20px;
  }
  .bottom {
    grid-template-columns: 65% 1fr;
  }
}

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
  }
  .app-header__meta {
    width: 100%;
    justify-content: space-between;
  }
  .app-main {
    padding: 16px;
    gap: 16px;
  }
  .sensors {
    grid-template-columns: 1fr;
  }
  .value {
    font-size: 48px;
  }
  .chart-panel__inner {
    height: 200px;
  }
  .bottom {
    grid-template-columns: 1fr;
  }
  .log-panel,
  .controls-panel {
    min-height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
