:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f1efec;
  --text: #1f1d1a;
  --muted: #6b6762;
  --border: #dedad5;
  --accent: #e8590c;
  --accent-text: #ffffff;
  --accent-soft: #fdeee5;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --warn: #b35c00;
  --focus: #1c7ed6;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #201f1d;
    --surface-2: #2a2826;
    --text: #ece9e5;
    --muted: #a19c96;
    --border: #3a3734;
    --accent: #ff7a2e;
    --accent-text: #1a0d05;
    --accent-soft: #3a2416;
    --danger: #ff6b6b;
    --ok: #69db7c;
    --warn: #ffa94d;
    --focus: #4dabf7;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; font-weight: 600; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 600; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1:focus, h1:focus-visible { outline: none; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.25rem; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand svg { width: 22px; height: 22px; }
.brand svg circle { fill: var(--accent); }
.brand svg path { stroke: var(--accent-text); stroke-width: 1.6; fill: none; stroke-linecap: round; }
.mainnav { display: flex; align-items: center; gap: .25rem; flex: 1; }
.mainnav > a { color: var(--muted); padding: .45rem .75rem; border-radius: var(--radius); font-weight: 500; }
.mainnav > a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.mainnav > a.active { background: var(--accent-soft); color: var(--accent); }
.mainnav .user { margin-left: auto; display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; }
.mainnav .user form { margin: 0; }
.menu-toggle { display: none; }
.content { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.toolbar, .filters, .date-nav, .row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.filters { margin: .5rem 0 1rem; }
.date-nav { margin-bottom: 1rem; }
.row { margin: .5rem 0; align-items: flex-end; }
.row.buttons { align-items: center; margin-top: 1rem; }
.grow { flex: 1 1 220px; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 1rem; justify-content: space-between; flex-wrap: wrap; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.25rem; }
.span-2 { grid-column: span 2; }
.breadcrumb { color: var(--muted); margin: 0 0 .5rem; font-size: .9rem; }

/* Text */
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85rem; }
.hint { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.empty { padding: 1rem 0; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: .6rem .9rem; margin: .5rem 0; }
.error { color: var(--danger); margin: .5rem 0; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; font-weight: 500; }
.tag.warn { color: var(--warn); }
.status { font-size: .8rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.status-sent { color: var(--focus); }
.status-overdue { color: var(--danger); }
.status-paid { color: var(--ok); }
.status-credited { text-decoration: line-through; }

/* Forms */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; color: var(--muted); }
label.check, label.inline { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); }
input, select, textarea, button, .button {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: .45rem .65rem; min-height: 38px;
}
textarea { resize: vertical; }
input[type="checkbox"] { min-height: 0; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
input:disabled, select:disabled { opacity: .6; }
button, .button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; background: var(--surface); white-space: nowrap; }
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.danger { color: var(--danger); }
button.link, .link { background: none; border: none; padding: .2rem .35rem; min-height: 0; color: var(--accent); }
button.link.danger { color: var(--danger); }
.icon { width: 38px; padding: 0; font-size: 1.2rem; }
.button.small { min-height: 30px; padding: .2rem .6rem; font-size: .85rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
legend { padding: 0 .35rem; font-weight: 600; }
input.short { width: 6.5rem; text-align: right; }
input.wide { width: 100%; min-width: 14rem; }
.file-drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1rem; align-items: flex-start; color: var(--muted); cursor: pointer; }
.file-drop { position: relative; }
.file-drop:hover { border-color: var(--accent); }
.file-drop input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.weekdays { display: flex; gap: 1rem; flex-wrap: wrap; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.segmented.wrap { flex-wrap: wrap; }
.segmented > a, .segmented > button { border: none; border-radius: 0; padding: .4rem .8rem; color: var(--muted); min-height: 36px; display: inline-flex; align-items: center; background: none; }
.segmented > * + * { border-left: 1px solid var(--border); }
.segmented > .active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.segmented > a:hover { text-decoration: none; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* Tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
table.list th, table.list td, table.lines th, table.lines td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.list th, table.lines th { font-size: .8rem; color: var(--muted); font-weight: 600; }
table.card { padding: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { text-align: right; white-space: nowrap; }
tr.archived, section.archived { opacity: .55; }
.amount + .amount::before { content: " · "; color: var(--muted); }

/* Day view */
.week-strip { display: grid; grid-template-columns: repeat(8, 1fr); gap: .35rem; margin-bottom: 1rem; }
.week-strip a, .week-strip .week-total { display: flex; flex-direction: column; align-items: center; padding: .45rem .25rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.week-strip a:hover { text-decoration: none; border-color: var(--accent); }
.week-strip a.active { border-color: var(--accent); background: var(--accent-soft); }
.week-strip a.today .dayname { color: var(--accent); font-weight: 700; }
.week-strip .dayname { font-size: .78rem; color: var(--muted); text-transform: capitalize; }
.week-strip .date { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.week-strip .total { font-variant-numeric: tabular-nums; font-weight: 600; }
.week-strip .week-total { background: var(--surface-2); }
.new-entry { margin-bottom: 1rem; }
.entries:empty { display: none; }
.entries { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.entry { display: flex; align-items: center; gap: 1rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.entry:last-child { border-bottom: none; }
.entry .what { flex: 1; min-width: 0; }
.entry .task { color: var(--muted); }
.entry .notes { margin-top: .2rem; }
.entry .duration { font-size: 1.35rem; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5rem; text-align: right; }
.entry .actions { display: flex; gap: .35rem; }
.entry.running { background: var(--accent-soft); }
.entry.editing { display: block; }
.timer.stop { color: var(--danger); }
.day-total { text-align: right; font-size: 1.1rem; margin-top: .75rem; }
.entry-form { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.entry-form.inline { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.entry-form .duration-input input { width: 7rem; font-size: 1.15rem; text-align: right; }

/* Week view */
.week-grid { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.week-grid th, .week-grid td { border-bottom: 1px solid var(--border); padding: .4rem .35rem; text-align: center; }
.week-grid thead th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.week-grid thead a { color: inherit; }
.week-grid .row-head { text-align: left; min-width: 13rem; font-weight: normal; }
.week-grid .row-head .task { color: var(--muted); font-size: .88rem; }
.week-grid .today { background: var(--accent-soft); }
.week-grid .cell { display: flex; align-items: center; justify-content: center; gap: 0; }
.week-grid .cell input { width: 4.6rem; text-align: right; font-variant-numeric: tabular-nums; padding: .35rem .45rem; }
.week-grid .note { border: none; background: none; min-height: 0; padding: .1rem .2rem; color: var(--border); font-size: .85rem; }
.week-grid .note.has-note, .week-grid .note:hover { color: var(--accent); }
.week-grid .cell-readonly { display: inline-block; padding: .35rem .45rem; font-variant-numeric: tabular-nums; color: var(--text); border-bottom: 1px dashed var(--muted); }
.week-grid .total { font-weight: 600; font-variant-numeric: tabular-nums; }
.week-grid tfoot td, .week-grid tfoot th { border-bottom: none; background: var(--surface-2); }
.week-grid .grand { color: var(--accent); }
.add-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 .5rem; }
.note-editor { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; }

/* Invoices */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.25rem; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.totals { display: grid; grid-template-columns: 1fr max-content; gap: .3rem 1.25rem; margin: 1rem 0 1rem auto; max-width: 420px; }
.totals dt { color: var(--muted); text-align: right; }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.lines td { white-space: nowrap; }
.lines td:nth-child(2) { white-space: normal; min-width: 20rem; width: 40%; }
ul.plain { list-style: none; padding: 0; margin: 0 0 .75rem; }
ul.plain li { padding: .3rem 0; }
.attachments li { display: flex; gap: .5rem; align-items: center; }
.summary { font-size: 1.05rem; }
.logo-preview { max-height: 64px; max-width: 240px; display: block; margin-bottom: .75rem; background: #fff; padding: .25rem; border-radius: 4px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
details > summary { cursor: pointer; padding: .25rem 0; }

/* Reports */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin: 1rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; display: flex; flex-direction: column; gap: .15rem; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .8rem; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-bottom: 1.4rem; margin-bottom: .5rem; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; min-width: 8px; }
.bar .fill { display: block; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.bar .bar-label { position: absolute; bottom: -1.3rem; left: 50%; transform: translateX(-50%); font-size: .7rem; color: var(--muted); white-space: nowrap; }
.report-rows .share { width: 22%; white-space: nowrap; font-size: .85rem; color: var(--muted); }
.share-bar { display: inline-block; height: 8px; background: var(--accent); border-radius: 4px; vertical-align: middle; max-width: 70%; margin-right: .35rem; }

/* Account pages */
.account-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem 16px; }
.account-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.75rem; box-shadow: var(--shadow); }
.account-card .brand { margin-bottom: 1.25rem; }
.account-card form { margin-top: 1rem; }
.account-card button.primary { width: 100%; }
.links { display: flex; flex-direction: column; gap: .4rem; margin-top: 1.25rem; font-size: .92rem; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: .75rem 1.25rem; background: var(--danger); color: #fff; z-index: 100; }
#blazor-error-ui .reload { color: #fff; margin-left: 1rem; text-decoration: underline; }

/* Phones (UX-001): everything works from 360 px, no sideways scrolling of the page. */
@media (max-width: 700px) {
  .content { padding: 1rem 16px 3rem; }
  .topbar { padding: 0 16px; }
  .menu-toggle { display: inline-flex; flex-direction: column; gap: 4px; margin-left: auto; border: none; background: none; padding: .5rem; min-height: 44px; }
  .menu-toggle span { width: 22px; height: 2px; background: var(--text); display: block; }
  .mainnav { display: none; position: absolute; top: 56px; left: 0; right: 0; background: var(--surface); flex-direction: column; align-items: stretch; padding: .5rem 16px 1rem; border-bottom: 1px solid var(--border); }
  .mainnav.open { display: flex; }
  .mainnav > a { padding: .75rem .5rem; }
  .mainnav .user { margin: .5rem 0 0; justify-content: space-between; }
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .week-strip { grid-template-columns: repeat(4, 1fr); }
  .entry { flex-wrap: wrap; }
  .entry .what { flex-basis: 100%; }
  .entry .duration { text-align: left; }
  .entry .actions { margin-left: auto; }
  button, .button, input, select { min-height: 44px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: .4rem; }
  input.wide { min-width: 10rem; }
  .bar .bar-label { display: none; }
  .report-rows .share { display: none; }
}

/* Something just saved: a time cell or an entry (TT-004). */
.saved { animation: saved 1.6s ease-out; }
@keyframes saved {
  0%, 30% { background-color: color-mix(in srgb, var(--ok) 28%, transparent); }
  100% { background-color: transparent; }
}
