/* Lexara Billing — Frontend Styles
   Palette: conservative legal-industry greys + accent teal, warning amber,
   critical coral. Type: Inter for UI, Source Serif for invoice preview.
*/

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --ink: #1a1d21;
  --ink-2: #3a4048;
  --ink-3: #646c76;
  --ink-4: #9099a3;
  --rule: #e5e4e0;
  --rule-2: #d4d2cd;
  --accent: #0d6b62;
  --accent-ink: #ffffff;
  --accent-soft: #e6f2f0;
  --warn: #b27a1b;
  --warn-soft: #fbf1de;
  --crit: #a9362f;
  --crit-soft: #f8e7e4;
  --shadow-sm: 0 1px 2px rgba(20, 30, 40, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 30, 40, 0.08);
  --shadow-lg: 0 12px 48px rgba(20, 30, 40, 0.18);
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Inter",
    system-ui,
    -apple-system,
    sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  overflow: hidden;
}

.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--rule-2);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 120ms,
    border-color 120ms;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--ink-4);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: #0a5650;
  border-color: #0a5650;
}
.btn-secondary {
  background: var(--surface);
}

/* ===================== TOP BAR ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--shadow-sm);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}
.logo-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.logo-sub {
  font-size: 12px;
  color: var(--ink-3);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.kpi {
  text-align: right;
  padding: 0 12px;
  border-right: 1px solid var(--rule);
}
.kpi:last-of-type {
  border-right: none;
}
.kpi-value {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.kpi-label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kpi-exceptions .kpi-value {
  color: var(--warn);
}
.kpi-risk .kpi-value {
  color: var(--crit);
}

.cycle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid #cde0dd;
  border-radius: var(--radius);
}
.cycle-before,
.cycle-after {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.cycle-before-value {
  font-size: 13px;
  color: var(--ink-3);
  text-decoration: line-through;
}
.cycle-before-label,
.cycle-after-label {
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cycle-after-value {
  font-size: 15px;
  color: var(--accent);
  font-weight: 600;
}
.cycle-arrow {
  color: var(--ink-3);
  font-size: 14px;
}

/* ===================== VIEW NAV ===================== */
.view-nav {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.view-nav-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition:
    color 120ms,
    border-color 120ms;
}
.view-nav-btn:hover {
  color: var(--ink);
}
.view-nav-btn.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.view-nav-icon {
  font-size: 13px;
  color: var(--ink-4);
}
.view-nav-btn.active .view-nav-icon {
  color: var(--accent);
}
.view-nav-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  margin-left: 2px;
}
.view-nav-spacer {
  flex: 1;
}
.view-nav-cycle {
  font-size: 12px;
  color: var(--ink-3);
  padding-right: 6px;
}
.view-nav-cycle strong {
  color: var(--ink);
  font-weight: 600;
}

.view {
  min-height: 0;
  overflow-y: auto;
}
.view[hidden] {
  display: none !important;
}

/* ===================== DEPARTMENTS VIEW ===================== */
#view-departments {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dept-hero {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 20px;
  padding: 24px 28px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  align-items: center;
}
.dept-hero-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 20px;
  border-right: 1px solid var(--rule);
}
.dept-hero-stat:nth-child(4) {
  border-right: none;
}
.dept-hero-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.dept-hero-label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.dept-hero-stat-risk .dept-hero-value {
  color: var(--crit);
}
.dept-hero-stat-fees .dept-hero-value {
  color: var(--accent);
}
.dept-hero-cta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.dept-hero-meta {
  font-size: 11px;
  color: var(--ink-3);
  text-align: right;
}

.dept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.dept-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 20px;
  cursor: pointer;
  transition:
    border-color 140ms,
    box-shadow 140ms,
    transform 140ms;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dept-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.dept-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.dept-card-code {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  padding: 2px 8px;
  background: var(--accent-soft);
  border-radius: 4px;
}
.dept-card-matters {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dept-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.dept-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.dept-card-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dept-card-stat-value {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.dept-card-stat-label {
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.dept-card-stat-exc .dept-card-stat-value {
  color: var(--warn);
}
.dept-card-stat-risk .dept-card-stat-value {
  color: var(--crit);
}
.dept-card-foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dept-card-bar {
  height: 6px;
  background: var(--rule);
  border-radius: 3px;
  overflow: hidden;
}
.dept-card-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--warn) 0%, var(--crit) 100%);
  border-radius: 3px;
}
.dept-card-bar-label {
  font-size: 11px;
  color: var(--ink-3);
}
.dept-card-cta {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-align: right;
  margin-top: -4px;
}

