/* ============================================================
   BUDGET — marketing cost-budget tool
   Mirrors the Försäljning / Lista design language.
   ============================================================ */

.bu-page { display: flex; flex-direction: column; gap: 24px; padding-bottom: 48px; }

/* ── TOPBAR ───────────────────────────────────────────────── */
.bu-top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px 14px;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
}
.bu-top-left { display: flex; align-items: center; gap: 8px; }
.bu-top-right { display: flex; align-items: center; gap: 10px; }
.bu-top-title {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--text);
}
.bu-top-crumb {
  font-size: 13px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.bu-top-link {
  font-size: 13px;
  color: var(--text-muted);
  transition: color 100ms;
}
.bu-top-link:hover { color: var(--text); }
.bu-top-link.is-active { color: var(--text); font-weight: 500; }

/* Year stepper — matches Försäljning's fo-months pill */
.bu-year {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--hairline);
  border-radius: 7px;
}
.bu-year-btn {
  width: 26px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  border-radius: 5px;
  transition: background 100ms, color 100ms;
}
.bu-year-btn:hover { background: var(--hairline); color: var(--text); }
.bu-year-label {
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: center;
}

.bu-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: var(--bg-elevated);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  transition: border-color 120ms, background 120ms;
}
.bu-btn:hover { border-color: var(--hairline-strong); background: var(--surface); }
.bu-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.bu-btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.bu-btn-primary:hover { background: var(--text); border-color: var(--text); opacity: 0.92; }
.bu-btn-icon {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  background: var(--bg-elevated);
  color: var(--text-muted);
}
.bu-btn-icon:hover { color: var(--text); border-color: var(--hairline-strong); }

