/* ============================================================
   DATASAFER MONITOR — CoreTalk Design System Components
   Extraído de DESIGN.md + BOUND_DS.json + design-system.html
   Tokens CSS via var(--*); nunca hardcode cores, fontes ou radii.
   ============================================================ */

/* ============================================================
   CSS CUSTOM PROPERTIES (Tokens)
   ============================================================ */

:root {
  /* Brand */
  --brand-primary: #F4791F;
  --brand-secondary: #5A2C87;

  /* Palette */
  --orange-500: #FE7600;
  --orange-600: #F4791F;
  --purple-600: #5A2C87;
  --purple-700: #48226D;

  /* Ink */
  --ink-900: #0D0F20;
  --ink-800: #16182E;
  --ink-700: #1E2240;
  --ink-600: #2A2E4A;
  --ink-500: #6B6F8A;
  --ink-300: #9EA1B0;
  --ink-100: #C5C7D1;

  /* Cream */
  --cream-100: #FFFDF5;
  --cream-200: #FFFBE8;

  /* Status / Functional */
  --status-ok: #22C55E;
  --status-warn: #F59E0B;
  --status-crit: #EF4444;
  --status-info: #3B82F6;

  /* Typography */
  --font-display: 'Montserrat', sans-serif;
  --font-body: 'Mulish', sans-serif;

  /* Radii */
  --radius-2xl: 36px;
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-md: 0 4px 24px rgba(13, 15, 32, 0.4);
  --shadow-lg: 0 8px 32px rgba(13, 15, 32, 0.55);
  --shadow-orange: 0 0 20px rgba(244, 121, 31, 0.25);
  --shadow-purple: 0 0 20px rgba(90, 44, 135, 0.25);
  --shadow-focus: 0 0 0 3px rgba(244, 121, 31, 0.5);

  /* Motion */
  --dur-fast: 140ms;
  --dur-base: 220ms;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Spacing */
  --space-unit: 4px;
}

/* ============================================================
   THEME: DARK (default)
   ============================================================ */
[data-theme="dark"] {
  --bg-root: var(--ink-800);
  --bg-surface: var(--ink-700);
  --bg-card: var(--ink-600);
  --text-primary: #F0F0F5;
  --text-secondary: #9EA1B0;
  --text-muted: #6B6F8A;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-card: rgba(255, 255, 255, 0.10);
  --border-hover: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   THEME: LIGHT
   ============================================================ */
[data-theme="light"] {
  --bg-root: var(--cream-100);
  --bg-surface: #FFFFFF;
  --bg-card: #FFFFFF;
  --text-primary: var(--ink-800);
  --text-secondary: #595E75;
  --text-muted: #9EA1B0;
  --border-subtle: rgba(22, 24, 46, 0.08);
  --border-card: rgba(22, 24, 46, 0.10);
  --border-hover: rgba(22, 24, 46, 0.18);
}

/* ============================================================
   GLOBAL RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background var(--dur-base) ease, color var(--dur-base) ease;
  min-height: 100vh;
}

/* Focus Ring */
*:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: 4px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
.display-xl {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.display-lg {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.display-md {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
}

.heading-sm {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

.body-lg {
  font-family: var(--font-body);
  font-size: 1.0625rem;
  font-weight: 400;
}

.body-md {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 400;
}

.body-sm {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 400;
}

.caption {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-number {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

/* ============================================================
   LAYOUT UTILITIES
   ============================================================ */
.container-main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1rem;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.chart-wrap {
  position: relative;
  width: 100%;
}

.sparkline-wrap {
  position: relative;
  width: 100%;
  height: 40px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  transition: transform var(--dur-fast) ease, box-shadow var(--dur-base) ease;
  border: 1px solid var(--border-card);
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.card.alert-critical {
  box-shadow: var(--shadow-orange);
  border-left: 4px solid var(--status-crit);
}

.card.alert-warning {
  border-left: 4px solid var(--brand-primary);
}

.card-glow-orange {
  box-shadow: var(--shadow-orange);
}

.card-glow-purple {
  box-shadow: var(--shadow-purple);
}

.card-empty {
  text-align: center;
  padding: 3rem 1.5rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-spring);
  padding: 10px 24px;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  min-height: 44px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--brand-primary);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: var(--orange-500);
  box-shadow: var(--shadow-orange);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--brand-secondary);
  color: #FFFFFF;
}
.btn-secondary:hover {
  background: var(--purple-700);
  box-shadow: var(--shadow-purple);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1.5px solid var(--border-card);
}
.btn-outline:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 16px;
  font-size: 0.8125rem;
  min-height: 36px;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1rem;
  min-height: 52px;
}

.btn-icon {
  padding: 10px;
  min-width: 44px;
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.badge-ok {
  background: rgba(34, 197, 94, 0.15);
  color: var(--status-ok);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-warn);
}

.badge-crit {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-crit);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--status-info);
}

/* ============================================================
   STATUS DOTS
   ============================================================ */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.ok {
  background: var(--status-ok);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.status-dot.warn {
  background: var(--status-warn);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

.status-dot.crit {
  background: var(--status-crit);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

.status-dot.info {
  background: var(--status-info);
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.4);
}

/* ============================================================
   PROGRESS BAR
   ============================================================ */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border-subtle);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width var(--dur-base) ease;
}

.progress-bar-fill.ok {
  background: var(--status-ok);
}

.progress-bar-fill.warn {
  background: var(--status-warn);
}

.progress-bar-fill.crit {
  background: var(--status-crit);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-container::after {
  content: '';
  position: sticky;
  right: 0;
  top: 0;
  bottom: 0;
  width: 40px;
  background: linear-gradient(to right, transparent, var(--bg-card));
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast);
}

.table-container.is-scrollable::after {
  opacity: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--dur-fast);
}

