/* zsybcom tree table — Kunde · Projekt · Task report layout.
   Adapted from the SEIDOS Zeiterfassung design; uses --tb-* tokens so
   it follows theme + accent. Per-row grid (not whole-table grid) so
   that nesting is just plain block elements with display:none toggle. */

.tree-card.is-spaced {
    margin-top: 14px;
}

.tree-cell-label .card-count {
    margin-left: 8px;
}

.tree-cell-label .label-sub {
    margin-left: 10px;
    color: var(--text-3, #888);
    font-size: 11.5px;
}

.tree-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    overflow: hidden;
    box-shadow: 0 1px 0 rgba(20, 17, 12, 0.02);
}

.tree-wrap {
    width: 100%;
}

/* ── Head row (column titles) ───────────────────────────────────────── */
.tree-head {
    display: grid;
    grid-template-columns: 1fr 220px 110px 44px;
    gap: var(--g3);
    align-items: center;
    padding: 8px 16px;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.tree-head .th-share {
    text-align: left;
    padding-left: 12px;
}

.tree-head .th-hours {
    text-align: right;
}

/* ── Generic row ────────────────────────────────────────────────────── */
.tree-row {
    display: grid;
    grid-template-columns: 1fr 220px 110px 44px;
    gap: var(--g3);
    align-items: center;
    padding: 0 16px;
    height: 38px;
    border-bottom: 1px solid var(--border);
    transition: background 100ms ease;
}

.tree-row:hover {
    background: var(--surface-2);
}

.tree-group:last-child>.tree-row,
.tree-children>.tree-group:last-child .tree-row:last-child {
    /* avoid double border at very end of card */
}

/* Depth tints — Kunde row is the heaviest. */
.tree-row[data-depth="0"] {
    background: var(--surface-2);
    font-weight: 600;
}

.tree-row[data-depth="0"]:hover {
    background: var(--surface-3);
}

/* ── Label cell + indent + toggle ───────────────────────────────────── */
.tree-cell-label {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.tree-indent {
    display: inline-block;
    flex: 0 0 auto;
}

.tree-row[data-depth="1"] .tree-indent {
    width: 16px;
}

.tree-row[data-depth="2"] .tree-indent {
    width: 32px;
}

.tree-row[data-depth="3"] .tree-indent {
    width: 48px;
}

.tree-toggle {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--accent-text);
    transition: transform 160ms ease, background 100ms ease, color 100ms ease;
    flex: 0 0 auto;
    cursor: pointer;
    padding: 0;
    font-size: 10px;
}

.tree-toggle:hover {
    background: var(--surface-3);
    color: var(--text);
}

.tree-toggle[data-leaf="true"] {
    visibility: hidden;
    cursor: default;
}

.tree-group[data-expanded="true"]>.tree-row>.tree-cell-label>.tree-toggle:not([data-leaf="true"]) {
    transform: rotate(90deg);
}

.label-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Per-depth label styling. */
.tree-row[data-depth="0"] .label-text {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
}

.tree-row[data-depth="1"] .label-text {
    font-weight: 600;
    color: var(--accent-text, var(--accent));
    font-size: 13px;
}

.tree-row[data-depth="2"] .label-text {
    color: var(--text-2);
    font-size: 12.5px;
}

.tree-row[data-depth="3"] .label-text {
    color: var(--text-3);
    font-size: 12px;
}

/* Tags / badges. */
.tree-tag {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 6px;
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-3);
    border: 1px solid var(--border);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    margin-left: 6px;
    flex: 0 0 auto;
}

