:root {
  --bg-main: #0a0d14;
  --bg-surface: #111622;
  --bg-card: #171e2e;
  --bg-card-hover: #1e273b;
  --border-color: #232d42;
  --border-subtle: #1c2436;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --color-red: #ef4444;
  --color-red-dark: #b91c1c;
  --color-red-glow: rgba(239, 68, 68, 0.25);

  --color-black: #1e293b;
  --color-black-border: #334155;
  --color-black-glow: rgba(30, 41, 59, 0.4);

  --color-white: #f8fafc;
  --color-white-accent: #e2e8f0;
  --color-white-glow: rgba(248, 250, 252, 0.25);

  --color-accent: #3b82f6;
  --color-accent-hover: #2563eb;
  --color-success: #10b981;
  --color-warning: #f59e0b;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 16px;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: linear-transient(135deg, #1e293b, #0f172a);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--color-accent);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.game-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
}

.selector-label {
  color: var(--text-muted);
  font-weight: 600;
}

.selector-value {
  color: var(--color-accent);
  font-weight: 700;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-success);
  box-shadow: 0 0 10px var(--color-success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

.auto-refresh-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.switch-container {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch-container input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border-color);
  transition: 0.25s;
  border-radius: 20px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s;
  border-radius: 50%;
}

input:checked + .switch-slider {
  background-color: var(--color-accent);
}

input:checked + .switch-slider:before {
  transform: translateX(16px);
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-action:hover {
  background-color: var(--color-accent-hover);
}

.btn-action:active {
  transform: translateY(1px);
}

.btn-action.secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.btn-action.secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Window Bar */
.window-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.window-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-right: 4px;
}

.tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab-btn.active {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
  font-weight: 600;
}

.last-updated {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: #3b4d6b;
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.kpi-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.kpi-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.kpi-tag.info { background: rgba(59, 130, 246, 0.15); color: var(--color-accent); }
.kpi-tag.red { background: rgba(239, 68, 68, 0.2); color: var(--color-red); }
.kpi-tag.black { background: rgba(148, 163, 184, 0.2); color: var(--text-secondary); }
.kpi-tag.white { background: rgba(248, 250, 252, 0.2); color: var(--color-white); }
.kpi-tag.streak { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.kpi-tag.delay { background: rgba(16, 185, 129, 0.15); color: var(--color-success); }

.kpi-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-metric-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-value {
  font-size: 1.85rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-value.red-text { color: var(--color-red); }
.kpi-value.black-text { color: #cbd5e1; }
.kpi-value.white-text { color: var(--color-white); }
.kpi-value.highlight { color: var(--color-warning); }

.kpi-count {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.kpi-unit {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.kpi-subtext {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.badge-active-color {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: middle;
}

.badge-active-color.red { background: var(--color-red); box-shadow: 0 0 8px var(--color-red); }
.badge-active-color.black { background: var(--color-black); border: 2px solid var(--border-color); }
.badge-active-color.white { background: var(--color-white); box-shadow: 0 0 8px white; }

/* Ratio Section */
.ratio-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ratio-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.ratio-legend {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.red { background: var(--color-red); }
.dot.black { background: #475569; }
.dot.white { background: var(--color-white); }

.ratio-bar-container {
  display: flex;
  height: 14px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
}

.ratio-segment {
  height: 100%;
  transition: width 0.5s ease;
}

.ratio-segment.red { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.ratio-segment.black { background: linear-gradient(90deg, #1e293b, #334155); }
.ratio-segment.white { background: linear-gradient(90deg, #e2e8f0, #ffffff); }

/* History Section */
.history-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-card);
}

.history-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 16px;
}

.section-heading {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.history-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-filters {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.custom-select {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.custom-select:focus {
  border-color: var(--color-accent);
}

.view-switch {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.export-group {
  display: flex;
  gap: 8px;
}

.switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.switch-btn:hover {
  color: var(--text-primary);
}

.switch-btn.active {
  background: var(--color-accent);
  color: white;
}

/* Tiles Container (Casino Style Roulette Grid) */
.tiles-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 180px;
  align-content: flex-start;
}

.tile-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
}

.tile-badge:hover {
  transform: scale(1.15);
  z-index: 10;
}

.tile-badge.red {
  background: linear-gradient(145deg, #ef4444, #b91c1c);
  color: white;
  border: 1px solid #f87171;
  box-shadow: 0 2px 8px var(--color-red-glow);
}

.tile-badge.black {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  color: #f1f5f9;
  border: 1px solid var(--color-black-border);
  box-shadow: 0 2px 8px var(--color-black-glow);
}

.tile-badge.white {
  background: linear-gradient(145deg, #ffffff, #e2e8f0);
  color: #0f172a;
  border: 2px solid #f59e0b;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
}

.tile-badge .roll-num {
  line-height: 1;
}

.loading-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 150px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Data Table View */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  padding: 10px 14px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.table-color-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
}

.table-color-pill.red { background: rgba(239, 68, 68, 0.2); color: var(--color-red); }
.table-color-pill.black { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; }
.table-color-pill.white { background: rgba(248, 250, 252, 0.2); color: var(--color-white); }

.mono-cell {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* Pagination Bar */
.pagination-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.btn-page {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-page:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--color-accent);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.custom-input {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
}

.custom-input:focus {
  border-color: var(--color-accent);
}

.input-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.modal-status {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--color-accent);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: var(--bg-card);
}

/* Tooltip Customizado */
.tile-tooltip {
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  z-index: 20;
}

.tile-badge:hover .tile-tooltip {
  opacity: 1;
}

@media (max-width: 768px) {
  .topbar {
    padding: 12px 16px;
  }
  .main-content {
    padding: 16px;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .history-controls-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}