/* ===================== EXCEPTIONS GRID ===================== */
#view-grid {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.grid-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.grid-filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.grid-filter {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 140px;
}
.grid-filter label {
  font-size: 10.5px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.grid-filter select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--rule-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.grid-filter select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.grid-stats {
  font-size: 13px;
  color: var(--ink-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.grid-stats strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}
.grid-stats-risk {
  color: var(--crit) !important;
}
.grid-stats-pct {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-left: 4px;
}

.grid-batchbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--accent-soft);
  border-bottom: 1px solid #cde0dd;
}
.grid-batchbar-summary {
  font-size: 13px;
  color: var(--ink);
}
.grid-batchbar-summary strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}
.grid-batchbar-actions {
  display: flex;
  gap: 8px;
}
.grid-batchbar-toast {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  padding: 4px 0;
}

.grid-container {
  flex: 1;
  overflow: auto;
  background: var(--surface);
}
.grid-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
.grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule-2);
  padding: 10px 12px;
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  font-weight: 600;
  white-space: nowrap;
}
.grid-table thead th[data-sort] {
  cursor: pointer;
  user-select: none;
}
.grid-table thead th[data-sort]:hover {
  color: var(--ink);
}
.grid-table thead th.grid-impact {
  text-align: right;
}
.grid-table thead th.grid-select,
.grid-table thead th.grid-severity {
  width: 40px;
  text-align: center;
}
.grid-table tbody tr {
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background 80ms;
}
.grid-table tbody tr:hover {
  background: var(--surface-2);
}
.grid-table tbody tr.selected {
  background: var(--accent-soft);
}
.grid-table tbody tr.selected:hover {
  background: #daeae7;
}
.grid-table tbody tr.resolved {
  opacity: 0.5;
}
.grid-table tbody tr.resolved .grid-matter-name {
  text-decoration: line-through;
}
.grid-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.grid-table tbody td.grid-select,
.grid-table tbody td.grid-severity {
  text-align: center;
  vertical-align: middle;
}
.grid-row-checkbox {
  cursor: pointer;
  width: 15px;
  height: 15px;
}
.grid-severity-chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 3px;
}
.grid-severity-chip.high {
  background: var(--crit-soft);
  color: var(--crit);
}
.grid-severity-chip.medium {
  background: var(--warn-soft);
  color: var(--warn);
}
.grid-severity-chip.low {
  background: var(--rule);
  color: var(--ink-3);
}
.grid-division-code {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
  padding: 1px 6px;
  background: var(--accent-soft);
  border-radius: 3px;
  margin-right: 6px;
}
.grid-division-name {
  font-size: 11.5px;
  color: var(--ink-3);
}
.grid-matter-name {
  font-weight: 500;
  color: var(--ink);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid-matter-client {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 2px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid-timekeeper {
  color: var(--ink-2);
  font-size: 12px;
}
.grid-rule {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
}
.grid-title {
  color: var(--ink);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.grid-impact {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.grid-impact-value {
  font-weight: 600;
  color: var(--crit);
}
.grid-impact-ctx {
  color: var(--ink-3);
  font-size: 11.5px;
  font-style: italic;
}
.grid-status {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 3px;
}
.grid-status.open {
  background: var(--warn-soft);
  color: var(--warn);
}
.grid-status.resolved {
  background: var(--accent-soft);
  color: var(--accent);
}
.grid-status.kept {
  background: var(--rule);
  color: var(--ink-3);
}
.grid-loading,
.grid-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-3);
  font-size: 13px;
}

.grid-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--rule);
}
.grid-pagination-label {
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  min-width: 160px;
  text-align: center;
}

