:root {
    --bg: #f4f6fa; --card: #fff; --ink: #1d2433; --muted: #6b7486; --line: #e3e7ef;
    --accent: #3a6df0; --accent-ink: #fff; --danger: #d64545; --ok: #1f9d63; --side: #172033;
    --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root { --bg: #0f141d; --card: #171e2b; --ink: #e6e9ef; --muted: #8f99ab; --line: #263044; --side: #0b1018; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; display: flex; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* Barre latérale */
.sidebar { width: 220px; flex-shrink: 0; background: var(--side); color: #c9d1e0; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 20px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar a { color: #c9d1e0; padding: 8px 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; }
.sidebar a:hover { background: rgba(255,255,255,.06); }
.sidebar a.active { background: rgba(58,109,240,.22); color: #fff; }
.ico { width: 18px; text-align: center; }
.me { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.me .link { color: #8f99ab; padding: 4px 10px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; }

main { flex: 1; padding: 24px 28px 60px; max-width: 1200px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.stats { display: flex; gap: 24px; }
.stats div { display: flex; flex-direction: column; align-items: flex-end; }
.stats strong { font-size: 17px; font-variant-numeric: tabular-nums; }

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

/* Formulaires */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
input[type=color] { padding: 2px; height: 36px; width: 56px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
textarea.code { width: 100%; font-family: ui-monospace, monospace; font-size: 12px; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 160px; }
.form-inline .row > .btn { margin-bottom: 10px; }
.form-inline .row > label.chk { margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + * { margin-top: 16px; }
form.inline { display: inline; }

.btn { font: inherit; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; justify-content: center; margin-top: 8px; }
.btn:disabled { opacity: .6; cursor: wait; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 2px 4px; }
.link.danger { color: var(--danger); }
.link:hover { text-decoration: underline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.flash.err { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); padding: 3px; border-radius: 9px; }
.tabs a { padding: 5px 12px; border-radius: 7px; color: var(--muted); }
.tabs a.active { background: var(--accent); color: #fff; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 6px 8px; font-size: 13px; }
.table td.r, .table th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr.archived td { opacity: .55; }
.scroll { overflow-x: auto; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; flex-shrink: 0; }
.tag { display: inline-block; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-radius: 5px; padding: 1px 7px; font-size: 12px; margin: 1px 2px; }

/* Barre du chrono */
.timerbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; position: sticky; top: 10px; z-index: 5; }
.timerbar.running { border-color: var(--accent); }
.timerbar #t-desc { flex: 1; border: 0; font-size: 15px; padding: 10px; background: transparent; }
.timerbar #t-desc:focus { outline: none; }
.picker { position: relative; }
.pick-btn { font: inherit; background: none; border: 1px dashed transparent; color: var(--accent); padding: 7px 10px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 4px; white-space: nowrap; max-width: 280px; overflow: hidden; }
.pick-btn:hover { border-color: var(--line); }
.pick-btn.icon { color: var(--muted); font-size: 15px; }
.pick-btn.set { color: var(--ink); }
#t-bill { font-weight: 700; }
#t-bill.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.clock { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }
.mode-timer, .mode-manual { display: flex; align-items: center; gap: 8px; border-left: 1px solid var(--line); padding-left: 12px; }
.mode-timer[hidden], .mode-manual[hidden] { display: none; }
.mode-manual input { padding: 6px 8px; }
#t-start { min-width: 100px; justify-content: center; }
.mode-switch { display: flex; flex-direction: column; }
.mode-switch .link { color: var(--muted); font-size: 13px; padding: 0 4px; }
.mode-switch .link.active { color: var(--accent); }

.popover { position: absolute; top: calc(100% + 6px); left: 0; width: 280px; z-index: 20; padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.popover input[type=search] { width: 100%; margin-bottom: 6px; }
.pop-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; }
.pop-list button { font: inherit; text-align: left; background: none; border: 0; color: var(--ink); padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.pop-list button:hover, .pop-list button.sel { background: var(--bg); }
.pop-list button.create { color: var(--accent); }
.pop-list label.chk { padding: 4px 8px; margin: 0; }
.pop-group { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 8px 8px 2px; letter-spacing: .04em; }

/* Entrées par jour */
.day { padding: 0; overflow: hidden; }
.day header { display: flex; justify-content: space-between; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 60%, var(--card)); border-bottom: 1px solid var(--line); font-weight: 600; }
.entry { display: grid; grid-template-columns: minmax(140px, 2fr) minmax(100px, 1.3fr) minmax(0, 1fr) 24px 110px 76px 84px; gap: 10px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry:hover { background: color-mix(in srgb, var(--bg) 50%, var(--card)); }
.entry .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .proj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .bill { color: var(--line); font-weight: 700; text-align: center; }
.entry .bill.on { color: var(--accent); }
.entry .span { font-variant-numeric: tabular-nums; text-align: right; }
.entry .dur { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.entry .actions { text-align: right; opacity: .35; }
.entry:hover .actions { opacity: 1; }
.empty { text-align: center; padding: 40px; }

dialog.card { border: 1px solid var(--line); width: min(560px, 94vw); padding: 20px; color: var(--ink); }
dialog::backdrop { background: rgba(10,15,25,.45); }
dialog label { margin-bottom: 12px; }
dialog .row label { flex: 1; }
.tag-checks { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 12px; margin: 0 0 12px; }
.tag-checks legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.tag-checks label { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Rapports */
.filters { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; }
.filters .btn { margin-bottom: 10px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: 2px; }
.kpi strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); }
.chart { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); gap: 4px; height: 200px; align-items: end; }
.chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .bar { width: 100%; max-width: 46px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; }
.chart .val { font-size: 10px; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.chart .lbl { font-size: 10px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; max-width: 100%; }
.hbar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; display: inline-block; width: calc(100% - 44px); vertical-align: middle; margin-right: 6px; }
.hbar div { height: 100%; background: var(--accent); border-radius: 4px; }

/* Connexion / installation */
body.auth { align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-card.wide { max-width: 680px; }
.auth-card h1 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.auth-card h2 { margin-top: 20px; }
.auth-card label:not(.chk) input, .auth-card label select { width: 100%; }
.auth-card label.chk { white-space: nowrap; }

/* Responsive */
@media (max-width: 900px) {
    body { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; }
    .brand { padding: 0 12px 0 0; }
    .sidebar nav { flex-direction: row; }
    .sidebar nav a { white-space: nowrap; }
    .me { border: 0; padding: 0; display: flex; align-items: center; }
    main { padding: 16px; }
    .timerbar { flex-wrap: wrap; position: static; }
    .timerbar #t-desc { flex-basis: 100%; }
    .entry { grid-template-columns: 1fr auto; grid-auto-rows: auto; }
    .entry .tags, .entry .bill, .entry .span { display: none; }
    .entry .actions { opacity: 1; grid-column: 1 / -1; text-align: left; }
    .grid2, .kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) { .grid2, .kpis { grid-template-columns: 1fr; } .stats { gap: 14px; } }

@media print {
    .sidebar, .filters, .page-head .btn, .page-head button { display: none !important; }
    body { background: #fff; display: block; }
    main { padding: 0; max-width: none; }
    .card { box-shadow: none; break-inside: avoid; }
}

/* Partage / vue publique */
.share-card { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.share-url { margin: 12px 0; align-items: center; }
.share-url input { font-family: ui-monospace, monospace; font-size: 12px; }
.share-opts { gap: 4px 20px; align-items: center; }
.share-opts label.chk { margin-bottom: 0; }
body.public { display: block; }
.public-main { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; }
.public-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.public-head p { margin: 0 0 4px; }
.public-head h1 { font-size: 26px; display: flex; align-items: center; gap: 10px; }
.public-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.dot.big { width: 14px; height: 14px; }
.live { color: var(--ok); font-weight: 600; font-size: 13px; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.kpi-dates { font-size: 18px !important; }
.section-title { margin: 22px 0 10px; }
.pentry { display: grid; grid-template-columns: 1fr auto 110px 76px auto; gap: 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.pentry:last-child { border-bottom: 0; }
.pentry .span, .pentry .dur, .pentry .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pentry .dur { font-weight: 600; }
.public-foot { text-align: center; margin-top: 30px; }
@media (max-width: 640px) {
    .pentry { grid-template-columns: 1fr auto; }
    .pentry .span, .pentry .who { display: none; }
    .public-meta { align-items: flex-start; }
}
