:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --primary: #5b8cff;
  --primary-d: #4a76e0;
  --green: #34d399;
  --red: #f87171;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 12px var(--primary); }
.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--surface-2); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--red); border-color: transparent; background: transparent; }
.btn.danger:hover { background: rgba(248,113,113,.12); }
.btn.big { padding: 12px 28px; font-size: 16px; }
.btn.running { background: var(--red); border-color: var(--red); color: #fff; }

/* ---------- Layout ---------- */
.view { display: none; max-width: 1100px; margin: 24px auto; padding: 0 24px; }
.view.active { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow);
}

/* ---------- Entry form ---------- */
.entry-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 120px; }
.field.grow { flex: 1 1 160px; }
.field.grow-2 { flex: 2 1 240px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input {
  font: inherit; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 8px; width: 100%;
}
.field input:focus { outline: none; border-color: var(--primary); }
.rate-field, .billable-field { min-width: 80px; max-width: 90px; }
.rate-field input { text-align: right; }
.toggle {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 10px 0; cursor: pointer; font-weight: 700; font-size: 15px;
}
.toggle.on { background: rgba(52,211,153,.15); border-color: var(--green); color: var(--green); }

.timer-display {
  font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 700;
  min-width: 130px; text-align: center; letter-spacing: 1px;
}
.notes-row { display: flex; gap: 12px; margin-top: 14px; }
.notes-row input {
  flex: 1; font: inherit; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 8px;
}
.notes-row input:focus { outline: none; border-color: var(--primary); }
.muted { color: var(--muted); font-weight: 400; }

/* ---------- Entries ---------- */
.entries-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.entries-head h2 { font-size: 16px; }
.summary { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.entries-list { display: flex; flex-direction: column; gap: 8px; }

.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.group-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface-2); cursor: pointer;
}
.group-head .caret { color: var(--muted); transition: .15s; font-size: 12px; }
.group.open .group-head .caret { transform: rotate(90deg); }
.g-title { font-weight: 600; }
.g-title small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.g-meta { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.g-total { font-variant-numeric: tabular-nums; font-weight: 700; }
.g-earn { color: var(--green); font-size: 13px; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: var(--border); color: var(--muted); }

.group-items { display: none; flex-direction: column; }
.group.open .group-items { display: flex; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-top: 1px solid var(--border); font-size: 14px;
}
.row .r-when { color: var(--muted); font-size: 13px; flex: 1; }
.row .r-notes { color: var(--muted); font-size: 13px; flex: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-dur { font-variant-numeric: tabular-nums; font-weight: 600; }
.row .r-edit { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; }
.row.live { background: rgba(91,140,255,.08); }
.row.live .r-dur { color: var(--primary); }

.empty { color: var(--muted); text-align: center; padding: 40px; }

/* ---------- Analytics ---------- */
.range-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  padding: 7px 14px; border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-val { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.analytics-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.analytics-cols h3 { font-size: 15px; margin-bottom: 14px; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-label { display: flex; justify-content: space-between; font-size: 13px; }
.bar-label .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #7aa2ff); border-radius: 6px; }
.bars .empty { padding: 20px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6);
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; width: 100%; max-width: 520px; box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 18px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.modal-grid label.full { grid-column: 1 / -1; }
.modal-grid label.inline { flex-direction: row; align-items: center; gap: 8px; }
.modal-grid input[type=text], .modal-grid input:not([type=checkbox]) {
  font: inherit; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 11px; border-radius: 8px;
}
.modal-grid input:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 22px; }
.modal-actions .spacer { flex: 1; }

@media (max-width: 720px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .analytics-cols { grid-template-columns: 1fr; }
  .timer-display { width: 100%; }
  .topbar { flex-wrap: wrap; gap: 12px; }
}
