/* Self-hosted Inter (variable, latin) — official Inter v4, ISC-adjacent
   OFL license. Kept local so nothing loads cross-origin (CSP: font-src 'self'). */
@font-face {
  font-family: "Inter";
  src: url("./InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* Ledger / workbench palette: a single green accent + warm greyscale,
   distinct from a card/network aesthetic. --blue is kept as the accent
   variable name to avoid a global rename; --accent aliases it. */
:root {
  /* Greyscale: Linear neutrals (S3-U). Brand identity now rides on the green
     accent + tabular money, not a warm base tint. */
  --bg: #fcfcfc;
  --surface: #ffffff;
  --surface-soft: #f4f4f5;
  --line: #e9e8e6;
  --line-strong: #dbdad8;
  --text: #282a30;
  --muted: #6f6e77;
  --text-3: #9c9ba1;
  --blue: #1d6b4f;
  --blue-dark: #14523c;
  --accent: #1d6b4f;
  --accent-soft: rgba(29, 107, 79, 0.12);
  --focus-ring: rgba(29, 107, 79, 0.16);
  --green: #2f8a5d;
  --amber: #b07d2e;
  --red: #b3402e;
  --shadow: 0 12px 32px rgba(20, 22, 26, 0.1);
  /* S3-U typography scale (Linear basis): only these sizes/weights ship.
     --text-stat/-timer are the two display sizes (KPI + focus countdown). */
  --font-ui: Inter, -apple-system, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  --text-micro: 11px;
  --text-small: 12px;
  --text-body: 13px;
  --text-emph: 14px;
  --text-title: 16px;
  --text-page: 20px;
  --text-stat: 34px;
  --text-timer: 76px;
  --w-regular: 400;
  --w-medium: 500;
  --w-semibold: 600;
  --r-control: 6px;
  --r-card: 10px;
}

body.theme-dark {
  /* Linear neutral dark, same structure; accent stays ledger green. */
  --bg: #1b1b1e;
  --surface: #232326;
  --surface-soft: #2a2a2e;
  --line: #333338;
  --line-strong: #44444a;
  --text: #f7f8f8;
  --muted: #9c9ba1;
  --text-3: #7a7a80;
  --blue: #5cb98a;
  --blue-dark: #7acca0;
  --accent: #5cb98a;
  --accent-soft: rgba(92, 185, 138, 0.16);
  --focus-ring: rgba(92, 185, 138, 0.28);
  --green: #6fce9b;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: var(--font-ui);
  /* S7-3: explicit base size — without it, headings with no size fell back to
     the UA's 16px and pulled per-mode page titles out of step. */
  font-size: var(--text-body);
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

/* Lucide icons (S3-U): 16px, stroke 1.75, currentColor, inherited from text. */
.ic {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}

.nav-ic {
  display: grid;
  place-items: center;
}

.bs-backup,
.bs-timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.cp-edit {
  display: inline-grid;
  place-items: center;
}

.app {
  display: grid;
  grid-template-columns: 58px 260px minmax(0, 1fr) 340px;
  height: 100vh;
  background: var(--surface);
}

@media (min-width: 1680px) {
  .app {
    max-width: 1680px;
    margin-inline: auto;
    border-inline: 1px solid var(--line);
  }
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  border-radius: var(--r-control);
  color: #fff;
  font-weight: var(--w-semibold);
  background: linear-gradient(135deg, var(--accent), var(--green));
}

.rail-btn,
.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--r-control);
  color: var(--muted);
  background: transparent;
  font-size: var(--text-title);
}

.rail-btn.active,
.rail-btn:hover,
.icon-btn:hover {
  color: var(--blue);
  background: var(--accent-soft);
}

.rail-btn.bottom {
  margin-top: auto;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.sidebar-head,
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

p,
h1,
h2 {
  margin: 0;
}

.sidebar-head p,
.pane-head p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: var(--text-small);
}

.sidebar-head h1,
.pane-head h2,
.view-title {
  margin: 0;
  font-size: var(--text-page);
  line-height: 1.15;
  letter-spacing: 0;
}

.nav-list {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.side-section {
  border-top: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px 4px;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
}

.section-title.flat {
  padding: 0 0 8px;
}

.plain-btn {
  border: 0;
  color: var(--blue);
  background: transparent;
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
}

.search-box {
  padding: 12px 12px 0;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.nav-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-control);
  color: var(--text);
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--surface);
}

