:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #17212b;
  --muted: #667482;
  --line: #dbe3ea;
  --primary: #0f766e;
  --primary-soft: #d9efec;
  --danger: #c2410c;
  --amber: #b45309;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(23,33,43,.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.app {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px max(18px, env(safe-area-inset-left)) 10px max(18px, env(safe-area-inset-right));
  background: rgba(244,246,248,.92);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.brand { font-size: 19px; font-weight: 700; letter-spacing: 0; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.dot.online { background: #059669; }
.dot.offline { background: var(--danger); }

.tabs {
  position: sticky;
  top: 55px;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right));
  background: rgba(244,246,248,.95);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.tab[aria-selected="true"] { background: #fff; color: var(--primary); box-shadow: 0 1px 5px rgba(23,33,43,.08); }

main { padding: 18px max(14px, env(safe-area-inset-left)) calc(28px + env(safe-area-inset-bottom)); }
.view[hidden] { display: none; }
.section { margin-top: 22px; }
.section:first-child { margin-top: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
h1, h2, h3 { letter-spacing: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.small { font-size: 13px; color: var(--muted); }

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

.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
label { display: block; color: var(--muted); font-size: 13px; font-weight: 650; margin-bottom: 5px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 11px 12px;
  font: inherit;
  color: var(--ink);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
textarea { resize: vertical; min-height: 88px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 180px; min-width: 0; }

button, .button {
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover { filter: brightness(.96); }
button.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
button.quiet { background: transparent; color: var(--primary); min-height: 34px; padding: 5px 8px; }
button.danger { background: #fff; color: var(--danger); border-color: #ecc4ae; }
button.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  min-height: 32px;
  padding: 5px 12px;
  font-size: 13px;
}

.task-list, .day-list { display: grid; gap: 10px; }
.task {
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.task.running { border-color: #9fd3cc; box-shadow: inset 4px 0 0 var(--primary); }
.task-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.name { font-weight: 700; word-break: break-word; }
.timer { color: var(--primary); font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef2f5;
  color: #48586a;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.badge.tag { background: var(--primary-soft); color: #065f58; }
.actions { display: flex; gap: 7px; margin-top: 11px; flex-wrap: wrap; }
.note-preview { margin-top: 8px; color: var(--muted); font-size: 14px; white-space: pre-wrap; }

.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.metric { padding: 13px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.metric-label { font-size: 12px; color: var(--muted); }
.metric-value { margin-top: 4px; font-size: 21px; font-weight: 750; font-variant-numeric: tabular-nums; }

.bars { display: grid; grid-template-columns: repeat(14, 1fr); gap: 5px; align-items: end; height: 130px; }
.bar-col { display: grid; grid-template-rows: 1fr auto; gap: 4px; height: 100%; text-align: center; }
.bar-track { display: flex; align-items: end; }
.bar { width: 100%; min-height: 3px; border-radius: 4px 4px 0 0; background: #a7d4cf; }
.bar.today { background: var(--primary); }
.bar-date { font-size: 9px; color: var(--muted); transform: rotate(-42deg); white-space: nowrap; }
.tag-row { display: grid; grid-template-columns: 88px 1fr 54px; gap: 8px; align-items: center; margin-bottom: 9px; font-size: 13px; }
.tag-track { height: 8px; background: #edf1f4; border-radius: 999px; overflow: hidden; }
.tag-fill { height: 100%; background: var(--primary); border-radius: inherit; }
.tag-value { text-align: right; font-variant-numeric: tabular-nums; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  z-index: 99;
  max-width: min(90vw, 420px);
  padding: 11px 15px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  opacity: 0;
  transition: .18s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  align-items: end;
  justify-content: center;
  background: rgba(15,23,32,.44);
  padding: max(14px, env(safe-area-inset-bottom));
}
.dialog.open { display: flex; }
.dialog-panel { width: min(520px, 100%); max-height: 88vh; overflow: auto; background: #fff; border-radius: 14px; padding: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.api-code { display: block; overflow-x: auto; padding: 10px; background: #17212b; color: #dff5f1; border-radius: 8px; font-size: 12px; white-space: pre; }

@media (max-width: 420px) {
  main { padding-top: 14px; }
  .panel { padding: 14px; }
  .metric-value { font-size: 19px; }
  .timer { font-size: 19px; }
}

@media (min-width: 640px) {
  .form-grid { grid-template-columns: 1fr 240px; align-items: end; }
  .form-grid .full { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: repeat(4, 1fr); }
  .dialog { align-items: center; padding: 18px; }
}

@media (display-mode: standalone) {
  body { user-select: none; }
  input, textarea { user-select: text; }
}
