:root {
  --paper: oklch(98.5% 0.004 90);
  --surface: oklch(96.5% 0.005 90);
  --border: oklch(89% 0.006 90);
  --ink: oklch(22% 0.01 90);
  --ink-muted: oklch(48% 0.01 90);
  --accent: oklch(62% 0.16 45);
  --accent-ink: oklch(98% 0.01 45);
  --accent-wash: oklch(94% 0.03 45);
  --danger: oklch(52% 0.17 25);

  --font-ui: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Login ---------- */

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 550;
  letter-spacing: -0.01em;
}

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

.field-label {
  font-size: 13px;
  color: var(--ink-muted);
}

.field input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.field input:focus-visible {
  border-color: var(--accent);
}

.login-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
}

.login-submit {
  margin-top: 4px;
}

/* ---------- Buttons ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out-quart), border-color 160ms var(--ease-out-quart), color 160ms var(--ease-out-quart);
}

.btn:hover { background: var(--surface); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn-primary:hover { background: oklch(30% 0.01 90); }

.btn-start {
  min-width: 96px;
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn-start:hover { background: oklch(30% 0.01 90); }

.btn-start.running {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-start.running:hover { background: oklch(57% 0.16 45); }

.link-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px;
}
.link-btn:hover { color: var(--ink); }

/* ---------- App shell ---------- */

.app-view {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar-title {
  font-size: 15px;
  font-weight: 550;
  color: var(--ink-muted);
}

/* ---------- Timer bar ---------- */

.timerbar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: sticky;
  top: 12px;
  z-index: 5;
}

.description-input {
  border: none;
  background: none;
  padding: 8px 2px;
  min-width: 0;
}

.combobox { position: relative; width: 160px; }

.project-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}

.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px oklch(22% 0.01 90 / 0.12);
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
}

.combobox-option {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.combobox-option:hover,
.combobox-option.active {
  background: var(--surface);
}

.combobox-option.create {
  color: var(--ink-muted);
}

.project-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: oklch(58% 0.09 var(--hue, 45));
}

.timer-display {
  font-family: var(--font-mono);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  min-width: 5.5ch;
  text-align: right;
  color: var(--ink-muted);
}

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

/* ---------- Entries ---------- */

.entries { margin-top: 32px; }

.day-group { margin-bottom: 28px; }

.day-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.day-header-label {
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-muted);
  text-transform: capitalize;
}

.day-header-total {
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
}

.entry-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.entry-row:hover { background: var(--surface); }
.entry-row.running { background: var(--accent-wash); }

.entry-description {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-description:empty::before {
  content: "(ohne Beschreibung)";
  color: var(--ink-muted);
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}

.entry-project {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-muted);
}

.entry-time {
  font-size: 13px;
  color: var(--ink-muted);
}

.entry-duration {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  text-align: right;
  min-width: 6ch;
}

.empty-state {
  padding: 32px 4px;
  color: var(--ink-muted);
  font-size: 14px;
  text-align: center;
}

/* ---------- Inline edit ---------- */

.edit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.edit-row input[type="text"] {
  flex: 1 1 160px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--paper);
}

.edit-row input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--paper);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn-delete {
  color: var(--danger);
  border-color: var(--border);
}
.btn-delete:hover { background: oklch(93% 0.04 25); }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .app-view { padding: 16px 14px 48px; }

  .timerbar {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "description description"
      "project timer"
      "button button";
    top: 8px;
  }
  .description-input { grid-area: description; padding: 6px 2px; }
  .combobox { grid-area: project; width: auto; }
  .timer-display { grid-area: timer; }
  .timer-btn, #timer-btn { grid-area: button; }

  .entry-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "description duration"
      "meta meta";
    row-gap: 4px;
  }
  .entry-description { grid-area: description; }
  .entry-duration { grid-area: duration; }
  .entry-meta { grid-area: meta; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