.nav-item.active {
  color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.nav-item span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  color: var(--muted);
  font-size: var(--text-small);
}

.nav-meta {
  color: var(--muted);
  font-size: var(--text-micro);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
}

.nav-item.nav-sub {
  padding-left: 20px;
  font-size: var(--text-body);
}

#tagSection[open],
#tagSection {
  padding: 0;
}

#tagSection > summary {
  cursor: pointer;
  list-style: none;
}

#tagSection > summary::-webkit-details-marker {
  display: none;
}

#tagSection > summary::marker {
  content: "";
}

.nav-edit {
  display: none;
  color: var(--muted);
  font-size: var(--text-body);
}

.nav-item:hover .nav-edit {
  display: inline;
}

.nav-edit:hover {
  color: var(--blue);
}

.main-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.head-actions,
.focus-actions,
.calendar-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-btn,
.soft-btn,
.danger-btn,
.quick-form button {
  min-height: 38px; /* S7-4: align with the 38px inputs */
  padding: 0 14px;
  border-radius: var(--r-control);
  font-weight: var(--w-semibold);
}

.primary-btn,
.quick-form button {
  border: 0;
  color: #fff;
  background: var(--blue);
}

.primary-btn:hover,
.quick-form button:hover {
  background: var(--blue-dark);
}

.soft-btn {
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
}

.danger-btn {
  /* S7-4: border/tint derived from the same --red as the text, not a
     hardcoded rgba(217,77,77) that didn't match. */
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--red) 30%, transparent);
  color: var(--red);
  background: color-mix(in srgb, var(--red) 8%, transparent);
}

/* S7-1 mobile nav: hamburger opens the sidebar as a slide-over drawer (same
   pattern as the detail pane). Both controls are desktop-hidden, shown <=760. */
.menu-btn {
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--muted);
}
.menu-btn:hover {
  color: var(--blue);
  border-color: var(--blue);
}
.menu-btn .ic {
  width: 18px;
  height: 18px;
}
.head-actions {
  margin-left: auto;
}
.sidebar-close {
  display: none;
  place-items: center;
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--muted);
}

/* S7-1b header overflow menu: on desktop the secondary actions flow inline
   (display:contents makes .head-more transparent); the "…" button is hidden.
   <=760 they collapse into a "…" popover (see the 760 media block). */
.overflow-btn {
  display: none;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--muted);
}
.overflow-btn:hover {
  color: var(--blue);
  border-color: var(--blue);
}
.head-more {
  display: contents;
}

.task-view,
.calendar-view,
.focus-view,
.stats-view {
  flex: 1;
  min-height: 0;
}

.quick-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px 132px 128px auto;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.quick-form input,
.quick-form select,
.detail-form input,
.detail-form select,
.detail-form textarea,
.focus-card select {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  outline: none;
}

.quick-form input,
.quick-form select,
.focus-card select {
  height: 38px;
  padding: 0 12px;
}

.quick-form input:focus,
.quick-form select:focus,
.detail-form input:focus,
.detail-form select:focus,
.detail-form textarea:focus,
.focus-card select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.stats-line {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 20px;
  color: var(--muted);
  font-size: var(--text-body);
}

.task-list {
  height: calc(100vh - 78px - 72px - 42px);
  overflow: auto;
  padding: 0 12px 24px;
}

.group-title {
  position: sticky;
  top: 0;
  padding: 14px 8px 8px;
  color: var(--muted);
  background: var(--surface);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
  z-index: 1;
}

.task-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-control);
  color: var(--text);
  background: transparent;
  text-align: left;
}

.task-row:hover,
.task-row.selected {
  background: var(--surface-soft);
}

.task-check {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
}

