/* ---------- 基础变量与重置 ---------- */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1b1e23;
  --muted: #6b7280;
  --line: #e8eaee;
  --primary: #4f7cff;
  --primary-dark: #3f68e0;
  --primary-soft: #eef2ff;
  --danger: #e03131;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- 整体布局 ---------- */
.app {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

/* 左侧导航 */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 14px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.native-settings {
  margin-left: auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  width: 28px; height: 28px;
  border-radius: 9px;
  font-size: 14px; line-height: 1;
}
.brand .native-settings ~ .native-settings { margin-left: 6px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 11px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .12);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .3px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  text-align: left;
  padding: 8px 11px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #f0f2f6; color: var(--text); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--primary);
  font-size: 12px;
}
.link-btn:hover { text-decoration: underline; }

/* 右侧主区域 */
.main { padding: 26px 30px 36px; max-width: 960px; }
.view { display: none; }
.view.is-active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 14px; }
.view-head h1 { font-size: 21px; font-weight: 650; letter-spacing: .2px; }
.view-head .sub { margin-top: 4px; color: var(--muted); font-size: 12.5px; }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field select,
.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field.inline input { width: 96px; }
.field select:focus,
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 124, 255, .12); }

.btn {
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 14px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f0f2f6; color: var(--text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #c92a2a; border-color: #c92a2a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .nav-item:focus-visible, .seg-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.bar { height: 6px; border-radius: 999px; background: #eef0f4; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .2s linear; }

/* ---------- 时间记录卡片 ---------- */
/* 每张卡片独占一整行：左项目信息、中计时区、右操作按钮，进度条单独一行 */
#timerGrid { grid-template-columns: 1fr; }

.timer-item {
  position: relative;
  overflow: hidden;
  padding: 12px 14px 12px 28px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}
/* 项目颜色竖条：紧贴卡片左侧，随卡片圆角裁切 */
.timer-stripe {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
}
.timer-head { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; }
.timer-name { cursor: pointer; }
.timer-name:hover { color: #444B55; }
.timer-head h3 {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 时钟与模式切换共用同一块区域，切换时高度不跳动 */
.timer-body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 40px;
}
.timer-config { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer-down { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.timer-down input {
  width: 62px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  outline: none;
}
.timer-down input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 124, 255, .12); }

.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: #f1f3f7;
  flex: none;
}
.seg-btn {
  border: 0;
  padding: 5px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
}
.seg-btn.is-active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .08); }

.clock {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfd;
}

.timer-actions { display: flex; gap: 8px; margin-left: auto; flex: none; }
/* 进度条横跨整行 */
.timer-item > .timer-bar { flex: 1 1 100%; }

/* 纯图标按钮 */
.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
}
.icon-btn svg { width: 15px; height: 15px; display: block; }