/* ===================== MATTER TABS (legacy) ===================== */
.matter-tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  overflow-x: auto;
}
.matter-tab {
  display: flex;
  flex-direction: column;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: background 120ms;
  min-width: 260px;
  gap: 3px;
}
.matter-tab:hover {
  background: var(--surface-2);
}
.matter-tab.active {
  border-bottom-color: var(--accent);
  background: var(--surface-2);
}
.matter-tab-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
}
.matter-tab-client {
  font-size: 11px;
  color: var(--ink-3);
}
.matter-tab-meta {
  display: flex;
  gap: 10px;
  margin-top: 3px;
  font-size: 11px;
}
.matter-tab-fees {
  color: var(--ink-2);
  font-weight: 500;
}
.matter-tab-exceptions {
  color: var(--warn);
  font-weight: 600;
}
.matter-tab-exceptions.zero {
  color: var(--ink-4);
}

/* ===================== WORKSPACE ===================== */
.workspace {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 16px;
  padding: 16px 24px;
  overflow: hidden;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  min-height: 0;
  overflow: hidden;
}
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface-2);
}
.pane-title {
  font-size: 14px;
  font-weight: 600;
}
.pane-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
}

.queue-filters {
  display: flex;
  gap: 6px;
}
.chip {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule-2);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover {
  background: var(--surface-2);
}
.chip-active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

/* ===================== QUEUE ===================== */
.queue-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.queue-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 120ms,
    border-color 120ms;
  margin-bottom: 6px;
}
.queue-item:hover {
  background: var(--surface-2);
  border-color: var(--rule);
}
.queue-item-severity {
  width: 3px;
  height: 36px;
  border-radius: 2px;
}
.queue-item-severity.high {
  background: var(--crit);
}
.queue-item-severity.medium {
  background: var(--warn);
}
.queue-item-severity.low {
  background: var(--ink-4);
}

.queue-item-body {
  min-width: 0;
}
.queue-item-title {
  font-weight: 500;
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.queue-item-meta {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 3px;
}
.queue-item-rule {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--rule);
  color: var(--ink-2);
  margin-right: 6px;
}

.queue-item-impact {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.queue-item-dollar {
  font-weight: 600;
  font-size: 14px;
  color: var(--crit);
}
.queue-item-dollar.zero {
  color: var(--ink-3);
}
.queue-item-status {
  font-size: 10.5px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.queue-item.resolved {
  opacity: 0.55;
  background: var(--surface-2);
}
.queue-item.resolved .queue-item-title {
  text-decoration: line-through;
}

.queue-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

/* ===================== INVOICE PREVIEW ===================== */
.invoice-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--surface-2);
}
.invoice-card {
  background: #fff;
  padding: 32px 36px;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-sm);
  font-family: "Source Serif 4", Georgia, serif;
  color: var(--ink);
}
.invoice-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 20px;
}
.invoice-from-name {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.invoice-from-tagline {
  font-size: 12px;
  color: var(--ink-3);
  font-family: "Inter", sans-serif;
}
.invoice-meta {
  text-align: right;
  font-size: 12px;
  color: var(--ink-2);
  font-family: "Inter", sans-serif;
}
.invoice-meta-row {
  display: flex;
  gap: 16px;
  justify-content: flex-end;
}
.invoice-meta-label {
  color: var(--ink-3);
}
.invoice-meta-value {
  font-weight: 500;
}

.invoice-bill-to {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
  font-family: "Inter", sans-serif;
  font-size: 12.5px;
}
.invoice-section-label {
  font-size: 10.5px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}

.invoice-matter {
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  font-size: 13px;
  margin-bottom: 18px;
  font-family: "Inter", sans-serif;
}
.invoice-matter-label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.invoice-matter-name {
  font-weight: 600;
  font-size: 14px;
  margin-top: 2px;
}
.invoice-matter-number {
  color: var(--ink-3);
  font-size: 11px;
}

.invoice-matter-meta {
  color: var(--ink-3);
  font-size: 11px;
  margin-top: 2px;
}

/* Invoice line table (supports both .invoice-lines and .invoice-table) */
.invoice-lines,
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Inter", sans-serif;
  font-size: 12px;
}
.invoice-lines thead th,
.invoice-table thead th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  padding: 6px 8px;
  border-bottom: 1px solid var(--rule-2);
}
.invoice-lines thead th.num,
.invoice-table thead th.num {
  text-align: right;
}
.invoice-lines tbody td,
.invoice-table tbody td {
  padding: 7px 8px;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
  font-size: 12px;
}
.invoice-lines tbody td.num,
.invoice-table tbody td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.invoice-lines tbody tr.flagged td,
.invoice-table tbody tr.flagged td {
  background: #fcf5f3;
}
.invoice-lines tbody tr.removed td,
.invoice-table tbody tr.removed td {
  opacity: 0.4;
  text-decoration: line-through;
}
.line-narrative {
  max-width: 340px;
}
.line-flags {
  display: inline-flex;
  gap: 4px;
  margin-left: 4px;
}
.line-flag {
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--crit-soft);
  color: var(--crit);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.line-flag.medium {
  background: var(--warn-soft);
  color: var(--warn);
}
.line-flag.removed {
  background: var(--rule);
  color: var(--ink-3);
}