.task-row.done .task-check {
  border-color: var(--green);
  background:
    linear-gradient(135deg, transparent 43%, #fff 44% 55%, transparent 56%),
    var(--green);
}

.task-row.done strong {
  color: var(--muted);
  text-decoration: line-through;
}

.task-main {
  min-width: 0;
}

.task-main strong,
.task-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-main strong {
  font-size: var(--text-emph);
  font-weight: var(--w-semibold);
}

.task-main small,
.task-date {
  color: var(--muted);
  font-size: var(--text-small);
}

/* Priority is also cued without colour (colour-blind safe): high = thick
   ring, medium = default ring, low = dashed ring. */
.task-row.pri-high:not(.done) .task-check {
  border-color: var(--red);
  border-width: 3px;
}

.task-row.pri-medium:not(.done) .task-check {
  border-color: var(--amber);
}

.task-row.pri-low:not(.done) .task-check {
  border-color: var(--green);
  border-style: dashed;
}

.empty {
  display: none;
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.empty.visible {
  display: grid;
  gap: 8px;
  padding-top: 72px;
}

.empty strong {
  color: var(--text);
  font-size: var(--text-title);
}

.empty .soft-btn {
  justify-self: center;
  margin-top: 4px;
}

/* In-flow empty states (below a toolbar or grid) need less headroom than
   the full-pane task empty state. */
.calendar-view .empty.visible,
.timesheet-view .empty.visible,
.invoice-view .empty.visible,
.clients-board .empty.visible {
  padding-top: 32px;
}

.calendar-view {
  padding: 18px 20px;
  overflow: auto;
}

.calendar-toolbar {
  justify-content: center;
  margin-bottom: 16px;
}

.calendar-toolbar strong {
  min-width: 160px;
  text-align: center;
  font-size: var(--text-page);
}

.calendar-grid {
  display: grid;
  /* minmax(0, 1fr): columns share the width evenly and may shrink below the
     content size — labels ellipsize instead of forcing a horizontal scroll. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--line);
}

.calendar-head {
  padding: 8px 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: var(--text-micro);
  font-weight: var(--w-semibold);
  text-align: center;
  text-transform: uppercase;
}

.calendar-day {
  min-height: 116px;
  padding: 8px;
  background: var(--surface);
}

.calendar-day.muted {
  background: var(--surface-soft);
}

.calendar-day.today {
  box-shadow: inset 0 0 0 2px var(--blue);
}

.calendar-date {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
}

.calendar-task {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
  padding: 2px 4px;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text);
  font-size: var(--text-small);
  text-align: left;
  cursor: pointer;
}

.calendar-task:hover {
  background: var(--surface-soft);
}

.calendar-task span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.calendar-count {
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: var(--text-micro);
  text-align: center;
}

.calendar-more {
  margin-top: 2px;
  padding: 0 4px;
  color: var(--muted);
  font-size: var(--text-micro);
}

.calendar-day.muted .calendar-task {
  color: var(--muted);
}

.settings-view {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}

/* One workspace, top of the content flow: timer + task context + today's
   logged entries. Not a lone card floating in empty space. */
.focus-view {
  padding: 24px;
  overflow: auto;
}

.focus-workspace {
  display: grid;
  gap: 16px;
  width: min(560px, 100%);
  margin: 0 auto;
}

/* Metric cards sit at the top of the content flow, not floating centered. */
.stats-view {
  padding: 24px;
  overflow: auto;
}

.settings-card {
  display: grid;
  gap: 16px;
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-card h3:not(.view-title) {
  margin: 0;
  font-size: var(--text-title);
}

.settings-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
}

.settings-field select {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  font-weight: var(--w-regular);
  outline: none;
}

.settings-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.settings-hint {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: var(--text-small);
  line-height: 1.5;
}

.clients-view {
  padding: 24px;
  overflow: auto;
}

.clients-board {
  width: min(760px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.clients-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.clients-head h2 {
  font-size: var(--text-page);
}

.cp-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
}

.cp-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.cp-head strong {
  display: block;
  font-size: var(--text-title);
}

.cp-head small {
  color: var(--muted);
  font-size: var(--text-small);
}

.cp-projects {
  display: grid;
  gap: 6px;
}

.cp-project {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--r-control);
  background: var(--surface-soft);
  font-size: var(--text-body);
}

.cp-edit {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: var(--text-body);
  cursor: pointer;
}

.cp-edit:hover {
  color: var(--blue);
}

.cp-empty {
  color: var(--muted);
  font-size: var(--text-body);
}

.detail-inline-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
}

.detail-inline-check input {
  width: 16px;
  height: 16px;
}

.modal-field textarea {
  min-height: 64px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  font-weight: var(--w-regular);
  outline: none;
  resize: vertical;
}

.modal-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  justify-self: start;
}

#timeEntryList {
  display: grid;
  gap: 6px;
}