.bu-sync-msg {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── KPI ROW ──────────────────────────────────────────────── */
.bu-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 0 32px;
}
.bu-kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
}
.bu-kpi-k {
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.bu-kpi-v {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  font-family: "Crimson Pro", "Clarendon Text", Georgia, serif;
  line-height: 1;
  margin-top: 2px;
}
.bu-kpi-v-unit {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  letter-spacing: 0.04em;
  margin-left: 4px;
  font-weight: 400;
}
.bu-kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.bu-kpi-sub.is-good { color: var(--h-strong); }
.bu-kpi-sub.is-bad { color: var(--h-critical); }

/* ── GRID TABLE ───────────────────────────────────────────── */
.bu-grid-wrap {
  margin: 0 32px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.bu-grid-scroll { overflow-x: auto; }

.bu-grid {
  width: 100%;
  font-size: 13px;
  color: var(--text);
  border-collapse: collapse;
}
.bu-grid thead tr {
  border-bottom: 1px solid var(--hairline);
  background: var(--bg-sunken);
}
.bu-grid th {
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-align: right;
  padding: 12px 12px;
  white-space: nowrap;
}
.bu-grid th.bu-th-cat {
  text-align: left;
  padding-left: 22px;
  min-width: 240px;
  position: sticky;
  left: 0;
  background: var(--bg-sunken);
  z-index: 2;
}
.bu-grid th.bu-th-year {
  border-left: 1px solid var(--hairline);
  background: var(--bg-elevated);
}
.bu-grid th.bu-th-total {
  text-align: right;
  padding-right: 22px;
  border-left: 1px solid var(--hairline);
  background: var(--bg-sunken);
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 100px;
}
.bu-grid th button {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}
.bu-grid th button:hover { color: var(--text); }

.bu-grid tbody tr {
  border-top: 1px solid var(--hairline);
  transition: background 100ms;
}
.bu-grid tbody tr:first-child { border-top: 0; }
.bu-grid tbody tr:hover { background: var(--bg-sunken); }

.bu-grid td {
  padding: 14px 12px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}
.bu-grid td.bu-td-cat {
  text-align: left;
  padding-left: 22px;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  font-weight: 500;
}
.bu-grid tbody tr:hover td.bu-td-cat { background: var(--bg-sunken); }
.bu-cat-row { display: inline-flex; align-items: center; gap: 10px; }
.bu-cat-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0;
  min-width: 38px;
}
.bu-cat-name { color: var(--text); font-size: 13.5px; font-weight: 500; letter-spacing: -0.005em; }
.bu-cat-badge {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  background: var(--h-soldout-bg);
  color: var(--h-soldout);
  border-radius: 999px;
}

.bu-grid td.bu-td-year {
  border-left: 1px solid var(--hairline);
  background: oklch(from var(--bg-elevated) l c h / 0.5);
}

.bu-grid td.bu-td-total {
  border-left: 1px solid var(--hairline);
  padding-right: 22px;
  position: sticky;
  right: 0;
  background: var(--surface);
  z-index: 1;
  font-weight: 500;
}
.bu-grid tbody tr:hover td.bu-td-total { background: var(--bg-sunken); }
.bu-total-main { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.bu-total-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; font-variant-numeric: tabular-nums; }

.bu-cell { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bu-cell-empty { color: var(--text-faint); font-size: 14px; }
.bu-cell-main {
  font-size: 13.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}
.bu-cell-sub {
  font-size: 10.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.bu-cell-sub.is-good { color: var(--h-strong); }
.bu-cell-sub.is-bad { color: var(--h-critical); }
.bu-cell-btn {
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: right;
  transition: opacity 100ms;
}
.bu-cell-btn:hover { opacity: 0.65; }
/* Empty-cell "+" affordance — hidden until row is hovered, then faint. */
.bu-cell-add { opacity: 0; }
.bu-cell-add .bu-cell-empty { color: var(--text-quiet); font-weight: 500; }
.bu-grid tr:hover .bu-cell-add { opacity: 0.45; }
.bu-grid tr:hover .bu-cell-add:hover { opacity: 1; }

/* Section header (e.g. "Projekt") above its rows in the same grid. */
.bu-grid tr.bu-section-head td {
  padding-top: 18px;
  padding-bottom: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-top: 1px solid var(--hairline);
}
/* Drag-and-drop: items show grab cursor on their name column (cells have
   their own buttons which capture mousedown — drag from the name area). */
.bu-item-row.is-draggable .bu-td-cat { cursor: grab; user-select: none; }
.bu-item-row.is-draggable .bu-td-cat:active { cursor: grabbing; }
.bu-drag-handle {
  color: var(--text-faint);
  transition: color 120ms;
}
.bu-item-row.is-draggable:hover .bu-drag-handle { color: var(--text-quiet); }
.bu-project-row.is-drop-target td {
  background: color-mix(in oklch, var(--accent, #047857) 8%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent, #047857);
}

/* Project rows: positive net = subtle green, negative = subtle red. */
.bu-net-pos { color: var(--h-strong, #047857); }
.bu-net-neg { color: var(--h-critical, #b91c1c); }

/* Inline row actions (edit/delete on project rows) — revealed on row hover.
   Matches v2 .bu-btn-icon (hairline border, bg-elevated hover) at a smaller
   inline scale appropriate for a table row. */
.bu-row-actions {
  display: inline-flex;
  gap: 2px;
  margin-left: 8px;
  opacity: 0;
  transition: opacity 120ms;
}
.bu-project-row:hover .bu-row-actions { opacity: 1; }
.bu-row-actions:focus-within { opacity: 1; }
.bu-row-action {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.bu-row-action:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--hairline);
}
.bu-row-action:focus-visible {
  outline: none;
  border-color: var(--hairline-strong);
}
.bu-row-action.is-danger:hover {
  color: var(--h-critical, #b91c1c);
  border-color: var(--h-critical, #b91c1c);
  background: transparent;
}

/* Parent-row expand toggle */
.bu-cat-disclosure {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-faint);
  transition: color 100ms, transform 120ms var(--ease);
  margin-right: -4px;
  cursor: pointer;
  background: transparent;
  padding: 0;
}
.bu-cat-disclosure:hover { color: var(--text); }
.bu-cat-disclosure.is-open { transform: rotate(90deg); }
.bu-cat-disclosure.is-empty { visibility: hidden; }

/* Item subrows — indented under their parent */
.bu-grid tr.bu-item-row td { padding-top: 10px; padding-bottom: 10px; }
.bu-grid tr.bu-item-row td.bu-td-cat {
  padding-left: 50px;
  font-weight: 400;
  background: var(--bg);
}
.bu-grid tr.bu-item-row:hover td.bu-td-cat { background: var(--bg-sunken); }
.bu-grid tr.bu-item-row td.bu-td-total { font-weight: 400; background: var(--bg); }
.bu-grid tr.bu-item-row:hover td.bu-td-total { background: var(--bg-sunken); }
.bu-grid tr.bu-item-row .bu-cat-name { color: var(--text-quiet); font-weight: 400; font-size: 13px; }
.bu-grid tr.bu-item-row .bu-cell-main { color: var(--text-quiet); font-size: 13px; }
.bu-grid tr.bu-item-row .bu-total-main { font-size: 13px; color: var(--text-quiet); }

/* Subtotal / totals */
.bu-grid tr.bu-subtotal {
  border-top: 1px solid var(--hairline-strong);
  background: var(--bg-sunken);
  font-weight: 500;
}
.bu-grid tr.bu-subtotal:hover { background: var(--bg-sunken); }
.bu-grid tr.bu-subtotal td { padding: 16px 12px; }
.bu-grid tr.bu-subtotal td.bu-td-cat {
  background: var(--bg-sunken);
  font-size: 13.5px;
  color: var(--text);
}
.bu-grid tr.bu-subtotal td.bu-td-total {
  background: var(--bg-sunken);
  font-weight: 600;
  font-size: 14px;
}

.bu-empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.bu-empty-title { color: var(--text); font-size: 15px; font-weight: 500; margin-bottom: 6px; }
.bu-empty-hint { font-size: 12.5px; color: var(--text-muted); }

/* Loading / error states */
.bu-state {
  padding: 56px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.bu-state.is-error { color: var(--h-critical); }

/* V2-token native <select> — replaces the hardcoded Tailwind neutrals on the
   ItemFormPanel dropdowns so they match the rest of the V2 design system. */
.bu-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--hairline);
  background-color: var(--surface, var(--bg-elevated));
  color: var(--text);
  border-radius: var(--r-md, 8px);
  padding: 8px 32px 8px 11px;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.12s var(--ease);
}
.bu-select:hover { border-color: var(--hairline-strong); }
.bu-select:focus { outline: none; border-color: var(--hairline-strong); }
.bu-select.sm { margin-top: 4px; padding: 6px 30px 6px 9px; }
.bu-select option { color: var(--text); background: var(--bg-elevated); }