/* ── Hours cell ─────────────────────────────────────────────────────── */
.hours-cell {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.tree-row[data-depth="0"] .hours-cell {
    font-size: 14px;
    font-weight: 600;
}

.tree-row[data-depth="1"] .hours-cell {
    color: var(--accent-text, var(--accent));
    font-weight: 600;
}

.tree-row[data-depth="2"] .hours-cell {
    color: var(--text-2);
    font-size: 12.5px;
}

.tree-row[data-depth="3"] .hours-cell {
    color: var(--text-3);
    font-size: 12px;
}

/* ── Share bar (% of parent) ────────────────────────────────────────── */
.share-cell {
    display: flex;
    align-items: center;
    padding-left: 12px;
}

.share-bar {
    position: relative;
    height: 6px;
    width: 100%;
    max-width: 180px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.share-bar .fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    background: color-mix(in oklab, var(--accent) 65%, transparent);
    border-radius: 3px;
    transition: width 240ms cubic-bezier(.4, 0, .2, 1);
}

.tree-row[data-depth="0"] .share-bar .fill {
    background: var(--accent);
}

/* ── Action cell (eye etc.) ─────────────────────────────────────────── */
.row-action {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.row-action .icon-btn {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--rad-2, 6px);
    cursor: pointer;
    opacity: 0.72;
    transition: opacity 100ms ease, background 100ms ease, border-color 100ms ease, color 100ms ease;
    font-size: 12px;
    text-decoration: none;
}

.tree-row:hover .row-action .icon-btn {
    opacity: 1;
}

.row-action .icon-btn:hover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

/* ── Group expand/collapse ─────────────────────────────────────────── */
.tree-group[data-expanded="false"]>.tree-children {
    display: none;
}

/* ── Filter / toolbar bar above the tree ───────────────────────────── */
.tree-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.tree-toolbar input[type="date"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--rad-2, 6px);
    padding: 4px 8px;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12px;
    height: 30px;
}

.tree-toolbar label {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    margin: 0;
}

.tree-toolbar .toolbar-spacer {
    flex: 1 1 auto;
}

.tree-toolbar .toolbar-total {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.tree-toolbar .toolbar-total small {
    color: var(--text-3);
    font-weight: 500;
    margin-right: 6px;
}

/* ── Period bar (preset chips + date range + summary) ──────────────── */
.period-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 12px);
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.period-chips {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--rad-2, 6px);
    padding: 2px;
    gap: 1px;
}

.period-chips button {
    height: 26px;
    padding: 0 12px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-2);
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.period-chips button:hover {
    color: var(--text);
}

.period-chips button[data-active="true"] {
    background: var(--surface-2);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(20, 17, 12, 0.06);
}

.date-input {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    height: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--rad-2, 6px);
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12.5px;
    color: var(--text);
}

.date-input i {
    color: var(--text-3);
    font-size: 11px;
}

.date-input input {
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    width: 110px;
    padding: 0;
}

.date-range-sep {
    color: var(--text-3);
    font-size: 12px;
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
}

.period-summary {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 12.5px;
    flex-wrap: wrap;
}

.ps-block {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.ps-lbl {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
}

.ps-val {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-weight: 500;
    font-size: 14px;
    color: var(--text);
}

.ps-val.is-accent {
    color: var(--accent-text, var(--accent));
    font-size: 16px;
}

.tree-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 12.5px;
}

/* ── Slim variant (2-col: label + actions) for Geschlossen / Tasks ───── */
.tree-wrap--slim .tree-head,
.tree-wrap--slim .tree-row {
    grid-template-columns: 1fr 60px;
    gap: var(--g2);
}

/* No toggle button needed — always expanded */
.tree-wrap--slim .tree-toggle {
    display: none;
}

/* Compact row height */
.tree-wrap--slim .tree-row {
    height: 34px;
}

/* depth-0 customer row is a link */
.tree-wrap--slim .tree-row[data-depth="0"] a.tree-customer-link {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
}

.tree-wrap--slim .tree-row[data-depth="0"] a.tree-customer-link:hover {
    color: var(--accent-text);
    text-decoration: underline;
}

/* depth-1 project label */
.tree-wrap--slim .tree-row[data-depth="1"] .label-text {
    color: var(--accent-text, var(--accent));
    font-weight: 600;
    font-size: 13px;
}

/* depth-2 task label (Tasks page only) */
.tree-wrap--slim .tree-row[data-depth="2"] .label-text {
    color: var(--text-2);
    font-size: 12.5px;
}

/* ── Projects variant (4-col flat: name + customer + status + actions) ── */
.tree-wrap--projects .tree-head,
.tree-wrap--projects .tree-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 120px 96px;
    gap: var(--g3);
}

