/* ============================================
   SKYNET DASHBOARD - STYLES
   Sprint 2 - Live Data + Health Checks
   ============================================ */

/* CSS Variables for Dark/Light Theme */
:root, [data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e5e5e5;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;
  --border: #e0e0e0;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --input-bg: #ffffff;
  --input-border: #d1d5db;
}

[data-theme="dark"] {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1f1f1f;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --success: #4ade80;
  --warning: #facc15;
  --error: #f87171;
  --border: #2a2a2a;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --input-bg: #1a1a1a;
  --input-border: #333333;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   LOGIN PAGE STYLES
   ============================================ */

.login-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--card-shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.login-logo .logo-icon {
  font-size: 2rem;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: none;
}

.error-message.show {
  display: block;
}

/* ============================================
   THEME TOGGLE
   ============================================ */

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
}

.theme-toggle button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s ease;
}

.theme-toggle button:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */

.dashboard-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.dashboard-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo .logo-icon {
  font-size: 1.5rem;
}

.header-logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-user {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.btn-logout {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

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

.btn-refresh {
  background: var(--accent);
  color: #ffffff;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

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

.btn-refresh.spinning .refresh-icon {
  animation: spin 0.5s linear;
}

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

/* Main Content */
.dashboard-main {
  flex: 1;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Refresh Indicator */
.refresh-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.refresh-status {
  font-size: 0.875rem;
  transition: color 0.3s ease;
}

.refresh-status.loading {
  color: var(--warning);
  animation: pulse 1s infinite;
}

.refresh-status.success {
  color: var(--success);
}

.refresh-status.error {
  color: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.auto-refresh-label {
  margin-left: auto;
  background: var(--bg-tertiary);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

.stat-card .stat-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-card .stat-label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.stat-card.active .stat-value {
  color: var(--success);
}

.stat-card.skycoin {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(96, 165, 250, 0.1) 100%);
}

.beta-tag {
  font-size: 0.625rem;
  background: var(--warning);
  color: #000;
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 0.25rem;
}

/* ============================================
   HEALTH CHECKS SECTION
   ============================================ */

.health-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 2rem;
}

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

.section-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.health-summary {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
}

.health-stat {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.health-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.health-card.online {
  border-color: rgba(34, 197, 94, 0.3);
}

.health-card.slow {
  border-color: rgba(234, 179, 8, 0.3);
}

.health-card.offline {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.05);
}

.health-icon {
  font-size: 1.25rem;
}

.health-info {
  flex: 1;
  min-width: 0;
}

.health-name {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.health-duration {
  font-size: 0.625rem;
  color: var(--text-muted);
}

/* ============================================
   PROJECTS TABLE
   ============================================ */

.projects-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 2rem;
}

.projects-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.projects-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.projects-count {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.projects-table-wrapper {
  overflow-x: auto;
}

.projects-table {
  width: 100%;
  border-collapse: collapse;
}

.projects-table th,
.projects-table td {
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.projects-table th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-tertiary);
}

.projects-table tbody tr:last-child td {
  border-bottom: none;
}

.projects-table tbody tr:hover {
  background: var(--bg-tertiary);
}

.project-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.project-link:hover {
  text-decoration: underline;
}

.sprint-badge {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
}

.status-indicator.active {
  color: var(--success);
}

.status-indicator.paused {
  color: var(--warning);
}

.deploy-cell {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.risks-cell {
  font-size: 0.875rem;
  color: var(--success);
}

.risks-cell.has-risks {
  color: var(--warning);
}

/* ============================================
   DECISIONS SECTION
   ============================================ */

.decisions-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.decisions-list {
  list-style: none;
}

.decision-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.decision-item:last-child {
  border-bottom: none;
}

.decision-date {
  color: var(--text-muted);
  font-size: 0.75rem;
  min-width: 80px;
}

.decision-text {
  flex: 1;
  color: var(--text-primary);
}

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

.no-decisions {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem 0;
}

/* Footer */
.dashboard-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.footer-content a {
  color: var(--accent);
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}

/* ============================================
   DEVICE-SPECIFIC STYLES
   ============================================ */

body.mobile .desktop-only {
  display: none !important;
}

body.desktop .mobile-only {
  display: none !important;
}

body.mobile .stats-grid {
  grid-template-columns: repeat(2, 1fr);
}

body.mobile .health-grid {
  grid-template-columns: repeat(2, 1fr);
}

body.mobile .header-user {
  display: none;
}

body.mobile .login-card {
  padding: 1.5rem;
}

body.mobile .projects-table th,
body.mobile .projects-table td {
  padding: 0.75rem 0.5rem;
  font-size: 0.8125rem;
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

@media (max-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .stat-card .stat-value {
    font-size: 1.5rem;
  }
  
  .header-logo h1 {
    font-size: 1rem;
  }

  .health-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .decision-item {
    flex-direction: column;
  }
}

@media (min-width: 768px) {
  .dashboard-main {
    padding: 2rem;
  }
  
  .login-card {
    padding: 3rem;
  }
}

@media (min-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .health-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

.login-card {
  animation: fadeIn 0.3s ease-out;
}

.stat-card {
  animation: fadeIn 0.3s ease-out;
}

.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }

.health-card {
  animation: fadeIn 0.2s ease-out;
}