.te-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  font-size: var(--text-body);
  text-align: left;
}

.te-row:hover {
  background: var(--surface-soft);
}

.te-amount {
  font-weight: var(--w-semibold);
  font-variant-numeric: tabular-nums;
}

.te-empty {
  color: var(--muted);
  font-size: var(--text-body);
  padding: 4px 2px;
}

.timesheet-view {
  padding: 24px;
  overflow: auto;
}

.ts-board {
  width: min(1100px, 100%);
  margin: 0 auto;
}

.ts-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.ts-range {
  min-width: 120px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ts-toolbar #tsCsv {
  margin-left: auto;
}

.ts-scroll {
  overflow-x: auto;
}

.ts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body);
}

.ts-table th,
.ts-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.ts-table thead th {
  color: var(--muted);
  font-size: var(--text-micro);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
}

.ts-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ts-dow {
  display: block;
}

.ts-dom {
  display: block;
  color: var(--muted);
  font-weight: var(--w-regular);
  font-size: var(--text-micro);
}

.ts-label {
  text-align: left;
  min-width: 160px;
}

.ts-label strong {
  display: block;
}

.ts-label span {
  color: var(--muted);
  font-size: var(--text-small);
}

.ts-zero {
  color: var(--line-strong);
}

.ts-total,
.ts-amount {
  font-weight: var(--w-semibold);
}

.ts-totalrow td {
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
  font-weight: var(--w-semibold);
}

.ts-totalrow .ts-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: var(--text-micro);
}

.ts-warn {
  color: var(--amber);
  font-size: var(--text-body);
  padding: 8px 2px;
}

.billing-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
}

.bs-week em {
  font-style: normal;
  font-weight: var(--w-semibold);
  color: var(--text);
  margin-right: 6px;
}

.bs-timer {
  margin-left: auto;
  color: var(--accent);
  font-weight: var(--w-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

.bs-backup {
  margin-left: auto;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-small);
  white-space: nowrap;
  cursor: pointer;
}

.bs-timer + .bs-backup {
  margin-left: 8px;
}

.bs-backup.ok {
  color: var(--accent);
  border-color: var(--accent-soft);
}

.bs-backup.warn {
  color: var(--amber);
  border-color: rgba(176, 125, 46, 0.35);
}

.backup-status {
  margin-top: 4px;
  padding: 8px 12px;
  border-radius: var(--r-control);
  background: var(--surface-soft);
  font-size: var(--text-body);
}

.backup-status.ok {
  color: var(--accent);
}

.backup-status.warn {
  color: var(--amber);
}

.import-sample {
  margin: 4px 0;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  overflow: hidden;
  font-size: var(--text-small);
}

.import-sample .is-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr auto;
  gap: 8px;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
}

.import-sample .is-row:first-child {
  border-top: 0;
}

.import-sample .is-head {
  color: var(--muted);
  font-weight: var(--w-semibold);
  background: var(--surface-soft);
}

.import-sample .is-row span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.import-sample .is-row span:not(:last-child) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-view {
  padding: 24px;
  overflow: auto;
}