.tree-wrap--projects .tree-row {
    height: 38px;
}

/* Flat list — no depth tint */
.tree-wrap--projects .tree-row[data-depth="1"] {
    background: transparent;
    font-weight: 500;
}

.tree-wrap--projects .tree-row .label-text {
    color: var(--text);
    font-weight: 500;
    font-size: 13px;
}

.tree-wrap--projects .tree-row a.link-plain {
    color: inherit;
    text-decoration: none;
}

.tree-wrap--projects .tree-row a.link-plain:hover .label-text,
.tree-wrap--projects .tree-row a.link-plain:hover {
    color: var(--accent-text, var(--accent));
}

.tree-wrap--projects .tree-row .muted {
    color: var(--text-3);
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Billing variant — Rechnungsdetails show view ──────────────────────────── */
/* Wider price column (130 px) so "3.130,00 €" + icon fit; no share bar. */
.tree-wrap--billing .tree-head,
.tree-wrap--billing .tree-row {
    grid-template-columns: 1fr 200px 100px 130px;
}

.tree-wrap--billing .tree-head .th-action {
    text-align: right;
    padding-right: 16px;
}

/* Employee column: plain text, no share bar */
.tree-wrap--billing .share-cell {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12.5px;
    color: var(--text);
}

/* Zeit column already has monospace via .hours-cell; ensure it for billing too */
.tree-wrap--billing .hours-cell {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
}

/* Price cell: stack price + rate label vertically, right-aligned */
.tree-wrap--billing .row-action {
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 1px;
    padding-right: 4px;
}

.tree-wrap--billing .price-main {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.tree-wrap--billing .price-rate {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 11.5px;
    color: var(--text-2);
}

/* Aggregate totals at depth 0/1/2 — muted price, no rate */
.tree-wrap--billing .tree-row[data-depth="0"] .price-main,
.tree-wrap--billing .tree-row[data-depth="1"] .price-main,
.tree-wrap--billing .tree-row[data-depth="2"] .price-main {
    font-size: 12.5px;
    color: var(--text-2);
    font-weight: 500;
}

/* Allow rows to grow with their content instead of clipping at 38px */
.tree-wrap--billing .tree-row {
    height: auto;
    min-height: 40px;
    padding-top: 7px;
    padding-bottom: 7px;
}

/* Time range shown inline with date (e.g. "17.06.2025 10:00–15:40") */
.tree-wrap--billing .billing-time {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 12px;
    color: var(--text-2);
    font-weight: 400;
    margin-left: 6px;
}

/* Night surcharge label in price cell */
.price-night {
    color: var(--warn-text, oklch(0.38 0.09 75));
}

html[data-theme="dark"] .price-night {
    color: var(--warn-text, oklch(0.88 0.09 75));
}

/* Work-entry label cell: date on line 1, description on line 2 */
.tree-wrap--billing .tree-row[data-depth="3"] .tree-cell-label {
    flex-wrap: wrap;
    align-items: baseline;
    row-gap: 1px;
}

/* Date: stay on first line, don't shrink */
.tree-wrap--billing .tree-row[data-depth="3"] .label-text {
    font-family: 'IBM Plex Mono', ui-monospace, monospace;
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    flex-shrink: 0;
    white-space: nowrap;
    line-height: 1.5;
}

/* Description: push to its own line, aligned under the date */
.tree-wrap--billing .tree-row[data-depth="3"] .label-sub {
    flex-basis: 100%;
    /* 48px indent + 6px gap = aligned with start of label-text */
    padding-left: 54px;
    color: var(--text-2);
    font-size: 12.5px;
    line-height: 1.5;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    margin-left: 0;
}

/* ── Grouped variant (3-col: label + middle + actions, with toggle support) ── */
.tree-wrap--grouped .tree-head,
.tree-wrap--grouped .tree-row {
    grid-template-columns: 1fr auto auto;
    gap: var(--g3);
}

.tree-wrap--grouped .tree-row {
    height: 36px;
}

.tree-wrap--grouped .tree-row[data-depth="1"] .label-text {
    color: var(--text-2);
    font-size: 13px;
    font-weight: 400;
}
