:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --ink: #1c2430;
    --muted: #6b7684;
    --line: #e2e6ea;
    --accent: #2f6df6;
    --accent-ink: #ffffff;
    --danger: #d1435b;
    --ok: #1f9d63;
    --radius: 8px;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar / nav */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0 1.25rem;
    height: 52px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 600; color: var(--ink); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 1rem; flex: 1; }
.mainnav a { color: var(--muted); padding: 2px 0; border-bottom: 2px solid transparent; }
.mainnav a:hover { color: var(--ink); text-decoration: none; }
.mainnav a.active { color: var(--ink); border-bottom-color: var(--accent); }
.logout { margin: 0; }
.linkbtn {
    background: none; border: 0; color: var(--muted); cursor: pointer;
    font: inherit; padding: 0;
}
.linkbtn:hover { color: var(--ink); }

/* Content */
.content { max-width: 960px; margin: 1.5rem auto; padding: 0 1.25rem; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin: 1rem 0;
}

/* Tables */
.datatable { width: 100%; border-collapse: collapse; }
.datatable th, .datatable td {
    text-align: left; padding: .5rem .25rem; border-bottom: 1px solid var(--line);
}
.datatable td { text-align: right; font-variant-numeric: tabular-nums; }
.datatable tr:last-child th, .datatable tr:last-child td { border-bottom: 0; }

/* Forms */
label { display: block; font-weight: 500; margin: .75rem 0 .25rem; }
input, select, textarea {
    width: 100%; padding: .55rem .65rem; font: inherit;
    border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent);
}
button, .btn {
    display: inline-block; padding: .55rem 1rem; font: inherit; font-weight: 500;
    color: var(--accent-ink); background: var(--accent); border: 0;
    border-radius: 6px; cursor: pointer;
}
button:hover, .btn:hover { filter: brightness(1.05); text-decoration: none; }

