:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --border: #e2dfd9;
  --text: #1f1e1c;
  --muted: #77736b;
  --accent: #1c8a60;
  --accent-text: #ffffff;
  --stop: #c9412f;
  --hover: #efede8;
  --none: #b9b5ad;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #262522;
    --border: #3a3834;
    --text: #efede8;
    --muted: #a09b92;
    --accent: #2fa877;
    --stop: #e0604f;
    --hover: #302e2b;
    --none: #5e5a54;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }

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

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  -webkit-app-region: drag;
}

body.mac .topbar { padding-left: 88px; }

.topbar button { -webkit-app-region: no-drag; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 9px;
  background: var(--bg);
}

.tab {
  border: 0;
  padding: 5px 16px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.running-pill {
  margin-left: auto;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 4px 12px;
  background: transparent;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.sign-out { margin-left: auto; }

.running-pill:not([hidden]) + .sign-out { margin-left: 0; }

/* Layout */

main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 48px;
}

.view {
  max-width: 900px;
  margin: 0 auto;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 12px;
}

.view > .section-head:first-child { margin-top: 0; }

h2 { margin: 0; font-size: 17px; }
h3 { margin: 0 0 14px; font-size: 16px; }

.spacer { flex: 1; }

.empty {
  padding: 36px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}

/* Controls */

input[type="text"], input[type="password"], input[type="date"], input[type="time"], select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

input[type="color"] {
  width: 46px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

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

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.primary:hover { filter: brightness(1.07); }

.btn.danger { color: var(--stop); }

.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }

.chip {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.chip:hover { background: var(--hover); }

.chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c, var(--none));
}

/* Timer */

.timer-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.timer-card.running { border-color: var(--accent); }

.timer-desc { flex: 1 1 260px; }

.timer-card select { flex: 0 1 190px; min-width: 130px; }

.timer-elapsed {
  min-width: 104px;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.timer-toggle { min-width: 84px; height: 38px; }

.timer-card.running .timer-toggle {
  border-color: var(--stop);
  background: var(--stop);
}

/* Entry list */

.day {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.day-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.day-total { font-variant-numeric: tabular-nums; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
}

.entry + .entry { border-top: 1px solid var(--border); }

.entry.flash { animation: flash 1.6s ease-out; }

@keyframes flash {
  from { background: color-mix(in srgb, var(--accent) 22%, transparent); }
  to { background: transparent; }
}

.entry-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.entry-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-project, .entry-range { color: var(--muted); font-size: 13px; }

.entry-range { white-space: nowrap; }

.entry-dur {
  min-width: 66px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.entry-actions { display: flex; gap: 6px; }

.muted { color: var(--muted); }

.more { display: block; margin: 0 auto; }

/* To-dos */

.todo-add {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.todo-add input { flex: 1 1 260px; }

.todo-add select { flex: 0 1 190px; min-width: 130px; }

.todo input[type="checkbox"] {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.todo input.todo-text {
  flex: 1;
  min-width: 0;
  padding: 0 6px;
  border-color: transparent;
  background: transparent;
  text-overflow: ellipsis;
}

.todo input.todo-text:hover, .todo input.todo-text:focus { border-color: var(--border); }

.todo.done input.todo-text { color: var(--muted); text-decoration: line-through; }

.done-todos summary { cursor: pointer; }

.done-todos:not([open]) summary { border-bottom: 0; }

.done-todos .entry { border-top: 1px solid var(--border); }

.done-todos summary + .entry { border-top: 0; }

/* Projects */

.project {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.project + .project { margin-top: 8px; }

.project.archived .project-name { color: var(--muted); }

.project-name { flex: 1; min-width: 0; font-weight: 600; }

.project-meta {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* Reports */

.report-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.presets, .project-filter { display: flex; flex-wrap: wrap; gap: 6px; }

.project-filter .chip { display: inline-flex; align-items: center; gap: 6px; }

.range { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

.range label { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.range input { color: var(--text); }

.report-total {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 16px;
  margin: 24px 0 14px;
}

.report-total strong {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

table {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  border-spacing: 0;
  background: var(--surface);
  overflow: hidden;
}

th, td {
  padding: 9px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody td, tfoot td { border-top: 1px solid var(--border); }

tfoot td { font-weight: 600; }

.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.cell-project { display: flex; align-items: center; gap: 8px; }

.bar-cell { width: 28%; }

.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--c, var(--none));
}

.nowrap { white-space: nowrap; }

/* Dialogs */

dialog {
  width: min(580px, 92vw);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.35); }

#confirm-dialog, #login-dialog { width: min(420px, 92vw); }

dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

dialog label input, dialog label select { color: var(--text); font-size: 14px; }

.field-row { display: flex; flex-wrap: wrap; gap: 10px; }

.field-row label { flex: 1 1 110px; }

.field-row label.grow { flex: 4 1 240px; }

.field-row input[type="text"], .field-row input[type="date"], .field-row input[type="time"] { width: 100%; }

.hint { min-height: 20px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }

.hint.error { color: var(--stop); }

.dialog-actions { display: flex; gap: 8px; margin-top: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 9px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
}

/* Phones */

@media (max-width: 640px) {
  /* Anything smaller makes iOS zoom the page when a field is focused. */
  input[type="text"], input[type="password"], input[type="date"], input[type="time"], select { font-size: 16px; height: 40px; }

  .btn { height: 40px; }
  .btn.small { height: 34px; }

  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .tabs { flex: 1 1 100%; }
  .tab { flex: 1; padding: 8px 4px; }
  .running-pill { margin-left: 0; max-width: none; flex: 1; text-align: left; }

  main { padding: 16px 12px 40px; }

  .timer-card select, .todo-add select { flex: 1 1 100%; }
  .timer-elapsed { flex: 1; text-align: left; }

  .entry, .project { flex-wrap: wrap; gap: 8px 10px; }
  .entry-text { flex: 1 1 60%; }
  .entry-range { flex: 1; }
  .entry-actions { flex: 1 1 100%; justify-content: flex-end; }
  .todo .entry-actions { flex: none; }
  .todo input.todo-text { flex: 1 1 60%; }
  .project-name { flex: 1 1 60%; }
  .project-meta { flex: 1 1 100%; }

  #report-output { overflow-x: auto; }
  .bar-cell { display: none; }
  th, td { padding: 8px 10px; }
}
