/* ===== CSS 变量 / 主题 ===== */
:root {
  --primary: #4f6ef7;
  --primary-hover: #3b5de7;
  --primary-light: #eef1ff;
  --primary-bg: rgba(79, 110, 247, 0.10);
  --bg: #f5f7fb;
  --card-bg: #ffffff;
  --text: #2d3436;
  --text-secondary: #636e72;
  --border: #e0e4ea;
  --success: #27ae60;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;

  /* 时间线常量 */
  --timeline-label-w: 60px;
  --timeline-hour-h: 60px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== Container ===== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

/* ===== Header / 导航栏 ===== */
.header {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

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

.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
  color: var(--text);
  user-select: none;
}

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

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

.date-display {
  font-size: 16px;
  font-weight: 600;
  min-width: 110px;
  text-align: center;
  color: var(--text);
  padding: 6px 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.today-btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  font-weight: 500;
}

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

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

/* ===== Main Content ===== */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== 中段双栏 ===== */
.middle-section {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}

.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

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

/* ===== 迷你月历 ===== */
.calendar-panel {
  overflow: hidden;
}

.mini-calendar {
  font-size: 14px;
}

/* 月历头部：月份标题 + 箭头 */
.mini-calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.mini-calendar-month {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.mini-calendar-nav {
  display: flex;
  gap: 4px;
}

.mini-calendar-nav-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  color: var(--text-secondary);
  user-select: none;
  line-height: 1;
}

.mini-calendar-nav-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* 星期行 */
.mini-calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
  padding: 0 2px;
}

/* 日期网格 */
.mini-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

/* 单个日期格 */
.calendar-day {
  text-align: center;
  font-size: 13px;
  padding: 6px 2px;
  cursor: pointer;
  border-radius: 50%;
  transition: all var(--transition);
  user-select: none;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-day:hover {
  background: var(--primary-light);
}

/* 非本月日期 */
.calendar-day.other-month {
  color: #ccc;
}

.calendar-day.other-month:hover {
  background: var(--bg);
}

/* 当天 */
.calendar-day.today {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.calendar-day.today:hover {
  background: var(--primary-hover);
}

/* 选中日期（非当天时） */
.calendar-day.selected:not(.today) {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  font-weight: 600;
  color: var(--primary);
}

/* 日程标记小圆点 */
.calendar-day .dot {
  position: absolute;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.calendar-day .dot.has-items {
  background: var(--primary);
}

.calendar-day .dot.all-completed {
  background: var(--success);
}

/* 图例行 */
.mini-calendar-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--text-secondary);
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.mini-calendar-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.mini-calendar-legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.mini-calendar-legend-dot.blue {
  background: var(--primary);
}

.mini-calendar-legend-dot.green {
  background: var(--success);
}

/* ===== 时间线面板 ===== */
.schedule-panel {
  overflow: hidden;
  min-height: 0;
}

/* 添加栏 */
.timeline-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.timeline-add-row .task-input {
  flex: 1;
  min-width: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}

.timeline-add-row .task-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

.time-input {
  width: 100px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
  color: var(--text);
  text-align: center;
}

.time-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

.time-sep {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 14px;
}

.timeline-error {
  font-size: 12px;
  color: var(--danger);
  min-height: 18px;
  margin-bottom: 6px;
  transition: opacity var(--transition);
}

.add-btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
}

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

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

/* ===== 时间线容器 ===== */
.timeline-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-height: 350px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
}

/* 空状态：无日程时隐藏时间线容器 */
.timeline-container--empty {
  display: none;
}

/* 智能分段容器 */
.timeline-segment {
  position: relative;
}

/* 段间空闲标识 */
.timeline-gap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
  color: var(--text-secondary);
  font-size: 12px;
  gap: 8px;
}

.timeline-gap::before,
.timeline-gap::after {
  content: '';
  flex: 1;
  border-top: 1px dashed var(--border);
}

/* 时间线网格（每小时一行） */
.timeline-grid {
  position: relative;
  min-height: 100%;
}

/* 小时行 */
.timeline-hour-row {
  display: flex;
  height: var(--timeline-hour-h);
  position: relative;
}

.timeline-hour-label {
  width: var(--timeline-label-w);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  padding-top: 2px;
  user-select: none;
  position: relative;
  z-index: 2;
}

.timeline-hour-line {
  flex: 1;
  border-top: 1px solid var(--border);
  position: relative;
}

/* 半小时虚线标记 */
.timeline-half-line {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--timeline-hour-h) / 2);
  border-top: 1px dashed rgba(0, 0, 0, 0.08);
}

/* 整点虚线标记（填充空时间区域） */
.timeline-hour-line .timeline-half-line {
  display: block;
}

/* ===== 日程块 ===== */
.schedule-block {
  position: absolute;
  left: calc(var(--timeline-label-w) + 12px);
  right: 16px;
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition);
  display: flex;
  align-items: flex-start;
  gap: 6px;
  overflow: hidden;
  z-index: 5;
  min-height: 24px;
}

