:root {
  --bg: #f4f7f3;
  --surface: #ffffff;
  --paper: #f7faf7;
  --soft: #eaf4ee;
  --line: #e2e9e3;
  --ink: #223027;
  --muted: #65766b;
  --accent: #3d7d59;
  --accent-strong: #2f6848;
  --pause: #c96b4d;
  --pause-bg: #fff2ec;
  --break: #a87524;
  --break-bg: #fcf6e7;
  --danger: #b54534;
  --danger-bg: #fff1ee;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  touch-action: manipulation;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex-shrink: 0;
  height: 44px;
  padding: 0 14px;
  background: #f4f7f3;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.topbar-brand strong {
  font-size: 15px;
  font-weight: 600;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8a9db5;
  flex-shrink: 0;
}

.brand-dot.working { background: var(--accent); }
.brand-dot.paused { background: var(--pause); }
.brand-dot.scheduled-break { background: #cf9a3e; }

.topbar-date {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e9eef3;
  color: #4f6278;
  white-space: nowrap;
}

.status-pill.working { background: var(--soft); color: var(--accent); }
.status-pill.paused { background: var(--pause-bg); color: var(--pause); }
.status-pill.scheduled-break { background: var(--break-bg); color: var(--break); }

.alert-banner {
  margin: 10px 12px 0;
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 12px;
}

.views {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 14px;
}

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

.view[hidden] {
  display: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
}

.card h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

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

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

.sub-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.sub-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--paper);
  padding: 1px 4px;
  border-radius: 4px;
}

/* Punch card (compact single-hand) */
.punch-card {
  padding: 14px 15px;
}

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

.punch-time {
  margin: 4px 0 8px;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.4px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.progress-track {
  height: 4px;
  border-radius: 4px;
  background: var(--soft);
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.25s ease;
}

.break-banner {
  margin: -4px 0 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--break-bg);
  color: var(--break);
  font-size: 12px;
}

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

.punch-actions .btn {
  flex: 1;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

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

.btn-sm {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 13px;
}

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

.btn-primary:active {
  background: var(--accent-strong);
}

.btn-soft {
  background: var(--soft);
  color: var(--accent);
  border-color: #cde3d5;
}

.btn-outline {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.btn-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 2px;
}

/* Today intervals & events */
.today-break-tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--break-bg);
  color: var(--break);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.interval-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.interval-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 3px 8px 8px 3px;
  background: var(--paper);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.interval-item.paused {
  border-left-color: var(--pause);
}

.interval-item.scheduled-break {
  border-left-color: #cf9a3e;
  background: var(--break-bg);
}

.interval-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.interval-left strong {
  font-weight: 600;
}

.interval-dur {
  flex-shrink: 0;
  color: var(--muted);
}

.event-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.event-list:empty {
  display: none;
}

.event-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid #eef2ee;
  font-size: 12px;
}

.event-item:last-child {
  border-bottom: 0;
}

.event-item time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.empty-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Stats view */
.stats-filter-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.segment {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.segment-btn {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  min-height: 32px;
}

.segment-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(34, 48, 39, 0.08);
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ctrl-row[hidden], .ctrl-stack[hidden] {
  display: none;
}

.chip-row {
  display: flex;
  gap: 6px;
}

.chip {
  flex: 1;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.chip.active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
  font-weight: 600;
}

.date-pair-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

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

.range-caption {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="date"],
input[type="time"],
input[type="number"],
select {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}

#stats-ctrl-day input[type="date"] {
  flex: 1;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 11px;
  color: var(--muted);
}

.metric-cell strong {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-cell small {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.day-rows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}

.day-row-btn {
  width: 100%;
  min-height: 40px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) auto auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.day-row-btn:active {
  background: var(--soft);
}

.day-row-btn.is-zero {
  color: var(--muted);
}

.day-row-work {
  font-weight: 600;
  text-align: right;
}

.day-row-break {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  min-width: 58px;
}

/* Settings view */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch {
  position: relative;
  width: 44px;
  height: 25px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: #c8d1ca;
  transition: background 0.2s;
}

.switch span::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
  transition: transform 0.2s;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(19px);
}

.break-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.break-list.is-disabled {
  opacity: 0.5;
}

.break-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.row-actions {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.row-actions.end {
  justify-content: flex-end;
}

.pref-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
}

.backup-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.backup-actions .btn {
  padding: 6px 6px;
  font-size: 12px;
}

.inline-error {
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 12px;
}

/* Bottom tabbar (in-flow flex footer so OPPO browser never clips or shifts it) */
.tabbar {
  flex-shrink: 0;
  width: 100%;
  z-index: 20;
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 8px rgba(34, 48, 39, 0.05);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px 0 calc(6px + env(safe-area-inset-bottom, 0px));
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
}

.tab-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab-btn.active {
  color: var(--accent);
  font-weight: 600;
}

/* Bottom sheet (avoid <dialog> for old ColorOS WebView compatibility) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20, 32, 24, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop[hidden] {
  display: none;
}

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.sheet-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.icon-close {
  border: 0;
  background: var(--paper);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}

.sheet-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--soft);
  color: var(--accent);
  margin-bottom: 10px;
}

.sheet-summary strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.sheet-foot {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 10px 0;
}

.radio-group label {
  position: relative;
}

.radio-group input {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  opacity: 0;
}

.radio-group span {
  display: block;
  text-align: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  background: var(--paper);
}

.radio-group input:checked + span {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent);
  font-weight: 600;
}

.duration-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.preview-box {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.preview-box.invalid {
  background: var(--danger-bg);
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(34, 48, 39, 0.92);
  color: #ffffff;
  font-size: 13px;
  white-space: nowrap;
}
