:root {
  --bg: #f4f6f9;
  --bg-soft: #eef1f5;
  --card: #ffffff;
  --text: #151a22;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --success: #12855c;
  --danger: #d13b3b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 30px -18px rgba(16, 24, 40, 0.35);
  --radius: 16px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --bg-soft: #12161d;
    --card: #161b23;
    --text: #e9edf3;
    --muted: #98a2b3;
    --line: #252c37;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.14);
    --success: #3ddc97;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 20px 40px -28px rgba(0, 0, 0, 0.9);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ------------------------------- Topbar ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 16px;
}

.brand .mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), #7c3aed);
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 800;
}

.spacer { flex: 1; }

.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

/* -------------------------------- Layout ------------------------------ */

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px; display: grid; gap: 18px; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1.15fr 0.85fr; }
.grid.top { grid-template-columns: 1.4fr 1fr; align-items: start; }

@media (max-width: 880px) {
  .grid.two, .grid.top { grid-template-columns: 1fr; }
  .wrap { padding: 14px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h2 .count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  letter-spacing: 0;
}

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

.statusline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  min-height: 20px;
}

.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent);
  animation: pulse 2s infinite;
}

.pulse.idle { background: var(--muted); animation: none; box-shadow: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 55%, transparent); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.clock {
  font-family: var(--mono);
  font-size: clamp(40px, 8vw, 62px);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  margin: 2px 0 4px;
}

.clock.idle { color: var(--muted); opacity: 0.55; }

.runningmeta { color: var(--muted); font-size: 13px; margin-bottom: 16px; min-height: 20px; }
.runningmeta b { color: var(--text); font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  background: var(--bg-soft);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* -------------------------------- Forms ------------------------------- */

label.field { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }

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

input[type="text"], input[type="number"], input[type="password"], input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row { display: flex; gap: 10px; }
.row > * { min-width: 0; }
.grow { flex: 1; }

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  background: var(--bg-soft);
  color: var(--text);
  transition: transform .06s, background .15s, border-color .15s, opacity .15s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary { background: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
button.ghost { background: transparent; border-color: var(--line); }
button.small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
button.big { padding: 13px 22px; font-size: 15px; border-radius: 12px; }
button.icon { padding: 6px 9px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

.quicktasks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.quicktasks button { font-weight: 500; }

/* -------------------------------- Stats ------------------------------- */

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }

.stat {
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 650; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); }

/* ------------------------------- Tables ------------------------------- */

.segmented { display: inline-flex; background: var(--bg-soft); padding: 3px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.segmented button { background: transparent; padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.summary { display: grid; gap: 14px; }

.project-block { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.project-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  background: var(--bg-soft);
}
.project-head .name { font-weight: 650; }
.project-head > div { min-width: 0; }
.project-head .name, .project-head .rate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-head .rate { font-size: 12px; color: var(--muted); }
.project-head .total { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.project-head .total .h { font-weight: 650; }
.project-head .total .money { font-size: 12px; color: var(--muted); }

.taskrow {
  display: grid;
  grid-template-columns: 1fr 150px 110px;
  gap: 12px;
  align-items: center;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.taskrow .tname { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.taskrow .tname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.taskrow .num { text-align: right; font-variant-numeric: tabular-nums; }
.taskrow .num small { display: block; color: var(--muted); font-size: 11.5px; }

.bar { height: 6px; border-radius: 99px; background: var(--bg-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }

.entries { display: grid; gap: 8px; }
.entry {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 13.5px;
}
.entry .bar-dot { width: 10px; height: 10px; border-radius: 50%; }
.entry .task { font-weight: 600; }
.entry .meta { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.entry .dur { font-variant-numeric: tabular-nums; font-weight: 600; }
.entry.running { border-color: color-mix(in srgb, var(--success) 40%, var(--line)); background: color-mix(in srgb, var(--success) 6%, transparent); }
.entry .row-actions { display: flex; gap: 6px; }

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

/* ------------------------------ Projekte ------------------------------ */

.list { display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 12.5px; }
.item .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.item.archived { opacity: .55; }

.addform { display: grid; grid-template-columns: 1fr 110px 44px auto; gap: 8px; margin-top: 12px; }
.addform input[type="color"] { padding: 2px; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-soft); }

@media (max-width: 560px) {
  .addform { grid-template-columns: 1fr 1fr; }
  .addform input[type="color"] { height: 42px; }
  .taskrow { grid-template-columns: 1fr 95px 80px; gap: 8px; }
  .entry { grid-template-columns: 12px 1fr auto; }
  .entry .row-actions { grid-column: 1 / -1; }
}

/* -------------------------------- Dialog ------------------------------ */

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  padding: 22px;
  width: min(460px, 92vw);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(8, 12, 20, .55); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 4px; font-size: 17px; }
dialog .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
dialog .field { margin-bottom: 12px; }

/* -------------------------------- Toast ------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 30px);
  background: var(--text);
  color: var(--card);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

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

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(700px 500px at 110% 110%, color-mix(in srgb, #7c3aed 18%, transparent), transparent 70%),
    var(--bg);
}
.login-card { width: min(380px, 100%); padding: 28px; }
.login-card .brand { margin-bottom: 20px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-card p.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }
