/* Cockpit & Verträge – Stile, siehe docs/COCKPIT.md. Präfix ck- (Cockpit, gemeinsame Bausteine) und vt- (Verträge).
   Nur Tokens aus theme.css. Mobile first. */

/* ------------------------------------------------------------------ Allgemein */
.ck-tone-danger { color: var(--danger); font-weight: 600; }
.ck-tone-warning { color: var(--warning); font-weight: 600; }
.ck-tone-success { color: var(--success); font-weight: 600; }
.ck-empty-line { margin: 0; }
.ck-note { margin: 10px 0 0; }
.ck-more { margin: 6px 0 0; }
.ck-subtitle { display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); }
.ck-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-muted); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1;
  letter-spacing: 0; text-transform: none;
}
.chip.is-active .ck-count { background: var(--brand); color: var(--brand-contrast); }
.ck-inline-link { border: 0; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--brand); cursor: pointer; text-decoration: underline; }
.ck-warn { display: flex; gap: 6px; align-items: flex-start; margin: 10px 0 0; color: var(--warning); }
.ck-warn .icon { margin-top: 2px; }

/* Vergleich mit der Vorperiode (↑/↓) */
.ck-delta { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.5; }
.ck-delta-good { background: var(--success-soft); color: var(--success); }
.ck-delta-bad { background: var(--danger-soft); color: var(--danger); }
.ck-delta-neutral { background: var(--surface-3); color: var(--text-muted); }

/* Balken mit Anteil (z.B. verrechenbar) */
.ck-meter { display: block; height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.ck-meter-fill { display: block; height: 100%; border-radius: inherit; background: var(--brand); position: relative; overflow: hidden; transition: width .3s; }
.ck-meter-sage .ck-meter-fill { background: var(--sage); }
/* Mit Anteil: Gesamtbalken hell, Anteil kräftig */
.ck-meter-fill:has(.ck-meter-part) { background: color-mix(in srgb, var(--brand) 32%, var(--surface-3)); }
.ck-meter-part { position: absolute; inset: 0 auto 0 0; background: var(--brand); border-radius: inherit; }
.ck-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 10px 0 0; font-size: var(--fs-xs); color: var(--text-muted); }
.ck-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.ck-swatch { width: 12px; height: 8px; border-radius: 999px; }
.ck-swatch-part { background: var(--brand); }
.ck-swatch-rest { background: color-mix(in srgb, var(--brand) 32%, var(--surface-3)); }

.ck-bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.ck-bar-label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 5px; font-size: var(--fs-sm); min-width: 0; }
.ck-bar-name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
.ck-bar-name .icon { color: var(--text-muted); }
.ck-bar-num { flex: none; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }

/* Filter-Chips (horizontal scrollbar am Handy) */
.ck-chips { display: flex; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px; }
.ck-chips::-webkit-scrollbar { display: none; }
.ck-chips .chip { flex: none; }
.ck-chip-due:not(.is-active) { border-color: var(--warning); color: var(--warning); }
.ck-chip-due .icon { color: var(--warning); }
@media (min-width: 900px) { .ck-chips { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; } }