.inv-board {
  width: min(820px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 20px;
}

.inv-generator h2,
.inv-saved h3 {
  margin: 0 0 12px;
}

.inv-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.inv-form .inv-wide {
  grid-column: 1 / -1;
}

.invoice-doc {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
}

.inv-doc-head h1 {
  margin: 0;
  font-size: var(--text-page);
  font-variant-numeric: tabular-nums;
}

.inv-doc-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--text-body);
}

.inv-parties {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.inv-parties h4 {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: var(--text-micro);
  text-transform: uppercase;
}

.inv-parties pre {
  margin: 0;
  font: inherit;
  white-space: pre-wrap;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body);
}

.inv-table th,
.inv-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.inv-table thead th {
  color: var(--muted);
  font-size: var(--text-micro);
  text-transform: uppercase;
}

.inv-table tfoot td {
  border-bottom: 0;
  font-weight: var(--w-semibold);
}

.inv-table .inv-total td {
  border-top: 2px solid var(--line-strong);
  font-size: var(--text-emph);
  font-weight: var(--w-semibold);
}

.inv-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: var(--text-body);
}

.inv-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.inv-saved-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.inv-open {
  flex: 1;
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.inv-open:hover {
  background: var(--surface-soft);
}

.inv-open span {
  color: var(--muted);
}

@media print {
  body.print-invoice .app > :not(.main-pane),
  body.print-invoice .main-pane > :not(#invoiceView),
  body.print-invoice .billing-strip,
  body.print-invoice .no-print,
  body.print-invoice .toast-stack {
    display: none !important;
  }

  body.print-invoice,
  body.print-invoice .app,
  body.print-invoice .main-pane,
  body.print-invoice #invoiceView {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  body.print-invoice .invoice-doc {
    border: 0;
    color: #000;
    background: #fff;
  }
}

.focus-card {
  display: grid;
  gap: 18px;
  width: 100%;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.focus-card p {
  color: var(--muted);
}

.focus-context {
  display: grid;
  gap: 2px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.focus-context strong {
  font-size: var(--text-emph);
}

.focus-context small {
  color: var(--muted);
  font-size: var(--text-small);
}

.focus-context:empty {
  display: none;
}

.focus-today {
  width: 100%;
}

.ft-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
}

.ft-head strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ft-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-body);
}

.ft-row span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ft-row span:last-child {
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ft-empty {
  padding: 12px 0;
  color: var(--muted);
  font-size: var(--text-body);
}

.focus-card > strong {
  font-size: var(--text-timer);
  line-height: 1;
  letter-spacing: 0;
}

.focus-actions {
  justify-content: center;
}

.stats-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
  width: min(760px, 100%);
  margin: 0 auto;
}

.stat-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  background: var(--surface);
}

.stat-card span {
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: var(--text-stat);
  font-variant-numeric: tabular-nums;
}

.detail-pane {
  min-width: 0;
  padding: 24px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.detail-empty {
  display: grid;
  gap: 8px;
  place-items: center;
  height: 100%;
  color: var(--muted);
  text-align: center;
}

.detail-empty strong {
  color: var(--text);
  font-size: var(--text-title);
}

.hidden {
  display: none !important;
}

.detail-form {
  display: grid;
  gap: 18px;
}

.detail-check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.detail-check input {
  width: 18px;
  height: 18px;
}

#detailTitle {
  min-height: 76px;
  padding: 12px;
  border-color: transparent;
  font-size: var(--text-page);
  font-weight: var(--w-semibold);
  resize: vertical;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-grid label,
.notes {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
}

.field-grid input,
.field-grid select,
.notes textarea {
  min-height: 38px;
  padding: 9px 11px;
  color: var(--text);
  font-weight: var(--w-regular);
}

.notes textarea {
  resize: vertical;
}

#subtaskList,
#historyList {
  display: grid;
  gap: 8px;
}

.subtask-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 156px 28px;
  align-items: center;
  gap: 8px;
}

.subtask-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.subtask-row input[type="text"],
.subtask-row input[type="datetime-local"] {
  min-height: 34px;
  padding: 0 9px;
}

