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

:root {
  --color-work: #e74c3c;
  --color-work-bg: #fdecea;
  --color-work-light: #fadbd8;
  --color-break: #27ae60;
  --color-break-bg: #eafaf1;
  --color-break-light: #d5f5e3;
  --color-text: #2c3e50;
  --color-text-secondary: #7f8c8d;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #e8e8e8;
  --color-primary: #3498db;
  --color-primary-hover: #2980b9;
  --color-danger: #e74c3c;
  --color-danger-hover: #c0392b;
  --color-ghost: #95a5a6;
  --color-ghost-hover: #7f8c8d;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 40px rgba(231, 76, 60, 0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --theme-color: var(--color-work);
  --theme-bg: var(--color-work-bg);
  --theme-light: var(--color-work-light);
}

body {
  font-family: var(--font);
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
  color: var(--color-text);
  min-height: 100vh;
}

/* ===== App Layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
  justify-content: center;
}

/* ===== Main Area ===== */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px;
  min-width: 0;
  max-width: 600px;
}

.container {
  width: 100%;
  max-width: 480px;
}

/* ===== Header ===== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
  padding: 0 8px;
  width: 100%;
  max-width: 480px;
}

.logo {
  font-size: 26px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 32px;
}

.stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

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

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ===== Timer Section ===== */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 36px;
  padding: 32px 24px;
  background: var(--color-surface);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  gap: 24px;
  width: 100%;
  max-width: 480px;
}

.timer-top {
  display: flex;
  gap: 8px;
}

.btn-timer-type {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  border: 2px solid var(--color-border);
  border-radius: 20px;
  padding: 8px 20px;
  cursor: pointer;
  background: transparent;
  color: var(--color-text-secondary);
  transition: all var(--transition);
}

.btn-timer-type:hover {
  border-color: var(--theme-color);
  color: var(--theme-color);
}

.btn-timer-type.active {
  border-color: var(--theme-color);
  background: var(--theme-bg);
  color: var(--theme-color);
  font-weight: 600;
}

.timer-middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.timer-time {
  font-size: 80px;
  font-weight: 300;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
  line-height: 1;
}

.timer-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.timer-controls-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.settings-row {
  display: flex;
  justify-content: center;
}

.btn-start {
  min-width: 90px;
  font-size: 15px;
  padding: 12px 20px;
}

/* ===== Settings Panel ===== */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  height: 100vh;
  background: var(--color-surface);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  z-index: 200;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

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

.settings-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.settings-body {
  padding: 20px 24px;
  flex: 1;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

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

.settings-label {
  font-size: 14px;
  color: var(--color-text);
  font-weight: 500;
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--color-border);
  border-radius: 24px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--color-primary);
}

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

/* ===== Buttons ===== */
.btn {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  padding: 12px 28px;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--theme-color);
  color: #fff;
  min-width: 100px;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--theme-color) 40%, transparent);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px color-mix(in srgb, var(--theme-color) 50%, transparent);
}

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

.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
  min-width: 100px;
}

.btn-secondary:hover {
  background: #d0d0d0;
}

.btn-ghost {
  background: transparent;
  color: var(--color-ghost);
  padding: 12px 16px;
  min-width: auto;
}

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

.btn-small {
  font-size: 13px;
  padding: 8px 16px;
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--color-text-secondary);
  transition: all var(--transition);
}

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

.btn-icon.danger:hover {
  background: var(--color-work-bg);
  color: var(--color-danger);
}

