/* style.css — Heatmap Calendar */

:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --card-bg: #161b22;
  --input-bg: #0d1117;
  --shadow: rgba(0, 0, 0, 0.3);
  --radius: 6px;
  --radius-lg: 12px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --text: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8b949e;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --danger: #cf222e;
  --success: #1a7f37;
  --warning: #9a6700;
  --card-bg: #f6f8fa;
  --input-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.1);
}

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

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

/* --- Header --- */

.app-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 3px 12px;
  font-size: 12px;
}

.btn-icon {
  padding: 5px 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  border-radius: var(--radius);
}

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

/* --- Layout --- */

.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* --- Track Tabs --- */

.track-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.track-tab {
  padding: 6px 16px;
  font-size: 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.track-tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.track-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.track-tab-add {
  padding: 6px 12px;
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
}

/* --- Quick Log --- */

.quick-log-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.quick-log-bar .today-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.quick-log-bar .today-date {
  font-weight: 600;
  font-size: 16px;
}

.quick-log-bar input[type="number"] {
  width: 100px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
}

.quick-log-bar .unit-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.quick-log-toggle {
  width: 50px;
  height: 28px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  background: var(--bg-tertiary);
}

.quick-log-toggle.active {
  background: var(--success);
}

.quick-log-toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.quick-log-toggle.active::after {
  transform: translateX(22px);
}

/* --- Heatmap Section --- */

.heatmap-section {
  margin-bottom: 24px;
}

.heatmap-wrapper {
  overflow-x: auto;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}

.heatmap-svg {
  display: block;
}

.heatmap-day-label,
.heatmap-month-label {
  font-size: 10px;
  fill: var(--text-muted);
  font-family: inherit;
}

.heatmap-cell {
  transition: fill 0.3s ease;
  stroke: var(--bg-secondary);
  stroke-width: 1;
}

.heatmap-cell:hover {
  stroke: var(--text-secondary);
  stroke-width: 2;
}

.heatmap-cell-flash {
  animation: cellFlash 0.4s ease;
}

@keyframes cellFlash {
  0% { opacity: 0.3; transform: scale(1.3); }
  100% { opacity: 1; transform: scale(1); }
}

.heatmap-tooltip {
  position: absolute;
  background: var(--bg-tertiary);
  color: var(--text);
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 50;
  transform: translateX(-50%);
  border: 1px solid var(--border);
}

/* --- Cell Popup (for editing) --- */

.cell-popup {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  z-index: 200;
  box-shadow: 0 8px 24px var(--shadow);
  min-width: 220px;
}

.cell-popup h4 {
  font-size: 14px;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.cell-popup input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
}

.cell-popup .popup-actions {
  display: flex;
  gap: 8px;
}

.cell-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 199;
}

/* --- Date Range Controls --- */

.range-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.range-controls select,
.range-controls input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
}

/* --- Stats --- */

.stats-section {
  margin-bottom: 24px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
}

.stat-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

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

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* --- Monthly Chart --- */

.chart-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.monthly-chart {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 150px;
}

.chart-bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar-wrapper.dual {
  gap: 2px;
}

.chart-bar-group {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 100%;
  width: 100%;
}

.chart-bar-group .chart-bar {
  flex: 1;
}

.chart-bar-value {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.chart-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 3px 3px 0 0;
  transition: height 0.3s ease;
}

.chart-bar-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
}

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* --- Log History --- */

.log-history {
  margin-top: 20px;
}

.log-history h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.log-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-entry-date {
  color: var(--text-secondary);
  min-width: 120px;
}

.log-entry-value {
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.log-entry-actions {
  display: flex;
  gap: 4px;
}

/* --- Modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 380px;
  max-width: 500px;
  width: 90vw;
  box-shadow: 0 16px 48px var(--shadow);
  animation: slideUp 0.2s ease;
}

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

.modal h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* --- Color Scheme Preview --- */

.color-scheme-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-scheme-option {
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}

.color-scheme-option.selected {
  border-color: var(--accent);
}

.color-scheme-option:hover {
  border-color: var(--text-muted);
}

.color-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
}

/* --- Multi-Track View --- */

.multi-track-view .track-section {
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 24px;
}

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

.track-section-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.track-section-header .track-actions {
  display: flex;
  gap: 4px;
}

/* --- Comparison panel --- */

.comparison-panel {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.comparison-selectors {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: center;
}

.comparison-selectors select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
}

.comparison-selectors .vs-label {
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- Import/Export --- */

.import-export-section {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

/* --- Empty State --- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  font-size: 16px;
  margin-bottom: 20px;
}

/* --- Year in Review --- */

.year-review {
  padding: 24px;
}

.year-review h2 {
  font-size: 24px;
  text-align: center;
  margin-bottom: 24px;
}

/* --- Confetti --- */

.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

/* --- View toggle --- */

.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 2px;
}

.view-toggle button {
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.view-toggle button.active {
  background: var(--bg-secondary);
  color: var(--text);
}

/* --- Responsive --- */

@media (max-width: 768px) {
  .app-container {
    padding: 12px;
  }

  .app-header {
    padding: 10px 16px;
  }

  .app-header h1 {
    font-size: 16px;
  }

  .stat-cards {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 10px;
  }

  .stat-value {
    font-size: 18px;
  }

  .quick-log-bar {
    flex-wrap: wrap;
  }

  .heatmap-wrapper {
    padding: 8px;
  }

  .modal {
    min-width: unset;
    width: 95vw;
  }

  .track-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
  }

  .comparison-selectors {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* --- Print --- */

@media print {
  .app-header,
  .quick-log-bar,
  .header-actions,
  .track-tabs .track-tab-add,
  .import-export-section,
  .log-history,
  .btn,
  .range-controls {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .heatmap-wrapper {
    border: none;
    box-shadow: none;
  }

  .stat-card {
    border: 1px solid #ddd;
  }
}

/* --- Scrollbar --- */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --- Hidden file input --- */

.hidden-input {
  display: none;
}

/* --- Notification --- */

.notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 500;
  animation: slideUp 0.2s ease;
  font-size: 14px;
}

.notification.success {
  border-color: var(--success);
}

.notification.error {
  border-color: var(--danger);
}
