:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --morning: #0d9488;
  --morning-soft: #f0fdfa;
  --morning-border: #99f6e4;
  --afternoon: #2563eb;
  --afternoon-soft: #eff6ff;
  --afternoon-border: #bfdbfe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
  --radius: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 20px 40px;
}

/* 顶栏 */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  color: #ffffff;
  font-weight: 700;
  font-size: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sync-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync-dot.is-ok {
  background: var(--success);
}

.sync-dot.is-loading {
  background: var(--warning);
  animation: pulse 1.2s infinite ease-in-out;
}

.sync-dot.is-error {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.sync-text {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.auth-pill:hover {
  background: #e2e8f0;
}

.auth-pill.is-unlocked {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.auth-pill.is-locked {
  background: var(--warning-soft);
  border-color: #fde68a;
  color: #92400e;
}

.auth-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

/* 主工作台响应式布局 */
.workbench {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.punch-panel {
  position: sticky;
  top: 16px;
}

.analytics-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.date-tag {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #dbeafe;
  color: #1e40af;
  white-space: nowrap;
}

.date-tag.is-history {
  background: #f1f5f9;
  color: #475569;
}

/* 口令横幅 */
.lock-banner {
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lock-banner-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: #92400e;
}

.inline-unlock-form {
  display: flex;
  gap: 8px;
}

.inline-unlock-form input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
}

.unlock-banner {
  background: var(--success-soft);
  border: 1px solid #a7f3d0;
  color: #065f46;
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 14px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 日期选择行 */
.date-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}

.date-switcher input[type="date"] {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-subtle);
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: var(--surface-subtle);
}

/* 今日时长核心展示卡 */
.duration-hero {
  background: linear-gradient(135deg, #0f172a, #1e293b);
  color: #ffffff;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.duration-hero-label {
  display: block;
  font-size: 12px;
  color: #cbd5e1;
}

.duration-hero-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.duration-hero-value strong {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.duration-decimal {
  font-size: 13px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.duration-breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.segment-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
}

.seg-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.segment-pill.is-morning .seg-dot {
  background: #2dd4bf;
}

.segment-pill.is-afternoon .seg-dot {
  background: #60a5fa;
}

/* 4次打卡分组 */
.punch-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.segment-group {
  border-radius: 11px;
  padding: 12px;
  border: 1px solid var(--border);
}

.segment-group.is-morning {
  background: var(--morning-soft);
  border-color: var(--morning-border);
}

.segment-group.is-afternoon {
  background: var(--afternoon-soft);
  border-color: var(--afternoon-border);
}

.segment-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.seg-title-badge {
  font-size: 12px;
  font-weight: 700;
}

.segment-group.is-morning .seg-title-badge {
  color: #0f766e;
}

.segment-group.is-afternoon .seg-title-badge {
  color: #1d4ed8;
}

.seg-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.punch-grid {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.punch-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.overnight-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
}

.time-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.time-input-wrap input[type="time"] {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #ffffff;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.btn-now {
  height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: 9px;
  background: #0f172a;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.btn-now:hover {
  background: #334155;
}

.btn-clear-field {
  width: 32px;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.btn-clear-field:hover {
  background: var(--danger-soft);
  border-color: #fecaca;
  color: var(--danger);
}

.note-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.note-field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-subtle);
  font-size: 13px;
  resize: vertical;
}

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

/* 通用按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block {
  flex: 1;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-export {
  background: linear-gradient(135deg, #0f766e, #2563eb);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.22);
}

.btn-export:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-subtle {
  background: var(--surface-subtle);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-subtle:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-danger-outline {
  background: #ffffff;
  border-color: #fecaca;
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-link {
  border: none;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

/* 筛选条 */
.filter-panel {
  padding: 14px 16px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quick-range-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-btn {
  height: 34px;
  padding: 0 13px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.range-btn:hover {
  background: #e2e8f0;
}

.range-btn.is-active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.custom-range-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-range-group input[type="date"] {
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-subtle);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.range-sep {
  font-size: 13px;
  color: var(--text-muted);
}

/* 统计指标卡 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* 图表区 */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

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

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

.dot.morning {
  background: var(--morning);
}

.dot.afternoon {
  background: var(--afternoon);
}

.chart-box {
  position: relative;
  width: 100%;
  height: 290px;
}

#hoursChart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  color: #ffffff;
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  z-index: 5;
  min-width: 185px;
}

.tooltip-date {
  font-weight: 700;
  margin-bottom: 5px;
  color: #f8fafc;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: #cbd5e1;
}

.tooltip-total {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  font-weight: 600;
  color: #ffffff;
}

/* Word 报告区 */
.narrative-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.narrative-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.narrative-meta label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.edited-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1e40af;
  font-weight: 600;
}

.narrative-box textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-subtle);
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
}

.export-bar {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* 明细表格 */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.records-table th {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.records-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.records-table tbody tr:last-child td {
  border-bottom: none;
}

.records-table tbody tr:hover {
  background: #f8fafc;
}

.note-cell {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

.empty-cell {
  text-align: center;
  padding: 28px 12px !important;
  color: var(--text-muted);
}

.table-edit-btn {
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.table-edit-btn:hover {
  background: var(--afternoon-soft);
  border-color: var(--afternoon-border);
  color: var(--primary);
}

/* 弹窗 */
.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.modal-card h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.modal-card p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-form input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 15px;
}

.modal-error {
  margin: 0 !important;
  font-size: 12px !important;
  color: var(--danger) !important;
  font-weight: 600;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
  z-index: 60;
}

.toast.is-error {
  background: var(--danger);
}

/* 平板与手机端自适应 */
@media (max-width: 1120px) {
  .workbench {
    grid-template-columns: 1fr;
  }

  .punch-panel {
    position: static;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .app-shell {
    padding: 12px 12px 32px;
  }

  .topbar {
    padding: 12px 14px;
  }

  .panel {
    padding: 14px;
  }

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

  .custom-range-group {
    width: 100%;
  }

  .custom-range-group input[type="date"] {
    flex: 1;
    min-width: 0;
  }

  .export-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-box {
    height: 245px;
  }
}