/* Flash */
.flash {
    padding: .6rem .85rem; border-radius: 6px; margin: 0 0 1rem;
    border: 1px solid transparent;
}
.flash-info    { background: #eef4ff; border-color: #cfe0ff; color: #204a9a; }
.flash-error   { background: #fdeef1; border-color: #f4c6cf; color: #8f2036; }
.flash-success { background: #eafaf1; border-color: #c3ecd4; color: #14663f; }

/* "Not today" warning banner */
.day-warning {
    display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
    background: #fff4e0; border: 1px solid #f0c987; color: #8a5200;
    border-left: 4px solid #e8940c;
    padding: .7rem 1rem; border-radius: 6px; margin: 0 0 1rem;
}
.day-warning-icon { font-size: 1.15rem; line-height: 1; }
.day-warning-text { flex: 1 1 auto; }
.day-warning-btn {
    background: #e8940c; color: #fff; border-radius: 6px;
    padding: .35rem .8rem; font-weight: 600; white-space: nowrap;
}
.day-warning-btn:hover { filter: brightness(1.05); text-decoration: none; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 2rem; width: 320px;
    box-shadow: 0 8px 30px rgba(20, 30, 45, .06);
}
.login-card h1 { font-size: 1.25rem; text-align: center; margin-bottom: 1rem; }
.login-card button { width: 100%; margin-top: 1rem; }

/* One-line pointer to a timer running on a day other than the one shown —
   on its own day the running row (highlight + clock + Stop) is the timer UI. */
.running-elsewhere { margin: 0 0 1rem; color: var(--muted); font-size: .9rem; }
.running-elsewhere strong { color: inherit; }
/* Row action buttons share one geometry so they line up; colour carries the
   meaning. Solid = the primary timer action, outlined = secondary. */
.btn-stop-sm, .btn-start-sm, .btn-edit-sm, .btn-delete-sm {
    display: inline-block; padding: .3rem .7rem; font-size: .85rem;
    font-weight: 500; border-radius: 6px; border: 1px solid transparent;
    line-height: 1.4; vertical-align: middle; cursor: pointer;
}
.btn-stop-sm { background: #ff5f56; color: #fff; }
.btn-start, .btn-start-sm { background: var(--ok); color: #fff; }
.btn-edit-sm { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-edit-sm:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-delete-sm { background: #fff; color: var(--danger); border-color: #f0c4cd; }
.btn-delete-sm:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.running-row td { background: #f0fff6; }
.running-clock { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ok); }

/* Day view */
.dayhead { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.daytotal { text-align: right; }
.daytotal .muted { display: block; font-size: .8rem; }
.daytotal strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.weekstrip { display: flex; align-items: stretch; gap: .5rem; margin: 1rem 0; }
.wk-nav {
    display: grid; place-items: center; width: 40px; flex: 0 0 40px;
    background: var(--card); border: 1px solid var(--line); border-radius: 6px;
    color: var(--muted); font-size: 1.3rem; text-decoration: none;
}
.wk-nav:hover { color: var(--ink); text-decoration: none; }
.wk-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: .5rem; flex: 1; }
.wk-day {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: .5rem 0; background: var(--card); border: 1px solid var(--line);
    border-radius: 6px; color: var(--ink); text-decoration: none;
}
.wk-day:hover { text-decoration: none; border-color: #cbd3db; }
.wk-dow { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.wk-dom { font-size: 1.1rem; font-weight: 600; }
.wk-hrs { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.wk-day.today { border-color: var(--accent); }
.wk-day.today .wk-dom { color: var(--accent); }
.wk-day.sel { background: var(--accent); border-color: var(--accent); }
.wk-day.sel .wk-dow, .wk-day.sel .wk-dom, .wk-day.sel .wk-hrs { color: #fff; }

/* Entries table */
.entries { width: 100%; border-collapse: collapse; }
.entries th, .entries td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.entries thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.entries .num, .entries th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entries .notes { color: var(--ink); max-width: 340px; }
.entries tfoot td { border-bottom: 0; padding-top: .75rem; }
.entries .num-label { text-align: right; color: var(--muted); }

/* Timesheet table only — the Log and Expenses pages share .entries and are
   deliberately left at their denser sizing. */
/* middle, so the hours figure sits on the same centre line as the row's
   action buttons, which are taller than bare text (was off by ~4px). */
.entries.daysheet th, .entries.daysheet td { vertical-align: middle; }
/* Hours is the number being scanned for — give it more weight than the rest. */
.entries.daysheet tbody td.num { font-size: 1.15rem; font-weight: 600; }
.entries.daysheet tbody td.num .pill { font-size: .72rem; font-weight: 400; }
.entries.daysheet tfoot td.num { font-size: 1.3rem; font-weight: 700; }
.rowactions { white-space: nowrap; text-align: right; }
.rowactions form { display: inline; }
/* Even gaps whether the control is a bare link or wrapped in a POST form. */
.rowactions form, .rowactions .btn-edit-sm { margin-left: .35rem; }

/* Entry form (add + inline edit) */
.entry-form .ef-grid {
    display: grid; gap: .5rem .75rem; align-items: end;
    grid-template-columns: minmax(180px, 2fr) minmax(120px, 1fr) 90px minmax(160px, 2fr) auto;
}
.entry-form .ef-billable { align-self: center; }
.entry-form label { margin: 0 0 .2rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.entry-form .small { margin-top: .6rem; }
.small { font-size: .82rem; }
tr.editing td { background: #f0f5ff; }

.chk { display: inline-flex; align-items: center; gap: .35rem; font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .95rem; color: var(--ink); }
.chk input { width: auto; }

.btn-ghost {
    display: inline-block; padding: .55rem .9rem; border-radius: 6px;
    border: 1px solid var(--line); color: var(--muted); background: #fff;
}
.btn-ghost:hover { color: var(--ink); text-decoration: none; }
.linkbtn.danger { color: var(--danger); }

/* Pills */
.pill {
    display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 20px;
    background: #e7f0ff; color: #23539e; white-space: nowrap;
}
.pill-muted { background: #eef0f2; color: var(--muted); }

/* Manage */
.manage-table td.cell-name { font-weight: 500; text-align: left; }
.manage-table td { text-align: left; }
.manage-table .num { text-align: right; }
.rowform { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.card .rowform:first-of-type { margin-top: 0; }
.listtools { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 .25rem; }
.listtools input[type=search] { width: auto; flex: 0 1 280px; }
details.addbox > summary { cursor: pointer; font-weight: 600; }

/* Day view: + button and new-entry modal (Harvest-style) */
.btn-plus {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: 0 0 auto;
    background: var(--ok); color: #fff; border-radius: var(--radius);
    font-size: 24px; line-height: 1; text-decoration: none;
}
.btn-plus:hover { text-decoration: none; filter: brightness(1.08); }
.dayhead .btn-plus { align-self: center; }
.dayhead h1 { margin-right: auto; } /* keep + and title left, total right */
dialog.modal {
    width: min(560px, calc(100vw - 2rem)); padding: 0; border: none;
    border-radius: 10px; background: var(--card); color: var(--ink);
    box-shadow: 0 18px 50px rgba(28, 36, 48, .3);
}
dialog.modal::backdrop { background: rgba(28, 36, 48, .45); }
/* No-JS fallback: [open] without showModal() renders in-flow, centered. */
dialog.modal[open] { margin: 1.5rem auto; }
.modal-head {
    padding: .8rem 1.25rem; text-align: center; font-weight: 600;
    background: var(--bg); border-bottom: 1px solid var(--line);
    border-radius: 10px 10px 0 0;
}
.modal-body { padding: 1rem 1.25rem 1.1rem; }
.modal-label { display: block; font-weight: 600; margin: .2rem 0 .5rem; }
.modal-field { margin-bottom: .6rem; }
.modal-row { display: flex; gap: .6rem; margin-bottom: .9rem; }
.modal-row input[name=notes] { flex: 1; }
.modal-hours { width: 110px; flex: 0 0 auto; text-align: right; font-size: 1.05rem; }
.modal-billable { display: inline-flex; margin-bottom: .9rem; }
.modal-actions { display: flex; gap: .6rem; align-items: center; }
.modal-actions .btn-start { background: var(--ok); }

/* Projects page: Harvest-style client grouping + per-row Actions menu */
.projects-table .group-head td {
    background: var(--bg); padding: .8rem .5rem .45rem;
    font-weight: 500; border-bottom: 1px solid var(--line);
}
.projects-table .group-head a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.projects-table .group-head a:hover { color: var(--accent); }
.projects-table td.cell-name .pill { margin-left: .4rem; }
.actions-menu { position: relative; display: inline-block; }
.actions-menu > summary {
    list-style: none; cursor: pointer; user-select: none;
    border: 1px solid var(--line); border-radius: var(--radius);
    padding: .25rem .7rem; background: var(--card); white-space: nowrap;
}
.actions-menu > summary::-webkit-details-marker { display: none; }
.actions-menu > summary::after { content: " ▾"; color: var(--muted); }
.actions-menu[open] > summary { border-color: var(--accent); }
.actions-pop {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
    min-width: 120px; padding: .5rem .8rem; text-align: left;
    display: flex; flex-direction: column; gap: .35rem;
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: 0 6px 18px rgba(28, 36, 48, .12);
}
.actions-pop form { margin: 0; }
details.addbox[open] > summary { margin-bottom: .25rem; }
details.addbox .projform { border-top: 0; margin-top: .25rem; padding-top: .5rem; }
.rowform input[type=text] { width: auto; flex: 1; min-width: 200px; }
.addform { border-top: 1px dashed var(--line); padding-top: 1rem; }
.projform { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: 1rem; }
.projform h3 { margin: 0 0 .75rem; font-size: 1rem; }
.pf-grid { display: grid; gap: .5rem .9rem; grid-template-columns: 1fr 1fr 1fr 1fr; }
.pf-grid > div { min-width: 0; }
.pf-flags { display: flex; align-items: center; gap: 1rem; padding-top: 1.6rem; }
.pf-notes { grid-column: 1 / -1; }
.pf-actions { margin-top: .9rem; display: flex; gap: .6rem; }

/* Reports */
.report-toolbar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.viewtoggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.viewtoggle a { padding: .45rem .9rem; color: var(--muted); background: #fff; }
.viewtoggle a:hover { text-decoration: none; color: var(--ink); }
.viewtoggle a.active { background: var(--accent); color: #fff; }
.cutoff-form { display: inline-flex; align-items: center; gap: .5rem; }
.cutoff-form label { margin: 0; font-weight: 500; }
.cutoff-form input[type=date] { width: auto; }
.report-toolbar > a { margin-left: auto; }

.client-block { padding-top: 1rem; }
.client-head { display: flex; align-items: baseline; justify-content: space-between; }
.client-head h2 { margin: 0; }
.client-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.report-table { width: 100%; border-collapse: collapse; margin: .75rem 0; }
.report-table th, .report-table td { padding: .5rem .5rem; border-bottom: 1px solid var(--line); text-align: left; }
.report-table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.report-table .num, .report-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table .chkcol { width: 28px; text-align: center; }
.report-table .chkcol input { width: auto; }
.report-table a.detail-link { text-decoration: underline dotted; text-underline-offset: 3px; }
.report-table a.detail-link:hover { text-decoration-style: solid; }

/* Uninvoiced/Invoiced report: one table per client, so an auto layout sizes
   each one to its own longest project name and the number columns land in a
   different place in every block. Fixing the column widths makes Hours (and
   every other figure) line up vertically down the whole page. Scoped to these
   two tables — the drill-down tables share .report-table but have their own
   column counts and are fine content-sized. */
.report-table.cols-uninvoiced, .report-table.cols-invoiced { table-layout: fixed; }
.report-table col.c-chk     { width: 28px; }
.report-table col.c-hours   { width: 9%; }
.report-table col.c-money   { width: 12%; }
.report-table col.c-batch   { width: 13%; }
.report-table col.c-actions { width: 9%; }
/* Long project names wrap rather than overflow now that widths are fixed. */
.report-table.cols-uninvoiced td, .report-table.cols-invoiced td { overflow-wrap: anywhere; }

@media (max-width: 720px) {
    /* Too narrow to hold seven fixed columns — let content size them again. */
    .report-table.cols-uninvoiced, .report-table.cols-invoiced { table-layout: auto; }
}
.detail-table .notes { color: var(--ink); }
.detail-table tfoot td { border-bottom: none; border-top: 2px solid var(--line); }
.client-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

.grand-total { display: flex; align-items: center; justify-content: space-between; font-size: 1.05rem; }
.grand-total .gt-nums { display: flex; align-items: baseline; gap: 1rem; }
.grand-total strong { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.pill-ok { background: #eafaf1; color: #14663f; }

/* Log filters */
.filters { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0; }
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem .9rem; }
.filter-grid label { margin: 0 0 .2rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.filter-q { grid-column: span 2; }
.filter-actions { display: flex; gap: .6rem; margin-top: .8rem; }
.logtable .nowrap { white-space: nowrap; }
.ef-grid-log { grid-template-columns: 130px minmax(160px,2fr) minmax(120px,1fr) 90px minmax(160px,2fr) auto; }

.pager { display: flex; align-items: center; gap: 1rem; justify-content: center; margin-top: 1rem; }

/* Searchable combobox (progressive enhancement over select.searchable) */
.combobox { position: relative; }
.combobox-native { display: none; }
.combobox-input { width: 100%; }
.combobox.has-clear .combobox-input { padding-right: 1.9rem; }
.combobox-clear {
    position: absolute; top: 0; right: 0; height: 100%; width: 1.9rem;
    background: none; border: 0; color: var(--muted); font-size: 1.2rem;
    line-height: 1; cursor: pointer; padding: 0; border-radius: 0 6px 6px 0;
}
.combobox-clear:hover { color: var(--danger); }
.combobox-list {
    position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px);
    margin: 0; padding: 4px; list-style: none;
    background: var(--card); border: 1px solid var(--line); border-radius: 6px;
    box-shadow: 0 8px 24px rgba(20, 30, 45, .12);
    max-height: 260px; overflow-y: auto;
}
.combobox-option {
    padding: .4rem .55rem; border-radius: 4px; cursor: pointer;
    display: flex; align-items: baseline; gap: .1rem; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.combobox-option .cb-label { font-weight: 500; }
.combobox-option .cb-group { color: var(--muted); font-size: .85em; }
.combobox-option.active { background: var(--accent); }
.combobox-option.active .cb-label,
.combobox-option.active .cb-group { color: #fff; }
.combobox-option[aria-selected="true"]:not(.active) { background: #eef4ff; }
.combobox-empty { padding: .4rem .55rem; color: var(--muted); }

/* Settings */
.settings-form { max-width: 380px; }
.export-list { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.export-list li { margin: 0; }

@media (max-width: 760px) {
    .entry-form .ef-grid, .ef-grid-log { grid-template-columns: 1fr 1fr; }
    .filter-grid { grid-template-columns: 1fr 1fr; }
    .filter-q { grid-column: span 2; }
    .report-toolbar > a { margin-left: 0; }
    .entry-form .ef-notes, .entry-form .ef-actions { grid-column: 1 / -1; }
    .pf-grid { grid-template-columns: 1fr 1fr; }
    .pf-flags { padding-top: 0; }
}

@media (max-width: 640px) {
    .topbar { gap: .75rem; padding: 0 .75rem; }
    .mainnav { gap: .6rem; font-size: .9rem; overflow-x: auto; }
    .content { margin: 1rem auto; }
    .wk-nav { width: 32px; flex-basis: 32px; }
    .wk-days { gap: .25rem; }
    .entry-form .ef-grid { grid-template-columns: 1fr; }
}