.subtask-row button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--r-control);
  color: var(--muted);
  background: transparent;
  font-size: var(--text-page);
}

.subtask-row button:hover {
  color: var(--red);
  background: rgba(217, 77, 77, 0.08);
}

.history-item {
  padding: 8px 10px;
  border-radius: var(--r-control);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: var(--text-small);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(18, 23, 34, 0.45);
  z-index: 50;
}

.modal {
  display: grid;
  gap: 14px;
  width: min(400px, calc(100vw - 40px));
  padding: 22px;
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal h3 {
  margin: 0;
  font-size: var(--text-title);
}

.modal-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: var(--w-semibold);
}

.modal-field input,
.modal-field select {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  color: var(--text);
  background: var(--surface);
  font-weight: var(--w-regular);
  outline: none;
}

.modal-field input:focus,
.modal-field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.modal-field input[type="color"] {
  height: 38px;
  padding: 4px;
}

.modal-text {
  color: var(--text);
  font-size: var(--text-emph);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .danger-btn {
  width: auto;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  z-index: 60;
}

.toast {
  max-width: 340px;
  padding: 10px 16px;
  border-radius: var(--r-control);
  color: var(--bg);
  background: var(--text);
  font-size: var(--text-body);
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
}

.toast.leaving {
  opacity: 0;
  transition: opacity 0.3s;
}

@keyframes toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

.detail-close,
.detail-scrim {
  display: none;
}

/* Below three columns, the detail pane becomes a right-side slide-over
   (never a bottom strip). Rail + sidebar + list stay in the grid. */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: 58px 240px minmax(0, 1fr);
  }

  .detail-pane {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 40;
    width: min(380px, 92vw);
    height: 100vh;
    border-left: 1px solid var(--line);
    border-top: 0;
    box-shadow: -12px 0 40px rgba(20, 30, 50, 0.16);
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

  body.detail-visible .detail-pane {
    transform: translateX(0);
  }

  body.detail-visible .detail-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(18, 23, 34, 0.45);
  }

  .detail-close {
    display: grid;
    place-items: center;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--r-control);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: var(--text-page);
  }

  /* Compact quick-add: title on its own row, then dates/priority/save in a
     row — not a full vertical stack. */
  .quick-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .quick-form input[type="text"] {
    grid-column: 1 / -1;
  }

  /* Save drops to a secondary style: the page's one primary button is the
     header "Add task" (S2-6 single-primary rule). */
  .quick-form button {
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--line);
  }

  .quick-form button:hover {
    background: var(--surface-soft);
  }

  .head-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

/* Phones: single column, sidebar hidden, detail is a full-screen sheet. */
@media (max-width: 760px) {
  .app {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  /* S7-1: sidebar is a left slide-over drawer (was display:none — unreachable) */
  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 41;
    width: min(300px, 88vw);
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(20, 30, 50, 0.18);
  }
  body.sidebar-visible .sidebar {
    transform: translateX(0);
  }
  body.sidebar-visible .detail-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(18, 23, 34, 0.45);
  }
  .menu-btn {
    display: grid;
  }
  .sidebar-close {
    display: grid;
  }

  .detail-pane {
    width: 100vw;
  }

  .quick-form {
    grid-template-columns: 1fr;
  }

  .head-actions {
    position: relative;
  }
  .overflow-btn {
    display: inline-grid;
  }
  .head-more {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 30;
    flex-direction: column;
    min-width: 190px;
    padding: 6px;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-card);
    box-shadow: 0 14px 34px rgba(20, 30, 50, 0.2);
  }
  body.more-open .head-more {
    display: flex;
  }
  .head-more .soft-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    border: 0;
    background: transparent;
  }
  .head-more .soft-btn:hover {
    background: var(--surface-soft);
  }

  /* Compact month grid: date + dots only, no event labels. */
  .calendar-view {
    padding: 12px;
  }

  .calendar-day {
    min-height: 64px;
    padding: 4px;
  }

  .calendar-task {
    padding: 2px 4px;
  }

  .calendar-task span:last-child,
  .calendar-more {
    display: none;
  }
}