.schedule-block:hover {
  box-shadow: 0 2px 8px rgba(79, 110, 247, 0.20);
}

.schedule-block.completed {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--border);
  border-left-color: var(--border);
  opacity: 0.6;
}

.schedule-block.completed:hover {
  box-shadow: none;
}

.schedule-checkbox {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 3px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: var(--card-bg);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.schedule-checkbox:checked {
  background: var(--success);
  border-color: var(--success);
}

.schedule-checkbox:checked::after {
  content: "✓";
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.schedule-block.completed .schedule-checkbox {
  border-color: var(--text-secondary);
}

.schedule-block.completed .schedule-checkbox:checked {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
}

.schedule-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  word-break: break-word;
  min-width: 0;
}

.schedule-block.completed .schedule-text {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.schedule-time-label {
  font-size: 11px;
  color: var(--primary);
  font-weight: 500;
  flex-shrink: 0;
}

.schedule-block.completed .schedule-time-label {
  color: var(--text-secondary);
}

.schedule-delete-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  opacity: 0;
  margin-top: 1px;
}

.schedule-block:hover .schedule-delete-btn {
  opacity: 1;
}

.schedule-delete-btn:hover {
  background: rgba(231, 76, 60, 0.1);
  color: var(--danger);
}

/* ===== "现在"指示线 ===== */
.now-indicator {
  position: absolute;
  left: var(--timeline-label-w);
  right: 0;
  border-top: 2px dashed var(--danger);
  z-index: 10;
  pointer-events: none;
}

.now-indicator::before {
  content: attr(data-label);
  position: absolute;
  left: -60px;
  top: -9px;
  font-size: 11px;
  color: var(--danger);
  font-weight: 600;
  white-space: nowrap;
  width: 56px;
  text-align: right;
}

/* ===== 空状态 ===== */
.timeline-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

/* ===== 编辑弹窗 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  animation: modalIn 0.2s ease;
}

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

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

.modal-body {
  margin-bottom: 20px;
}

.modal-field {
  margin-bottom: 16px;
}

.modal-field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.modal-field input[type="text"],
.modal-field input[type="time"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
}

.modal-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

.modal-time-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.modal-time-group {
  flex: 1;
}

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

.modal-time-row .time-sep {
  padding-bottom: 12px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
}

.modal-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.modal-btn:active {
  transform: scale(0.96);
}

.modal-btn-save {
  background: var(--primary);
  color: #fff;
}

.modal-btn-save:hover {
  background: var(--primary-hover);
}

.modal-btn-cancel {
  background: var(--bg);
  color: var(--text);
}

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

.modal-btn-delete {
  background: transparent;
  color: var(--danger);
  padding-left: 0;
}

.modal-btn-delete:hover {
  color: var(--danger-hover);
}

/* ===== 日记面板 ===== */
.journal-panel {
  min-height: 0;
}

.journal-textarea {
  flex: 1;
  min-height: 140px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.8;
  resize: vertical;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
}

.journal-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.12);
}

.journal-textarea::placeholder {
  color: #b2bec3;
}

.journal-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: right;
  min-height: 18px;
  transition: color var(--transition);
}

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

/* ===== 响应式：移动端 ===== */
@media (max-width: 768px) {
  :root {
    --timeline-hour-h: 48px;
  }

  .container {
    padding: 12px;
  }

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

  .app-title {
    font-size: 18px;
    text-align: center;
  }

  .date-nav {
    justify-content: center;
    flex-wrap: wrap;
  }

  .middle-section {
    grid-template-columns: 180px 1fr;
    gap: 12px;
  }

  .panel {
    padding: 18px;
  }

  .calendar-day {
    font-size: 12px;
    padding: 4px 1px;
  }

  .mini-calendar-month {
    font-size: 13px;
  }

  .mini-calendar-weekdays {
    font-size: 10px;
  }

  .journal-textarea {
    min-height: 120px;
  }

  /* 移动端添加栏纵向排列 */
  .timeline-add-row {
    flex-direction: column;
    align-items: stretch;
  }

  .timeline-add-row .task-input {
    min-width: auto;
  }

  .time-input {
    width: auto;
    flex: 1;
  }

  .timeline-add-row .time-sep {
    display: none;
  }

  .add-btn {
    width: 100%;
  }

  .schedule-block .schedule-delete-btn {
    opacity: 1;
  }

  .timeline-container {
    min-height: 250px;
  }

  .modal-content {
    padding: 20px;
  }
}

/* 更小屏幕适配 */
@media (max-width: 480px) {
  .middle-section {
    grid-template-columns: 140px 1fr;
    gap: 8px;
  }

  .calendar-day {
    font-size: 11px;
    padding: 3px 1px;
  }

  .mini-calendar-weekdays {
    font-size: 9px;
  }
}