thead th:hover {
  color: var(--text-primary);
}

thead th.sort-asc::after,
thead th.sort-desc::after {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.625rem;
}

thead th.sort-desc::after {
  content: '▼';
}

thead th.sort-asc::after {
  content: '▲';
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--dur-fast);
}

tbody tr:hover {
  background: var(--bg-surface);
}

/* Row status variants */
tr.row-crit {
  background: rgba(239, 68, 68, 0.08);
}
tr.row-crit:hover {
  background: rgba(239, 68, 68, 0.14);
}

tr.row-warn {
  background: rgba(245, 158, 11, 0.06);
}
tr.row-warn:hover {
  background: rgba(245, 158, 11, 0.12);
}

tr.row-info {
  background: rgba(59, 130, 246, 0.05);
}
tr.row-info:hover {
  background: rgba(59, 130, 246, 0.10);
}

/* Cell alignment helpers */
td.text-right, th.text-right {
  text-align: right;
}

td.text-center, th.text-center {
  text-align: center;
}

td.font-mono {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.8125rem;
}

/* ============================================================
   TABLE — RESPONSIVE (mobile card view)
   ============================================================ */
@media (max-width: 768px) {
  .table-responsive table,
  .table-responsive thead,
  .table-responsive tbody,
  .table-responsive th,
  .table-responsive td,
  .table-responsive tr {
    display: block;
  }

  .table-responsive thead {
    display: none;
  }

  .table-responsive tbody tr {
    margin-bottom: 1rem;
    border: 1px solid var(--border-card);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    background: var(--bg-card);
  }

  .table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-subtle);
    text-align: right;
  }

  .table-responsive td:last-child {
    border-bottom: none;
  }

  .table-responsive td::before {
    content: attr(data-label);
    font-family: var(--font-body);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    margin-right: 1rem;
  }

  .table-responsive td.font-mono {
    font-size: 0.875rem;
  }
}

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
}

.navbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--dur-fast);
}

.nav-brand:hover {
  color: var(--brand-primary);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--dur-fast);
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

.nav-tab.active {
  background: var(--brand-primary);
  color: #FFFFFF;
}

.nav-tab.active:hover {
  background: var(--orange-500);
}

/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--dur-fast);
  margin-left: 0.75rem;
}

.theme-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.page-subtitle {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ============================================================
   BACK LINK
   ============================================================ */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color var(--dur-fast);
  margin-bottom: 1.5rem;
}

.back-link:hover {
  color: var(--brand-primary);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}

.empty-state-icon {
  color: var(--text-muted);
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-text {
  color: var(--text-secondary);
  font-size: 0.9375rem;
}

/* ============================================================
   ALERT / ERROR BOX
   ============================================================ */
.alert-box {
  padding: 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
}

.alert-box-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--status-crit);
}

.alert-box-success {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--status-ok);
}

.alert-box-info {
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: var(--status-info);
}

/* ============================================================
   TOAST / NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-card);
  font-size: 0.875rem;
  animation: toast-in var(--dur-base) var(--ease-spring);
  max-width: 380px;
}

.toast-success {
  border-left: 4px solid var(--status-ok);
}

.toast-error {
  border-left: 4px solid var(--status-crit);
}

.toast-hidden {
  display: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   TEXT COLOR HELPERS
   ============================================================ */
.text-ok { color: var(--status-ok); }
.text-warn { color: var(--status-warn); }
.text-crit { color: var(--status-crit); }
.text-info { color: var(--status-info); }
.text-muted { color: var(--text-muted); }
.text-brand { color: var(--brand-primary); }

/* ============================================================
   SPACING HELPERS
   ============================================================ */
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

/* ============================================================
   GRID HELPERS
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; }

@media (max-width: 1024px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.animate-pulse-glow {
  animation: pulse-glow 2s ease-in-out infinite;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */
@media (max-width: 640px) {
  .page-title { font-size: 1.5rem; }
  .kpi-number { font-size: 1.5rem; }
  .display-xl { font-size: 1.75rem; }
}

/* ============================================================
   FORM CONTROLS
   ============================================================ */
.form-input {
  background: var(--surface-secondary, #1E2240);
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 10px;
  color: var(--text-primary, #F0F0F5);
  padding: 0.625rem 0.875rem;
  font-family: 'Mulish', sans-serif;
  font-size: 0.875rem;
  transition: border-color 0.2s;
}
.form-input:focus {
  outline: none;
  border-color: var(--brand-primary, #F4791F);
}
[data-theme="light"] .form-input {
  background: #FFFFFF;
  border-color: rgba(22, 24, 46, 0.12);
  color: #16182E;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.5rem 2rem;
  background: var(--surface-secondary, #1E2240);
  border: 1px solid var(--border-color, rgba(255,255,255,0.06));
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.4);
}
[data-theme="light"] .login-card {
  background: #FFFFFF;
  border-color: rgba(22, 24, 46, 0.08);
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
}
.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.login-title {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary, #F0F0F5);
  margin-top: 0.75rem;
}
.login-subtitle {
  font-family: 'Mulish', sans-serif;
  font-size: 0.875rem;
  color: var(--text-muted, #9EA1B0);
  margin-top: 0.25rem;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.input-icon-wrap {
  position: relative;
}
.input-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #9EA1B0);
  pointer-events: none;
}
.form-input-icon {
  padding-left: 2.5rem !important;
}
.login-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem;
  font-size: 1rem;
  margin-top: 0.5rem;
}
.login-card .form-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 0.875rem;
}
