:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #66716d;
  --border: #dde3e0;
  --accent: #0f766e;
  --accent-soft: #d5efeb;
  --end: #c2410c;
  --break: #b45309;
  --break-soft: #fdf0d8;
  --danger: #b91c1c;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1c2220;
    --text: #e8eeeb;
    --muted: #97a39e;
    --border: #2d3633;
    --accent: #2dd4bf;
    --accent-soft: #163a35;
    --end: #fb923c;
    --break: #fbbf24;
    --break-soft: #3a2e14;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }

main { max-width: 560px; margin: 0 auto; padding: 0 16px 16px; }

.tab { display: none; }
.tab.active { display: block; }

/* 記録 */
.clock { text-align: center; margin: 8px 0 12px; }
.clock-date { color: var(--muted); }
.clock-time { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-bottom: 16px;
}
.status-card.working { background: var(--accent-soft); border-color: transparent; }
.status-card.on-break { background: var(--break-soft); border-color: transparent; }
.status-label { font-weight: 700; color: var(--muted); }
.working .status-label { color: var(--accent); }
.on-break .status-label { color: var(--break); }
.elapsed { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.status-sub { color: var(--muted); font-size: 0.9rem; min-height: 1.35em; }

.main-btn {
  display: block;
  width: 100%;
  height: 120px;
  border: 0;
  border-radius: 24px;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s;
}
.main-btn:active { transform: scale(0.98); }
.main-btn.start { background: var(--accent); }
.main-btn.end { background: var(--end); }
@media (prefers-color-scheme: dark) {
  .main-btn { color: #0b0f0e; }
}

.sub-btn, .primary-btn, .danger-btn {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .primary-btn { color: #0b0f0e; } }
.danger-btn { color: var(--danger); background: transparent; border-color: transparent; padding-left: 0; }

#break-btn { display: block; width: 100%; margin-top: 12px; min-height: 52px; }
#break-btn[hidden] { display: none; }

.field { display: block; margin-bottom: 12px; }
.field[hidden] { display: none; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.field select:disabled { opacity: 0.5; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 8px; }
.section-head h2 { font-size: 1rem; margin: 0; }
.pill { background: var(--accent-soft); color: var(--accent); font-weight: 700; padding: 2px 10px; border-radius: 99px; font-variant-numeric: tabular-nums; }

.entry-list { list-style: none; margin: 0; padding: 0; }
.entry { margin-bottom: 6px; }
.entry-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}
.entry-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.entry-range { font-weight: 600; font-variant-numeric: tabular-nums; }
.entry-meta { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta:empty { display: none; }
.entry-min { font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 16px; }

.day-head { display: flex; justify-content: space-between; font-weight: 700; margin: 16px 2px 6px; font-variant-numeric: tabular-nums; }
.day-head .sun { color: var(--danger); }
.day-head .sat { color: #2563eb; }
@media (prefers-color-scheme: dark) { .day-head .sat { color: #60a5fa; } }

/* 月次 */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.month-label { font-size: 1.25rem; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat:first-child { background: var(--accent-soft); border-color: transparent; }
.stat.wide { grid-column: 1 / -1; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }
.client-row { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.client-row:first-of-type { border-top: 0; }

.btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.btn-row > * { flex: 1; text-align: center; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; }

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

/* タブバー */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
}
.tab-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-btn.active { color: var(--accent); font-weight: 700; }

/* ダイアログ */
dialog {
  width: min(520px, calc(100vw - 32px));
  border: 0;
  border-radius: 18px;
  padding: 20px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 16px; font-size: 1.15rem; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.dialog-actions .spacer { flex: 1; }
[hidden] { display: none !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 99px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