.hidden {
  display: none !important;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--color-surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  animation: modalIn 0.25s ease;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 0;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

.modal-close {
  font-size: 28px;
  padding: 0 4px;
  line-height: 1;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 20px;
}

/* ===== Completion Modal ===== */
.completion-modal {
  max-width: 340px;
}

.completion-message {
  font-size: 16px;
  color: var(--color-text-secondary);
  text-align: center;
  margin: 0;
  padding: 8px 0;
}

/* ===== Notes ===== */
.notes-section {
  width: 100%;
  max-width: 480px;
  padding: 20px 24px;
  background: var(--color-surface);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 24px;
}

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

.notes-title {
  font-size: 16px;
  font-weight: 600;
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.note-input {
  font-family: var(--font);
  font-size: 14px;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--color-bg);
  width: 100%;
  resize: vertical;
}

.note-input:focus {
  outline: none;
  border-color: var(--theme-color);
}

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

.notes-empty {
  font-size: 13px;
  color: var(--color-text-secondary);
  text-align: center;
  padding: 8px 0 4px;
}

.note-card {
  border-top: 1px solid var(--color-border);
  padding: 12px 0;
}

.note-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  word-break: break-word;
}

.note-card-content {
  font-size: 14px;
  color: var(--color-text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.note-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 6px;
}

/* ===== Stats Section ===== */
.stats-section {
  width: 100%;
  max-width: 480px;
  padding: 24px;
  background: var(--color-surface);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 36px;
}

.stats-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--color-bg);
  border-radius: 10px;
  padding: 4px;
}

.stats-tab {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.stats-tab.active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.stats-panel {
  display: none;
}

.stats-panel.active {
  display: block;
}

.stats-grid {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stats-card {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}

.stats-card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.stats-card-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

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

/* Histogram */
.histogram {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 80px;
  padding-bottom: 20px;
  position: relative;
}

.histogram-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}

.histogram-bar {
  width: 100%;
  max-width: 16px;
  background: var(--color-work-light);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
}

.histogram-bar.active {
  background: var(--theme-color);
}

.histogram-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* Heatmap (inside total tab) */
.heatmap-year-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.heatmap-year-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  min-width: 50px;
  text-align: center;
}

.btn-sm {
  padding: 2px 8px;
  font-size: 14px;
}

.heatmap-wrap {
  display: flex;
  gap: 8px;
}

.heatmap-weekdays {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 0 2px;
  height: calc(18px + 7 * 12px + 6 * 3px);
  font-size: 10px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.heatmap-weekdays span {
  line-height: 12px;
  height: 12px;
}

.heatmap-scroll {
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  padding-top: 28px;
  margin-top: -28px;
}

.heatmap-months {
  display: flex;
  font-size: 10px;
  color: var(--color-text-secondary);
  height: 14px;
  margin-bottom: 4px;
}

.heatmap-month-label {
  flex-shrink: 0;
  white-space: nowrap;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
}

.heatmap-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #ebedf0;
  cursor: default;
  position: relative;
}

.heatmap-cell[data-level="1"] { background: #9be9a8; }
.heatmap-cell[data-level="2"] { background: #40c463; }
.heatmap-cell[data-level="3"] { background: #30a14e; }
.heatmap-cell[data-level="4"] { background: #216e39; }

.heatmap-cell[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 12px;
}

.heatmap-legend-label {
  font-size: 10px;
  color: var(--color-text-secondary);
  margin: 0 2px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .main-area {
    padding: 20px 16px;
  }

  .header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }

  .stats {
    justify-content: center;
  }

  .logo {
    justify-content: center;
  }

  .header-right {
    width: 100%;
    justify-content: center;
  }

  .timer-time {
    font-size: 56px;
  }

  .timer-section {
    padding: 24px 16px;
    gap: 20px;
  }

  .btn-timer-type {
    font-size: 13px;
    padding: 6px 14px;
  }

  .stats-section {
    padding: 16px;
  }

  .heatmap-cell {
    width: 10px;
    height: 10px;
  }

  .heatmap-grid {
    grid-template-rows: repeat(7, 10px);
    grid-auto-columns: 10px;
    gap: 2px;
  }

  .heatmap-weekdays {
    height: calc(18px + 7 * 10px + 6 * 2px);
  }

  .heatmap-weekdays span {
    line-height: 10px;
    height: 10px;
  }
}
