:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1c2030;
  --muted: #646b80;
  --border: #dfe2ea;
  --accent: #4f7cff;
  --accent-text: #ffffff;
  --danger: #d6455d;
  --ok: #1f9d63;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 2px 8px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141b;
    --surface: #1b1e28;
    --surface-2: #252937;
    --text: #e6e8ef;
    --muted: #9198ad;
    --border: #2f3445;
    --accent: #6d92ff;
    --danger: #ef6b81;
    --ok: #3cc78a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
[hidden] { display: none !important; }

button, input, select {
  font: inherit;
  color: inherit;
}
input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type=color] { padding: 2px; height: 36px; width: 56px; }
button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { filter: brightness(.96); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label small, .hint { color: var(--muted); font-weight: 400; font-size: 13px; margin: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.error { color: var(--danger); min-height: 1em; margin: 0; }
.ok { color: var(--ok); margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.narrow { max-width: 480px; display: flex; flex-direction: column; gap: 14px; }
hr { border: 0; border-top: 1px solid var(--border); width: 100%; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 12px; border-radius: 7px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.tabs a.active { background: var(--surface-2); color: var(--text); }
.timer { margin-left: auto; display: flex; }
.timer-idle, .timer-running { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer-idle select { max-width: 240px; }
.timer-idle input { width: 160px; }
.timer-running strong { font-variant-numeric: tabular-nums; font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none; } }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0; flex: 1; min-width: 160px; }
.toolbar .hint { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--surface); }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.nav-buttons { display: inline-flex; gap: 4px; }
.switch { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }

/* Reports */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.chart svg { display: block; width: 100%; height: 180px; }
.chart .bar { fill: var(--accent); }
.chart .bar:hover { opacity: .8; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--border); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; }
td.note { white-space: normal; max-width: 320px; color: var(--muted); }
tfoot td { font-weight: 650; border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.archived td { opacity: .5; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: baseline; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.empty { color: var(--muted); padding: 12px 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: min(480px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog .row { display: flex; gap: 10px; flex-wrap: wrap; }
dialog .row label { flex: 1; min-width: 110px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.swatches { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; }
.swatch-opt { position: relative; display: block; cursor: pointer; }
.swatch-opt input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.swatch-opt span { display: block; aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
.swatch-opt input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatch-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }
@media (max-width: 480px) { .swatches { grid-template-columns: repeat(6, 1fr); } }
.inline-new {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.inline-new legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

/* FullCalendar theming */
#calendar {
  --fc-border-color: var(--border);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-today-bg-color: color-mix(in srgb, var(--accent) 7%, transparent);
  --fc-now-indicator-color: var(--danger);
  --fc-button-bg-color: var(--surface-2);
  --fc-button-border-color: var(--border);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--border);
  --fc-button-hover-border-color: var(--border);
  --fc-button-active-bg-color: var(--accent);
  --fc-button-active-border-color: var(--accent);
  --fc-highlight-color: color-mix(in srgb, var(--accent) 22%, transparent);
}
.fc .fc-toolbar-title { font-size: 18px; }
.fc .fc-button { font-size: 13px; text-transform: none; box-shadow: none !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: #fff; }
.fc-event { cursor: pointer; }
.fc-event.running { background-image: repeating-linear-gradient(45deg, rgb(255 255 255 / .18) 0 6px, transparent 6px 12px); }
.fc-event.invoiced { opacity: .7; }
.fc-event.nonbillable { border-style: dashed !important; }

.timer { order: 1; }
#logout { order: 2; }
.fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }

@media (max-width: 720px) {
  .topbar { position: static; gap: 8px; padding: 8px 12px; }
  .tabs { order: 0; flex: 1; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs a { padding: 6px 9px; white-space: nowrap; flex: none; }
  #logout { order: 1; padding: 6px 9px; }
  .timer { order: 2; margin-left: 0; width: 100%; }
  .timer-idle, .timer-running { width: 100%; flex-wrap: nowrap; }
  .timer-idle select { flex: 1.4; max-width: none; }
  .timer-idle input { flex: 1; width: auto; }
  #timer-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding: 12px; }
  .toolbar .hint { display: none; }
  .fc .fc-toolbar-title { font-size: 15px; }
}