.invoice-totals {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 2px solid var(--ink);
  font-family: "Inter", sans-serif;
}
.invoice-total-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}
.invoice-total-row.grand {
  font-size: 16px;
  font-weight: 700;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  margin-top: 6px;
}
.invoice-total-row .delta {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 500;
}

/* New invoice totals markup (invoice-totals-row) */
.invoice-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  font-family: "Inter", sans-serif;
}
.invoice-totals-label {
  color: var(--ink-2);
}
.invoice-totals-value {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.invoice-totals-row.invoice-totals-adj .invoice-totals-value {
  color: var(--accent);
}
.invoice-totals-row.invoice-totals-due {
  font-size: 16px;
  font-weight: 700;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  margin-top: 6px;
}
.invoice-totals-row.invoice-totals-due .invoice-totals-label,
.invoice-totals-row.invoice-totals-due .invoice-totals-value {
  color: var(--ink);
  font-weight: 700;
}

/* ===================== MODAL ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 29, 33, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(720px, 92vw);
  max-height: 88vh;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-in 160ms ease-out;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--rule);
}
.modal-chip {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}
.modal-chip.high {
  background: var(--crit-soft);
  color: var(--crit);
}
.modal-chip.medium {
  background: var(--warn-soft);
  color: var(--warn);
}
.modal-chip.low {
  background: var(--rule);
  color: var(--ink-3);
}
.modal-chip-high {
  background: var(--crit-soft);
  color: var(--crit);
}
.modal-chip-medium {
  background: var(--warn-soft);
  color: var(--warn);
}
.modal-chip-low {
  background: var(--rule);
  color: var(--ink-3);
}
.modal-subtitle {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-top: 3px;
}
.modal-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover {
  color: var(--ink);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-section {
  margin-bottom: 20px;
}
.modal-label {
  font-size: 10.5px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  font-weight: 600;
}
.modal-explanation {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  padding: 14px 16px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}
.modal-explanation.error {
  background: var(--crit-soft);
  border-left-color: var(--crit);
}
.ai-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-3);
}
.ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-4);
  animation: ai-bounce 1.2s infinite;
}
.ai-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.ai-dot:nth-child(3) {
  animation-delay: 0.3s;
  margin-right: 6px;
}
@keyframes ai-bounce {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-quote {
  font-family: "Source Serif 4", Georgia, serif;
  font-style: italic;
  font-size: 13.5px;
  color: var(--ink-2);
  padding: 10px 16px;
  border-left: 2px solid var(--rule-2);
  margin: 0;
}

.modal-detail {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0;
  font-size: 13px;
}
.modal-detail dt {
  color: var(--ink-3);
  font-weight: 500;
}
.modal-detail dd {
  margin: 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--surface-2);
  border-top: 1px solid var(--rule);
}
.modal-impact {
  font-size: 13px;
  color: var(--ink-2);
}
.modal-impact strong {
  font-size: 15px;
  color: var(--crit);
  font-variant-numeric: tabular-nums;
}
.modal-actions {
  display: flex;
  gap: 8px;
}

/* ===================== MISC ===================== */
.loading {
  display: grid;
  place-items: center;
  padding: 64px 24px;
  color: var(--ink-3);
  font-size: 13px;
}

.ai-stream-fade-in {
  animation: fade-in 280ms ease-out;
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   Ensure the `hidden` attribute beats our display:flex overrides
   ========================================================================== */
.grid-breakdown[hidden],
.grid-pills[hidden],
.grid-pill[hidden] {
  display: none !important;
}

/* ==========================================================================
   Rule-type breakdown chip row (grid toolbar, enhancement #2)
   ========================================================================== */
.grid-breakdown {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.grid-breakdown-label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  white-space: nowrap;
}
.grid-breakdown-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.grid-breakdown-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--rule-2);
  border-radius: 16px;
  font-family: inherit;
  font-size: 12px;
  color: var(--ink-2);
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}
.grid-breakdown-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.grid-breakdown-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.grid-breakdown-chip.active .grid-breakdown-chip-count {
  color: rgba(255, 255, 255, 0.75);
}
.grid-breakdown-chip-name {
  font-weight: 600;
}
.grid-breakdown-chip-pct {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.grid-breakdown-chip-count {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Active-filter pills (timekeeper drill-in from Diagnostics)
   ========================================================================== */
.grid-pills {
  display: flex;
  gap: 6px;
  padding: 8px 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule);
}
.grid-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 16px;
  font-size: 12px;
  color: var(--accent);
}
.grid-pill-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 10.5px;
}
.grid-pill-value {
  font-weight: 600;
  color: var(--ink);
}
.grid-pill-close {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.grid-pill-close:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ==========================================================================
   Diagnostics tab (enhancement #3)
   ========================================================================== */
#view-diagnostics {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.diag-intro {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 22px;
}
.diag-intro-title {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}
.diag-intro-sub {
  font-size: 13px;
  color: var(--ink-3);
  max-width: 640px;
}
.diag-section {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.diag-section .diag-table {
  border-radius: 0 0 var(--radius) var(--radius);
}
.diag-section-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface-2);
}
.diag-section-title {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 2px 0;
}
.diag-section-sub {
  font-size: 12px;
  color: var(--ink-3);
}
.diag-rough {
  color: var(--ink-4);
  font-style: italic;
  margin-left: 4px;
}
.diag-table thead th {
  background: var(--surface-2);
}
.diag-table th.diag-rank,
.diag-table td.diag-rank {
  width: 44px;
  text-align: center;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.diag-table th.num,
.diag-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.diag-table tbody tr.diag-clickable {
  cursor: pointer;
}
.diag-table tbody tr.diag-clickable:hover {
  background: var(--accent-soft);
}
.diag-primary {
  font-weight: 600;
  color: var(--ink);
}
.diag-division {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-2);
  border: 1px solid var(--rule-2);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.05em;
}
.diag-top-clients {
  font-size: 12px;
  color: var(--ink-2);
  max-width: 320px;
}
.diag-days {
  color: var(--accent);
  font-size: 15px;
}

