/* ============================================================
   Garmin AI Running Coach — Dashboard Styles
   Dark mode, minimalis, profesional, responsif
   ============================================================ */

:root {
  /* Warna aksen: hijau olahraga (primary) & oranye (accent) */
  --color-bg: #0b0f14;
  --color-surface: #131a22;
  --color-surface-elev: #18232d;
  --color-border: #24323e;
  --color-text: #e8eef4;
  --color-text-muted: #94a3b8;
  --color-text-dim: #64748b;

  --color-primary: #10b981;      /* hijau emerald */
  --color-primary-hover: #059669;
  --color-accent: #f97316;       /* oranye */
  --color-accent-hover: #ea580c;

  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-info: #38bdf8;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);

  --radius: 12px;
  --radius-lg: 16px;
  --transition: 200ms ease;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Scrollbar halus ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--color-bg);
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

/* ===== Navbar ===== */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 1.5rem;
  background: rgba(11, 15, 20, 0.8);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-text);
  text-decoration: none;
}

.brand-icon {
  font-size: 1.5rem;
}

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

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--color-surface-elev);
  border-color: var(--color-primary);
}

.btn-icon:active {
  transform: scale(0.95);
}

.btn-icon:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Badge status sinkronisasi */
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}

.sync-synced {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-primary);
  border-color: rgba(16, 185, 129, 0.3);
}

.sync-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-error);
  border-color: rgba(239, 68, 68, 0.3);
}

.sync-unknown {
  background: var(--color-surface);
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

.sync-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

/* ===== Flash messages ===== */
.flash-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.flash {
  pointer-events: auto;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  border: 1px solid;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { transform: translateX(-50%) translateY(-10px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.flash-success { background: rgba(16, 185, 129, 0.15); color: #86efac; border-color: rgba(16, 185, 129, 0.4); }
.flash-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
.flash-info { background: rgba(56, 189, 248, 0.15); color: #bae6fd; border-color: rgba(56, 189, 248, 0.4); }
.flash-warning { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border-color: rgba(245, 158, 11, 0.4); }

/* ===== Container & Section ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

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

/* ===== Hero / Target Card ===== */
.target-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

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

.hero-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid;
}

.pill-active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--color-primary);
  border-color: rgba(16, 185, 129, 0.3);
}

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

.stat-block {
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

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

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

.hero-note {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition), border-color var(--transition);
}

.stat-card:hover {
  border-color: var(--color-primary);
}

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

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

.stat-card .stat-unit {
  font-size: 0.85rem;
  color: var(--color-text-dim);
}

.stat-card .stat-trend {
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: auto;
}

.trend-up { color: var(--color-success); }
.trend-down { color: var(--color-error); }
.trend-neutral { color: var(--color-text-muted); }

/* ===== Grafik ===== */
.charts-section {
  margin-bottom: 2rem;
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.chart-controls label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.chart-controls select {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  min-width: 180px;
  cursor: pointer;
}

.chart-controls select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.chart-card.full {
  grid-column: 1 / -1;
}

.chart-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text);
}

.chart-wrapper {
  position: relative;
  height: 260px;
  width: 100%;
}

/* ===== Riwayat Aktivitas ===== */
.activities-section {
  margin-bottom: 2rem;
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

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

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

th {
  background: var(--color-surface-elev);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 2;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

td .value-mono {
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

td .hr-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  border: 1px solid;
}

.hr-good { background: rgba(16, 185, 129, 0.1); color: var(--color-primary); border-color: rgba(16, 185, 129, 0.3); }
.hr-warn { background: rgba(245, 158, 11, 0.1); color: var(--color-warning); border-color: rgba(245, 158, 11, 0.3); }
.hr-high { background: rgba(239, 68, 68, 0.1); color: var(--color-error); border-color: rgba(239, 68, 68, 0.3); }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

/* ===== Chat AI Coach ===== */
.chat-section {
  margin-bottom: 2rem;
}

.chat-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 500px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 200px;
}

.chat-message {
  display: flex;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease;
}

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

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
}

.chat-bubble {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  max-width: 85%;
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat-ai .chat-bubble {
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

.chat-user {
  flex-direction: row-reverse;
}

.chat-user .chat-avatar {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}

.chat-user .chat-bubble {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--color-text);
}

.chat-bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.chat-bubble .typing-indicator {
  display: inline-flex;
  gap: 4px;
}

.chat-bubble .typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing 1.4s infinite both;
}

.chat-bubble .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat suggestions */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1rem;
  padding-bottom: 0.75rem;
}

.chat-suggestion {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition);
}

.chat-suggestion:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(16, 185, 129, 0.1);
}

/* Chat input form */
.chat-input-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.chat-input {
  flex: 1;
  padding: 0.65rem 1rem;
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
}

.chat-input:focus {
  border-color: var(--color-primary);
}

.chat-input::placeholder {
  color: var(--color-text-dim);
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: var(--color-primary);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-send:hover {
  background: var(--color-primary-hover);
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Generator Jadwal Mingguan ===== */
.schedule-section {
  margin-bottom: 2rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.schedule-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.schedule-info {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.schedule-info-item {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.schedule-info-label {
  color: var(--color-text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.schedule-info-value {
  color: var(--color-text);
}

.schedule-output {
  padding: 1.5rem;
}

.schedule-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 0;
  color: var(--color-text-muted);
}

.spinner-large {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.schedule-content {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--color-text);
}

.schedule-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem;
  color: var(--color-primary);
}

.schedule-content h3:first-child {
  margin-top: 0;
}

.schedule-content p {
  margin: 0.5rem 0;
}

.schedule-content ul, .schedule-content ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.schedule-content li {
  margin: 0.35rem 0;
}

.schedule-content strong {
  color: var(--color-text);
  font-weight: 600;
}

.schedule-content em {
  color: var(--color-text-muted);
  font-style: normal;
  font-size: 0.85rem;
}

.schedule-content .schedule-day {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--color-surface-elev);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin: 0.5rem 0;
}

.schedule-content .day-name {
  font-weight: 600;
  color: var(--color-primary);
  min-width: 60px;
  flex-shrink: 0;
}

.schedule-content .day-activity {
  flex: 1;
}

/* ===== Footer ===== */
.footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
  margin-top: 2rem;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container {
    padding: 1rem 0.75rem;
  }

  .navbar {
    padding: 0 1rem;
    height: 56px;
  }

  .nav-brand {
    font-size: 1.1rem;
    gap: 0.4rem;
  }

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

  .hero-grid {
    grid-template-columns: 1fr 1fr;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrapper {
    height: 220px;
  }

  th, td {
    padding: 0.7rem 0.5rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .chart-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-controls select {
    min-width: auto;
  }
}

/* Utilitas */
.text-center { text-align: center; }
.mt-2 { margin-top: 0.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