/* 当日累计投入：两行、居中，数值加粗，带边框与底色 */
.today-total {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfd;
  line-height: 1.15;
  flex: none;
}
.today-total b {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.today-total span { font-size: 10px; color: var(--muted); }

/* ---------- 台账 ---------- */
.ledger-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.summary { display: flex; gap: 18px; font-size: 12.5px; color: var(--muted); }
.summary b { display: block; color: var(--text); font-size: 16px; font-weight: 600; margin-top: 1px; }

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 12px;
}
.project { padding: 15px; display: flex; flex-direction: column; gap: 10px; }
.project-top { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.project-top h3 { font-size: 15px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.project:hover .project-actions, .project:focus-within .project-actions { opacity: 1; }
.project-actions button {
  border: 0; background: none; color: var(--muted);
  font-size: 12px; padding: 4px 6px; border-radius: 6px;
}
.project-actions button:hover { background: #f0f2f6; color: var(--text); }
.project-actions button[data-act="delete"]:hover { color: var(--danger); }

.project-hours { display: flex; align-items: baseline; gap: 6px; }
.project-hours strong { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.project-hours span { color: var(--muted); font-size: 12px; }
.project-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.empty-hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

/* ---------- 弹窗 ---------- */
.dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .18);
}
.dialog::backdrop { background: rgba(17, 22, 30, .35); }
.dialog form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dialog h2 { font-size: 17px; font-weight: 650; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.confirm-text { font-size: 14px; line-height: 1.65; color: var(--text); }

/* 结束计时：补录编辑 */
.stop-edit {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfd;
}
.stop-edit-hint { font-size: 12px; line-height: 1.5; color: var(--muted); }

/* 项目记录详情 */
.detail-dialog { width: min(560px, calc(100vw - 32px)); }
.detail-wrap { display: flex; flex-direction: column; gap: 10px; padding: 20px; max-height: 72vh; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.detail-sub { font-size: 12.5px; color: var(--muted); }
.detail-list { overflow-y: auto; margin: 0 -4px; padding: 0 4px; display: flex; flex-direction: column; gap: 6px; }
.detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.detail-when { flex: 1; min-width: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.detail-dur { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.detail-del {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  flex: none;
}
.detail-del:hover { background: #f0f2f6; color: var(--danger); }
.detail-empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

.color-options { display: flex; gap: 10px; }
.color-options button {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 3px #fff;
  transition: transform .12s, border-color .12s;
}
.color-options button.is-active { border-color: var(--text); }
.color-options button:hover { transform: scale(1.08); }

/* ---------- Todo ---------- */
.todo-summary { display: flex; gap: 22px; }
.todo-summary > div { display: flex; flex-direction: column; gap: 2px; }
.todo-summary span { font-size: 11.5px; color: var(--muted); }
.todo-summary b { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }

.todo-groups { display: flex; flex-direction: column; gap: 18px; }
.todo-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .3px;
}
.todo-group-title span {
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef0f4;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.todo-items { display: flex; flex-direction: column; gap: 8px; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.todo-check {
  width: 21px;
  height: 21px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1.5px solid #cfd4dc;
  border-radius: 50%;
  background: #fff;
  color: #fff;
  font-size: 12px;
  line-height: 1;
}
.todo-check:hover { border-color: var(--primary); }
.todo-check.is-checked { background: var(--primary); border-color: var(--primary); }
.todo-main { flex: 1; min-width: 0; cursor: pointer; }
.todo-title {
  font-size: 14px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.todo-meta { margin-top: 3px; font-size: 12px; color: var(--muted); }
.todo-note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.todo-remind-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
}
.todo-item.is-done .todo-title { color: var(--muted); text-decoration: line-through; }
.todo-item.is-done .todo-main { cursor: default; }

.todo-item.is-overdue {
  border-color: rgba(220, 38, 38, .35);
  background: #fff4f4;
  box-shadow: inset 3px 0 0 var(--danger);
}
.todo-item.is-overdue .todo-title { color: var(--danger); }
.todo-overdue-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(220, 38, 38, .12);
  color: var(--danger);
  font-size: 11.5px;
  font-weight: 600;
}

.remind-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.todo-check-label { display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-size: 13px; }
.todo-check-label input { width: 16px; height: 16px; accent-color: var(--primary); }
.remind-row select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 13px;
}
.remind-row select:disabled { opacity: .5; }
#todoDeleteBtn { margin-right: auto; }

.weekday-picks { display: flex; gap: 6px; flex-wrap: wrap; }
.weekday-pick {
  width: 32px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}
.weekday-pick.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-dark);
  font-weight: 600;
}
.month-picks { gap: 5px; }
.month-picks .weekday-pick { width: auto; min-width: 32px; padding: 0 4px; }

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: #1b1e23;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(90vw, 480px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 窄屏适配 ---------- */
/* 触屏无 hover，卡片操作按钮常显 */
@media (hover: none) {
  .project-actions { opacity: 1; }
}

@media (max-width: 820px) {
  /* 窄屏改为普通块级流式布局：网格行的 stretch 会把顶栏拉高并居中，导致上下大片空白 */
  .app { display: block; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    overflow-x: auto;
  }
  .brand-text small { display: none; }
  .nav { flex-direction: row; gap: 4px; }
  .nav-item { white-space: nowrap; }
  .main { padding: 18px 14px 32px; }
  .timer-item { padding: 10px 12px 10px 24px; }
  .summary { gap: 16px; }
  .ledger-bar { flex-wrap: wrap; }
}

/* 仅在 360px 及以下的窄屏才改为上下排列 */
@media (max-width: 360px) {
  .timer-item { gap: 8px; }
  .timer-head { flex-basis: 100%; }
  .timer-body { justify-content: flex-start; }
  .timer-actions { margin-left: 0; }
}