/* ============================================================
   Mobile pass (light) — desktop layout collapses gracefully.
   One media block, no markup changes. <=768px.
   ============================================================ */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
  }
  .topbar-right, .topbar-kpis { flex-wrap: wrap; gap: 8px; row-gap: 6px; }
  .kpi { text-align: left; padding: 0 8px 0 0; border-right: none; }
  .kpi-value { font-size: 16px; }
  .cycle-pill, .cycle-compare, .view-nav-cycle { display: none; }
  /* tab nav scrolls */
  .view-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 8px;
  }
  .view-nav::-webkit-scrollbar { display: none; }
  .view-nav-btn { white-space: nowrap; padding: 12px 12px; }
  /* views */
  .view { padding: 12px; gap: 12px; }
  .dept-hero { grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; }
  .dept-grid { grid-template-columns: 1fr; }
  /* filters + tables scroll instead of crushing */
  .grid-filters, .filter-row { flex-wrap: wrap; gap: 8px; }
  .grid-table-wrap, .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .view table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* modal goes near-fullscreen */
  .modal { width: calc(100vw - 16px); max-height: 94dvh; }
  /* tour bits */
  .tour-tip { width: min(360px, calc(100vw - 24px)); }
  #tour-timers { top: auto; bottom: 70px; right: 12px; font-size: 11px; padding: 7px 12px; }
}