/* Hinweis-Banner «x Fristen in den nächsten 30 Tagen» */
.ck-banner { align-items: flex-start; flex-wrap: wrap; padding: 12px 14px; border-radius: var(--radius); }
.ck-banner > .icon { margin-top: 2px; }
.ck-banner-text { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.ck-banner-text strong { color: inherit; }
.alert-warning.ck-banner strong { color: var(--warning); }
.alert-danger.ck-banner strong { color: var(--danger); }
.ck-banner-head { display: flex; flex-wrap: wrap; column-gap: .35em; }
.ck-banner-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ck-banner-item {
  display: block; width: 100%; min-height: 32px; padding: 4px 0; border: 0; background: none; font: inherit; color: var(--text);
  text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.ck-banner-title { font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.ck-banner-item:hover .ck-banner-title { text-decoration-thickness: 2px; }
.ck-banner > .btn { flex: none; align-self: center; }

/* ------------------------------------------------------------------ Cockpit */
.ck-page { gap: 14px; }
.ck-toolbar { display: flex; flex-direction: column; gap: 8px; }
.ck-toolbar .segmented { align-self: stretch; }
.ck-toolbar .segmented-item { flex: 1 1 0; }
.ck-period { margin: 0; }
@media (min-width: 720px) {
  .ck-toolbar { flex-direction: row; align-items: center; gap: 14px; flex-wrap: wrap; }
  .ck-toolbar .segmented { align-self: auto; }
  .ck-toolbar .segmented-item { flex: none; min-width: 78px; }
}

/* Kacheln in Spalten (Verteilung in cockpit.js nach geschätzter Höhe – keine Lücken unter kurzen Kacheln) */
.ck-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; transition: opacity .2s; }
.ck-grid.is-loading { opacity: .6; }
.ck-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ck-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ck-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.ck-tile { display: flex; flex-direction: column; padding: 14px 16px 4px; min-width: 0; }
.ck-tile-alert { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.ck-tile-head { display: flex; align-items: center; gap: 10px; min-width: 0; margin-bottom: 10px; }
.ck-tile-icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand); }
.ck-tile-alert .ck-tile-icon { background: var(--danger-soft); color: var(--danger); }
.ck-tile-title { flex: 1 1 auto; min-width: 0; font-size: var(--fs-lg); font-weight: 650; }
.ck-tile-title a { color: var(--text); }
.ck-tile-title a:hover { color: var(--brand); }
.ck-tile-extra { flex: none; max-width: 50%; font-size: var(--fs-xs); color: var(--text-muted); text-align: right; line-height: 1.3; }
.ck-tile-body { flex: 1 1 auto; min-width: 0; }
.ck-tile-link {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px; min-height: var(--tap); margin: 8px -16px 0; padding: 0 16px;
  border-top: 1px solid var(--border); font-size: var(--fs-sm); font-weight: 600; text-decoration: none !important;
}
.ck-tile-link:hover { background: var(--surface-2); }

.ck-headline-main { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.ck-headline-value { font-size: clamp(22px, 6.4vw, 28px); font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
@media (min-width: 720px) { .ck-headline-value { font-size: 26px; } }
.ck-headline-label { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.ck-headline-sub { font-size: var(--fs-sm); margin-top: 2px; }

.ck-facts { margin: 12px 0 0; display: flex; flex-direction: column; gap: 0; }
.ck-fact { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.ck-fact dt { color: var(--text-muted); font-weight: 600; min-width: 0; }
.ck-fact dt a { color: inherit; text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 2px; }
.ck-fact dd { margin: 0; display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; font-weight: 650; font-variant-numeric: tabular-nums; justify-content: flex-end; }

/* Zeilen (Deals, Kunden, Rechnungen, Verträge, Aufgaben) */
.ck-rows { list-style: none; margin: 0 -8px; padding: 0; }
.ck-row {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 8px; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none !important; min-width: 0;
}
a.ck-row:hover, .ck-row-bill a.ck-row-main:hover { background: var(--surface-2); }
.ck-rows > li + li { border-top: 1px solid var(--border); }
.ck-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; color: var(--text); text-decoration: none !important; }
.ck-row-title { font-weight: 600; overflow-wrap: anywhere; }
/* Titel höchstens zwei Zeilen (3 Spalten ab 1280 px sind schmal); voller Text im title der Zeile */
@supports (-webkit-line-clamp: 2) {
  .ck-row-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
}
.ck-row-sub { font-size: var(--fs-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.ck-row-num { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ck-row-num .ck-row-sub { font-weight: 500; white-space: nowrap; overflow-wrap: normal; }
.ck-row-icon { flex: none; color: var(--text-muted); }
.ck-row-due { flex: none; font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
/* überfällig: Datum rot (gleiche Spezifität wie .ck-tone-danger, das sonst von .ck-row-due überschrieben würde) */
.ck-row-due.ck-tone-danger { color: var(--danger); }
.ck-row-badge { flex: none; }
.ck-row-badge .vt-deadline { align-items: flex-end; }
/* Nicht verrechnet: Kunde (Link zum Bericht) | Betrag über «Abrechnen» */
.ck-bill { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main amount" "main btn"; align-items: center; gap: 2px 10px; padding: 8px; }
.ck-bill-main { grid-area: main; display: flex; flex-direction: column; gap: 2px; min-width: 0; align-self: stretch; justify-content: center;
  margin: -6px 0 -6px -6px; padding: 6px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none !important; }
.ck-bill-main:hover { background: var(--surface-2); }
.ck-bill-title { font-weight: 600; overflow-wrap: anywhere; }
.ck-bill-main .ck-row-sub { white-space: normal; }
.ck-bill-amount { grid-area: amount; justify-self: end; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ck-bill-btn, .ck-bill-none { grid-area: btn; justify-self: end; }

/* Fristen: Datum + Restzeit rechts, farbig nach Dringlichkeit */
.ck-when-danger { color: var(--danger); }
.ck-when-warning { color: var(--warning); }
.ck-when-danger .ck-row-sub, .ck-when-warning .ck-row-sub { color: inherit; font-weight: 600; }
.ck-when-icon { vertical-align: -1px; margin-right: 3px; }

/* Auslastung pro Person */
.ck-people { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.ck-person-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 5px; min-width: 0; }
.ck-person-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ck-person-num { flex: none; display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ck-person-sub { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: var(--fs-xs); color: var(--text); }

.ck-task-group + .ck-task-group { margin-top: 2px; }
.ck-task-overdue .ck-subtitle { color: var(--danger); }
.ck-empty-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* ------------------------------------------------------------------ Verträge: Liste */
.vt-page { gap: 14px; }
.vt-kpis .stat { min-width: 0; }
.vt-kpis .stat-value { font-size: clamp(17px, 5vw, 22px); overflow-wrap: anywhere; }
.vt-kpis .stat-sub { overflow-wrap: anywhere; }
.ck-stat-warning { border-color: var(--warning); background: var(--warning-soft); }
.ck-stat-warning .stat-value { color: var(--warning); }
.ck-stat-danger { border-color: var(--danger); background: var(--danger-soft); }
.ck-stat-danger .stat-value { color: var(--danger); }
.vt-filters { display: flex; flex-direction: column; gap: 10px; }
.vt-filter-row { display: flex; flex-direction: column; gap: 8px; }
.vt-filter-row .ad-search { flex: none; max-width: none; }
.vt-cat { width: 100%; }
@media (min-width: 900px) {
  .vt-filters { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .vt-filter-row { flex-direction: row; align-items: center; }
  .vt-cat { width: auto; min-width: 190px; }
  .vt-filter-row .ad-search { width: 260px; }
}

.vt-table-card { overflow: hidden; }
.vt-table { min-width: 720px; }
.vt-table td { vertical-align: middle; }
.vt-row { cursor: pointer; }
.vt-row.is-inactive .vt-title { color: var(--text-muted); }
.vt-title-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; margin: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; min-width: 0; }
.vt-title-btn:hover .vt-title { color: var(--brand); text-decoration: underline; }
.vt-title-text { display: flex; flex-direction: column; min-width: 0; }
.vt-title { font-weight: 600; overflow-wrap: anywhere; }
.vt-cat-icon { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand); }
.vt-party { overflow-wrap: anywhere; max-width: 240px; }
.vt-chev { width: 28px; padding-left: 0 !important; }

/* Nächste Frist (Badge + Restzeit) */
.vt-deadline { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; }
.vt-deadline .badge { font-variant-numeric: tabular-nums; }
.vt-deadline-type { font-weight: 500; }
.vt-deadline-type::after { content: ' '; }
.vt-deadline-left { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.vt-deadline-danger .vt-deadline-left { color: var(--danger); font-weight: 600; }
.vt-deadline-warning .vt-deadline-left { color: var(--warning); font-weight: 600; }

/* Karten am Handy */
.vt-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.vt-card { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 12px 14px; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.vt-card:hover { background: var(--surface-2); }
/* Fällig: farbiger Streifen links */
.vt-card-warning { box-shadow: inset 4px 0 0 var(--warning), var(--shadow-sm); }
.vt-card-danger { box-shadow: inset 4px 0 0 var(--danger), var(--shadow-sm); }
.vt-card.is-inactive { opacity: .8; }
.vt-card-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.vt-card-title { flex: 1 1 auto; min-width: 0; font-weight: 650; overflow-wrap: anywhere; }
.vt-card-sub { padding-left: 40px; overflow-wrap: anywhere; }
.vt-card-foot { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 6px 10px; padding-left: 40px; margin-top: 2px; }
.vt-card-foot .vt-deadline { align-items: flex-end; margin-left: auto; text-align: right; }
.vt-card-cost { font-variant-numeric: tabular-nums; }

.vt-cat-card .card-head { margin-bottom: 8px; }
.vt-cat-groups { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 28px; }
@media (min-width: 900px) { .vt-cat-groups:has(> :nth-child(2)) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.vt-cat-group .ck-subtitle { margin-top: 4px; }
.vt-cat-group .ck-bar-name .small { font-weight: 500; }

/* ------------------------------------------------------------------ Verträge: Modal */
.ck-modal .modal-body { display: flex; flex-direction: column; gap: 14px; }
.ck-modal-lead { margin: 0; }
.ck-form { gap: 16px; }
.ck-form-alert { margin-bottom: 2px; }
.ck-form-section { display: flex; flex-direction: column; gap: 12px; }
.ck-form-title { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.ck-docs { padding-top: 2px; }
.ck-toggle-row { display: flex; align-items: center; }
.ck-field-spacer { visibility: hidden; }
@media (max-width: 599px) { .ck-field-spacer { display: none; } }
.ck-notice, .ck-amount { display: flex; gap: 8px; min-width: 0; }
.ck-notice .input:first-child { flex: 1 1 80px; min-width: 0; }
.ck-notice select { flex: 1 1 120px; min-width: 0; }
.ck-amount .ck-currency { flex: 0 0 96px; }
.ck-amount .input:last-child { flex: 1 1 auto; min-width: 0; }
.ck-danger-btn { color: var(--danger); }
.ck-danger-btn:hover:not(:disabled) { background: var(--danger-soft); }

.ck-summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; margin: 0; padding: 4px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.ck-summary-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.ck-summary-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.ck-summary-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 2px 12px; padding: 7px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.ck-summary-row:first-child { border-top: 0; }
.ck-summary dt { color: var(--text-muted); font-weight: 600; }
.ck-summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.ck-summary dd .vt-deadline { align-items: flex-end; }
@media (min-width: 720px) {
  .ck-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
  .ck-summary-row:nth-child(2) { border-top: 0; }
}

/* Dokumente */
.ck-files { display: flex; flex-direction: column; gap: 10px; }
.ck-file-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.ck-file { display: flex; align-items: center; gap: 2px; padding: 0 6px 0 0; border-top: 1px solid var(--border); }
.ck-file:first-child { border-top: 0; }
.ck-file.is-queued { background: var(--surface-2); }
.ck-file-main { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 56px; padding: 6px 8px 6px 12px; color: var(--text); text-decoration: none !important; }
a.ck-file-main:hover { background: var(--surface-2); }
.ck-file-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--brand); }
.ck-file-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ck-file-name { font-weight: 600; overflow-wrap: anywhere; }
.ck-file-dl { color: var(--text-faint); }
.ck-file-busy { display: grid; place-items: center; width: var(--tap); height: var(--tap); }
.ck-file-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

/* ------------------------------------------------------------------ «Mehr» (Handy): Cockpit-Karte oben */
.ck-more-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; color: var(--text); text-decoration: none !important;
  background: linear-gradient(135deg, var(--brand-soft), var(--surface) 70%);
}
.ck-more-card:hover { background: var(--brand-soft); }
.ck-more-card .ck-tile-icon { width: 44px; height: 44px; background: var(--brand); color: var(--brand-contrast); }
.ck-more-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.ck-more-title { font-weight: 700; font-size: var(--fs-lg); }

/* ------------------------------------------------------------------ Touch-Ziele (Handy / Touch) */
@media (pointer: coarse), (max-width: 899px) {
  /* app.css: die Grundregel .input (min-height 42px) steht nach der Touch-Regel und gewinnt – hier ≥ 44 px erzwingen */
  .ck-page .input, .vt-page .input, .ck-modal .input, .ck-modal .picker { min-height: var(--tap); }
  .ck-toggle-row .toggle { min-height: var(--tap); }
  .ck-inline-link { min-height: var(--tap); display: inline-flex; align-items: center; }
  .ck-banner-item { min-height: var(--tap); }
  .ck-fact dt a { display: inline-flex; align-items: center; min-height: var(--tap); }
  .ck-tile-title a { display: inline-flex; align-items: center; min-height: var(--tap); }
  .ck-row { min-height: 52px; }
}

@media print {
  .ck-toolbar .segmented, .ck-bill-btn, .ck-tile-link, .ck-file-add { display: none !important; }
  .ck-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
