:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #e8f1ef;
  --text: #16201f;
  --muted: #667574;
  --line: #d8e0de;
  --primary: #0f766e;
  --primary-dark: #155e75;
  --danger: #b42318;
  --warning: #f05252;
  --success: #16a34a;
  --shadow: 0 12px 35px rgba(21, 34, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.file-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: #a9b9b6;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.danger {
  border-color: #f2b8b5;
  color: var(--danger);
}

.ghost {
  background: transparent;
  min-height: 34px;
  color: var(--muted);
}

.app-shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar,
.today-band,
.toolbar,
.habit-title-row,
.section-head,
menu,
.button-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar,
.today-band,
.section-head {
  justify-content: space-between;
}

.topbar h1,
.today-band h2,
.section-head h2,
.habit-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 32px;
}

.app-switcher,
.tabs {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

.app-tab,
.tab,
.time-tab {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
}

.app-tab {
  min-height: 46px;
  font-size: 18px;
  font-weight: 750;
}

.app-tab.active,
.tab.active,
.time-tab.active {
  background: var(--primary);
  color: white;
}

.app-section,
.view,
.time-view {
  display: none;
}

.app-section[hidden],
.view[hidden],
.time-view[hidden],
.time-view:not(.active),
.view:not(.active) {
  display: none !important;
}

.app-section.active,
.view.active,
.time-view.active {
  display: block;
}

.section-head {
  margin: 22px 0 14px;
}

.eyebrow,
.date-label,
.hint,
.metric small {
  color: var(--muted);
}

.eyebrow,
.date-label {
  margin: 0 0 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.sync-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 8px 12px;
  color: var(--muted);
  white-space: nowrap;
}

.sync-pill.online {
  color: var(--primary);
  border-color: #9ad7ce;
  background: #e7f8f5;
}

.sync-pill.error {
  color: var(--danger);
  border-color: #f4b7b1;
  background: #fff1f0;
}

.today-band {
  margin-top: 22px;
  padding: 18px;
  background: var(--primary-dark);
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.today-band .date-label {
  color: #cce8e5;
}

.today-band h2 {
  font-size: 25px;
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 28px;
  line-height: 1;
}

.icon-button.dark {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.date-button {
  display: grid;
  justify-items: center;
  min-width: 220px;
  min-height: auto;
  padding: 6px 18px;
  border: 0;
  background: transparent;
  color: white;
}

.date-button:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: transparent;
}

.today-jump-button {
  min-height: 38px;
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.today-jump-button:hover {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.18);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.day-strip {
  display: flex;
  gap: 10px;
  margin: 14px -4px 16px;
  padding: 4px 4px 10px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.day-chip {
  flex: 0 0 58px;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 82px;
  border: 0;
  background: transparent;
  padding: 4px;
  color: var(--muted);
}

.day-chip:hover {
  border-color: transparent;
  background: #eef5f3;
}

.day-chip-weekday {
  font-size: 13px;
  font-weight: 650;
}

.day-chip-ring {
  --progress: 0deg;
  --ring-color: var(--warning);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--ring-color) var(--progress), #ffdbe5 0);
  position: relative;
}

.day-chip-ring::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: inherit;
  background: var(--surface);
}

.day-chip-date,
.day-chip-check {
  position: relative;
  z-index: 1;
  font-weight: 750;
  color: var(--text);
}

.day-chip-check {
  color: var(--success);
}

.day-chip.complete .day-chip-ring {
  --ring-color: var(--success);
  background: conic-gradient(var(--success) 360deg, var(--success) 0);
}

.day-chip.selected {
  background: #e7f8f5;
  border-radius: 8px;
}

.day-chip.selected .day-chip-ring::before {
  background: #e7f8f5;
}

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

.metric span {
  display: block;
  font-size: 28px;
  font-weight: 750;
}

.toolbar {
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.habit-list {
  display: grid;
  gap: 12px;
}

.habit-card {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.habit-card.quit-habit {
  border-color: #f3c5cf;
}

.habit-card.quit-habit .quick-adds button {
  border-color: #ffc4d2;
  background: #fff7fa;
  color: #be123c;
}

.check-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  border-width: 2px;
  position: relative;
}

.check-button.done::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 24px;
  font-weight: 800;
}

.habit-main {
  min-width: 0;
}

.habit-title-row {
  justify-content: space-between;
  align-items: flex-start;
}

.habit-card h3 {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.habit-target {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.progress-track {
  height: 8px;
  margin: 12px 0;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
}

.progress-controls {
  display: grid;
  grid-template-columns: 42px minmax(110px, 170px) 42px 30px;
  gap: 8px;
  align-items: end;
  margin: 8px 0;
}

.step-button {
  min-height: 42px;
  padding: 0;
  font-size: 22px;
  font-weight: 750;
}

.count-field {
  gap: 4px;
}

.count-field span {
  font-size: 12px;
}

.count-input {
  text-align: center;
  font-weight: 750;
}

.quick-adds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 12px;
}

.quick-adds button {
  min-height: 34px;
  border-color: #bfe4df;
  background: #eefaf8;
  color: var(--primary);
}

.reset-count-button {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  align-self: center;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  opacity: 0.72;
  font-size: 15px;
}

.reset-count-button:hover {
  color: var(--danger);
  opacity: 1;
}

.note-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  max-width: 620px;
}

.note-button {
  flex: 0 0 38px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
  font-size: 18px;
}

.note-button.has-note {
  color: var(--primary);
  border-color: #bfe4df;
  background: #eefaf8;
}

.note-text {
  display: none;
  min-height: 34px;
  text-align: left;
  color: var(--muted);
  background: #f8faf9;
  overflow-wrap: anywhere;
}

.note-text.visible {
  display: block;
  flex: 1;
}

.stats-layout {
  display: grid;
  gap: 18px;
}

.rate-card {
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 30px 16px;
}

.rate-ring {
  --progress: 0deg;
  width: min(320px, 74vw);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(#ff6b7a var(--progress), #ffd7e3 0);
  position: relative;
}

.rate-ring::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: inherit;
  background: var(--surface);
}

.rate-ring-content {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
}

.rate-ring strong {
  font-size: 38px;
}

.stats-grid,
.history-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.mini-chart {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  align-items: end;
  gap: 6px;
  min-height: 150px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mini-chart-bar {
  min-height: 8px;
  border-radius: 6px 6px 0 0;
  background: var(--primary);
}

.history-content {
  display: grid;
  gap: 14px;
}

.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.month-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px;
}

.month-switcher button {
  min-height: 34px;
  width: 34px;
  padding: 0;
  font-size: 22px;
}

.month-switcher strong {
  min-width: 150px;
  text-align: center;
}

.history-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.history-day {
  min-height: 58px;
  border-radius: 8px;
  background: #eef0ef;
  padding: 7px;
  display: grid;
  align-content: space-between;
}

.history-day.partial {
  background: #dff6ed;
}

.history-day.off {
  background: #f8faf9;
  color: #a5b0ae;
}

.history-day.done {
  background: #86efac;
}

.history-day.over {
  background: #22c55e;
  color: white;
}

.habit-admin-list {
  display: grid;
  gap: 10px;
}

.admin-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.admin-row p {
  margin: 4px 0 0;
  color: var(--muted);
}

.page-calendar {
  margin-bottom: 18px;
}

.page-calendar .calendar-day {
  min-height: 82px;
}

.stats-layout .metric span,
.history-metrics .metric span {
  font-size: 24px;
  overflow-wrap: anywhere;
}

.history-day small {
  color: inherit;
  opacity: 0.75;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.admin-row strong {
  overflow-wrap: anywhere;
}

.time-summary-card,
.active-timer-card {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
  background: #17201f;
  color: white;
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 14px;
}

.time-ring {
  width: 180px;
  background: conic-gradient(#38bdf8 var(--progress, 0deg), #33403f 0);
}

.time-ring::before {
  background: #17201f;
}

.time-top-list,
.time-log-list {
  display: grid;
  gap: 8px;
}

.time-top-row,
.time-log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 0;
}

.time-log-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.activity-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.activity-tile {
  min-height: 160px;
  border: 0;
  border-radius: 8px;
  padding: 16px;
  color: white;
  display: grid;
  align-content: space-between;
  justify-items: center;
  text-align: center;
  box-shadow: var(--shadow);
}

.activity-tile.running {
  outline: 4px solid #38bdf8;
  outline-offset: 3px;
}

.activity-tile strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.activity-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.22);
  font-size: 24px;
}

.activity-time {
  font-weight: 800;
}

.active-timer-card {
  grid-template-columns: 150px 1fr auto;
}

.active-timer-card.empty-timer {
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
}

.time-day-grid {
  display: grid;
  grid-template-columns: 54px repeat(12, 1fr);
  gap: 5px;
  align-items: stretch;
}

.time-hour-label {
  color: var(--muted);
  padding-top: 6px;
}

.time-slot {
  min-height: 28px;
  border-radius: 5px;
  background: #26302f;
}

.time-slot.filled {
  background: var(--primary);
}

.time-color-dot {
  width: 10px;
  height: 36px;
  border-radius: 999px;
  flex: 0 0 10px;
}

.active-timer-list {
  display: grid;
  gap: 8px;
}

.active-timer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.active-timer-row button {
  min-height: 34px;
}

.time-report-card {
  display: grid;
  grid-template-columns: minmax(260px, 380px) 1fr;
  gap: 22px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.time-donut-wrap {
  position: relative;
  width: min(360px, 80vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0 auto;
}

.time-donut {
  width: 100%;
  height: 100%;
}

.time-donut circle {
  fill: none;
  stroke-linecap: butt;
}

.time-donut-center {
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  background: white;
  border: 1px solid var(--line);
  text-align: center;
}

.time-donut-center strong,
.time-donut-empty strong {
  font-size: 25px;
}

.time-donut-empty {
  width: min(320px, 76vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 26px solid #d7dedc;
  display: grid;
  place-items: center;
  align-content: center;
  margin: 0 auto;
}

.time-report-legend {
  display: grid;
  gap: 10px;
}

.time-report-legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.legend-swatch {
  width: 6px;
  height: 32px;
  border-radius: 999px;
}

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

.schedule-panel {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.schedule-panel[hidden] {
  display: none;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

.choice-row input {
  width: auto;
}

.checkbox-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.checkbox-row input {
  width: auto;
}

.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-picker button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  color: var(--text);
}

select {
  min-height: 42px;
  max-width: 280px;
}

textarea {
  resize: vertical;
  min-height: 58px;
}

dialog {
  width: min(520px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 26, 28, 0.45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
}

.dialog-card.wide {
  width: min(680px, 100%);
}

.dialog-card h2,
.hint {
  margin: 0;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.calendar-header h2 {
  text-align: center;
  font-size: 22px;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-weekdays span {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.calendar-day {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
  display: grid;
  align-content: space-between;
  text-align: left;
}

.calendar-day.outside {
  color: #9aa8a6;
  background: #f8faf9;
}

.calendar-day.selected {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px var(--primary);
}

.calendar-day.today {
  background: #e7f8f5;
}

.calendar-day.complete {
  border-color: #86efac;
  background: #ecfdf3;
}

.calendar-day.complete .calendar-number::after {
  content: " ✓";
  color: var(--success);
}

.calendar-day.partial {
  border-color: #ffc4d2;
  background: #fff7fa;
}

.calendar-number {
  font-weight: 750;
}

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

.hint.small {
  font-size: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

label input,
label textarea {
  color: var(--text);
}

menu {
  margin: 0;
  padding: 0;
  justify-content: flex-end;
}

menu span {
  flex: 1;
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  background: #102021;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  max-width: min(560px, calc(100% - 28px));
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%);
}

.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 26px;
  }

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

  .today-band {
    flex-wrap: wrap;
  }

  .today-jump-button {
    order: 4;
    flex: 1 1 100%;
  }

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

  .app-switcher {
    grid-template-columns: 1fr;
  }

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

  .time-summary-card,
  .active-timer-card {
    grid-template-columns: 1fr;
  }

  .time-entry-grid {
    grid-template-columns: 1fr;
  }

  .time-report-card {
    grid-template-columns: 1fr;
  }

  .time-report-legend-row {
    grid-template-columns: 12px 1fr;
  }

  .time-report-legend-row strong {
    grid-column: 2;
  }

  .history-actions,
  .history-actions select {
    width: 100%;
  }

  .day-chip {
    flex-basis: 52px;
  }

  .habit-card {
    grid-template-columns: 44px 1fr;
    padding: 12px;
  }

  .check-button {
    width: 42px;
    height: 42px;
  }

  .button-row,
  .toolbar {
    align-items: stretch;
  }

  .button-row > *,
  .toolbar > * {
    flex: 1 1 150px;
  }

  .calendar-day {
    min-height: 54px;
    padding: 6px;
  }

  .calendar-progress {
    font-size: 11px;
  }

  .progress-controls {
    grid-template-columns: 40px minmax(96px, 1fr) 40px 30px;
  }
}
