/**
 * App shell: layout, header, filters, cards, buttons, badges, alerts.
 * Requires tokens.css. Does not style the sidebar (app-sidebar.css).
 */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

body.app-sidebar-ready .main {
  margin-left: var(--sidebar-w);
}

/* ?? Header ?? */
.header {
  min-height: var(--header-h);
  height: auto;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 16px;
}

.header-title {
  font-size: var(--text-page-title);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--gray-800);
}

.header-subtitle {
  font-size: var(--text-subtitle);
  color: var(--gray-400);
  margin-top: 3px;
}

/* Underline sub-tabs (LifeTime-style) */
.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 20px;
  border-bottom: 1px solid var(--gray-200);
  background: transparent;
}

.page-tab,
.monat-tab-btn {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-radius: 0;
  white-space: nowrap;
}

.page-tab:hover,
.monat-tab-btn:hover {
  color: var(--blue);
}

.page-tab.active,
.monat-tab-btn.active {
  color: var(--blue);
  font-weight: 600;
  border-bottom-color: var(--blue);
  background: transparent;
}

.monat-tab-btn--ausserhalb {
  color: #92400e;
  border-bottom-style: dashed;
}

.monat-tab-btn--ausserhalb.active {
  color: #92400e;
  border-bottom-color: var(--warning);
  background: transparent;
}

.monat-tabs-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gray-200);
}

.monat-filter-hint {
  font-size: 12px;
  color: #92400e;
  background: var(--warning-bg);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}

/* Soft info strip above lists */
.list-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--blue-light);
  border: 1px solid rgba(37, 99, 168, 0.18);
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 500;
}

.list-banner svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--blue);
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--gray-400);
  margin: 8px 0 12px;
}

/* Compact metric strip (replaces crowded KPI card rows) */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow: hidden;
}

.metric-strip-item {
  padding: 18px 22px;
  border-right: 1px solid var(--gray-100);
}

.metric-strip-item:last-child {
  border-right: none;
}

.metric-strip-item .stat-label {
  margin-bottom: 6px;
}

.metric-strip-item .stat-value {
  font-size: 22px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

/* ?? Content ?? */
.content {
  padding: 24px 28px 40px;
}

.content--narrow {
  max-width: 1280px;
}

/**
 * Page workspace � one large white surface on gray canvas.
 * Strongest visual difference vs. legacy pages (floating cards only).
 */
.page-workspace {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 28px 32px 32px;
  min-height: calc(100vh - 96px);
}

.page-workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.page-workspace-head .header-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.page-workspace-head .header-subtitle {
  font-size: 14px;
  color: var(--gray-400);
  margin-top: 6px;
}

.main--workspace {
  background: #eef1f6;
}

.main--workspace > .header {
  background: #eef1f6;
  border-bottom: none;
  min-height: 56px;
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Filters inside workspace: muted inset, not a second white card */
.page-workspace .filter-bar,
.page-workspace .toolbar {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  box-shadow: none;
  margin-bottom: 4px;
  border-radius: 12px;
}

/* Nested cards quieter inside workspace */
.page-workspace .card,
.page-workspace .stat-card,
.page-workspace .hero-bs,
.page-workspace .metric-strip,
.page-workspace .table-panel {
  box-shadow: none;
}

.page-workspace .stat-card:not(.primary):not(.highlight):not(.success):not(.warning):not(.error):not(.fehler):not(.warnung):not(.ok),
.page-workspace .hero-bs,
.page-workspace .metric-strip,
.page-workspace .card {
  background: var(--gray-50);
  border-color: var(--gray-200);
}

.page-workspace .stat-card.primary,
.page-workspace .stat-card.highlight,
.page-workspace .kpi.highlight {
  background: var(--blue-light);
}

.page-workspace .table-panel {
  background: var(--white);
  border: 1px solid var(--gray-200);
}

.page-workspace .data-table thead th {
  background: var(--gray-50);
}

/* ?? Filter / toolbar ?? */
.filter-bar,
.toolbar {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  gap: 12px 16px;
  align-items: flex-end;
  margin-bottom: 8px;
  box-shadow: none;
  flex-wrap: wrap;
}

.filter-group,
.filter-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 160px;
}

.filter-label,
.filter-select-wrap label {
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-select,
.filter-select-wrap select,
.search-input {
  padding: 8px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
  min-width: 160px;
}

.filter-select:focus,
.filter-select-wrap select:focus,
.search-input:focus {
  outline: none;
  border-color: var(--blue);
}

.filter-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--gray-400);
  align-self: center;
}

.search-wrap {
  flex: 1 1 220px;
  min-width: 180px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--gray-400);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--white);
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--blue);
}

/* ?? Buttons ?? */
.btn,
.btn-link {
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
}

.btn-primary,
.btn-link {
  background: var(--blue);
  color: var(--white);
}

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

.btn-secondary,
.btn-link.secondary,
.filter-reset {
  background: var(--white);
  color: var(--gray-600);
  border: 1.5px solid var(--gray-200);
}

.btn-secondary:hover,
.btn-link.secondary:hover,
.filter-reset:hover {
  background: var(--gray-50);
  color: var(--gray-800);
}

.filter-reset {
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-sm,
.btn-table {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--blue-mid);
  background: var(--blue-light);
  color: var(--blue);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-table:hover:not(:disabled) {
  background: #dce8f8;
}

.btn-table:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.is-busy {
  cursor: progress;
  pointer-events: none;
}

.btn.is-busy:hover {
  cursor: progress;
}

.btn-primary.is-busy:hover {
  background: var(--blue);
}

.btn-primary.is-busy:disabled {
  opacity: 0.85;
  cursor: progress;
}

.btn.is-busy > svg {
  display: none;
}

.btn.is-busy::before {
  content: '';
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  flex-shrink: 0;
  animation: kvdt-btn-spin 0.7s linear infinite;
}

.btn-primary.is-busy::before {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: var(--white);
}

@keyframes kvdt-btn-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn.is-busy::before {
    animation: none;
    border-top-color: currentColor;
    opacity: 0.55;
  }

  .btn-primary.is-busy::before {
    border-top-color: var(--white);
  }
}

.modal-overlay.is-busy {
  cursor: progress;
}

html.kvdt-page-busy,
html.kvdt-page-busy * {
  cursor: wait !important;
}

.loading-state::before {
  content: '';
  display: block;
  width: 22px;
  height: 22px;
  margin: 0 auto 12px;
  box-sizing: border-box;
  border: 2px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: kvdt-btn-spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .loading-state::before {
    animation: none;
    opacity: 0.55;
  }
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  background: var(--white);
  text-decoration: none;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
}

.icon-btn svg {
  width: 14px;
  height: 14px;
}

/* ?? Cards & KPIs ?? */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head,
.card-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: var(--text-card-title);
  font-weight: 600;
}

.card-sub,
.card-subtitle {
  font-size: var(--text-card-sub);
  color: var(--gray-400);
  margin-top: 2px;
}

.card-body {
  padding: 18px 22px;
}

.stats-grid,
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 14px;
  margin-bottom: 22px;
  align-items: stretch;
}

.stats-grid.stats-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card-body > .stats-grid,
.card-body > .kpi-grid {
  margin-bottom: 0;
}

.stat-card,
.kpi {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: var(--stat-card-min-h, 120px);
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.stat-label,
.kpi-label {
  font-size: var(--text-label);
  font-weight: 600;
  color: var(--gray-400);
  letter-spacing: 0.3px;
  margin-bottom: 8px;
  text-transform: uppercase;
  line-height: 1.3;
  max-height: calc(1.3em * 2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.stat-value,
.kpi-value {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-width: 0;
  font-size: clamp(18px, 1.7vw, 24px);
  font-weight: 600;
  line-height: 1.15;
  color: var(--gray-800);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub,
.kpi-sub {
  font-size: 11px;
  color: var(--gray-400);
  margin-top: 6px;
  line-height: 1.35;
  min-height: calc(1.35em * 2);
  max-height: calc(1.35em * 2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.stat-hint {
  font-size: 10px;
  color: var(--gray-400);
  margin-top: 6px;
  line-height: 1.45;
}

.stat-card > .btn,
.kpi > .btn {
  margin-top: 10px;
  align-self: flex-start;
  flex-shrink: 0;
}

.stat-card.primary,
.stat-card.highlight,
.kpi.highlight {
  background: var(--blue-light);
  border-color: rgba(37, 99, 168, 0.2);
}

.stat-card.primary .stat-value,
.stat-card.highlight .stat-value,
.kpi.highlight .kpi-value,
.kpi.highlight .stat-value {
  color: var(--blue);
}

.stat-card.success,
.kpi.ok {
  background: var(--success-bg);
  border-color: var(--success-border);
}

.stat-card.success .stat-value,
.kpi.ok .kpi-value {
  color: var(--success);
}

.stat-card.warning,
.kpi.warnung {
  background: var(--warning-bg);
  border-color: rgba(217, 119, 6, 0.28);
}

.stat-card.warning .stat-value,
.kpi.warnung .kpi-value {
  color: var(--warning);
}

.stat-card.error,
.kpi.fehler {
  background: var(--error-bg);
  border-color: rgba(220, 38, 38, 0.28);
}

.stat-card.error .stat-value,
.kpi.fehler .kpi-value {
  color: var(--error);
}

@media (max-width: 1100px) {
  .stats-grid,
  .kpi-grid,
  .page-workspace .stats-grid,
  .page-workspace .kpi-grid,
  .page-workspace .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .stats-grid,
  .kpi-grid,
  .page-workspace .stats-grid,
  .page-workspace .kpi-grid,
  .page-workspace .kpi-row,
  .stats-grid.stats-grid--2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

.trend-up {
  color: var(--success);
}

.trend-down {
  color: var(--error);
}

/* ?? Status pills ?? */
.status-badge,
.status-pill,
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-green,
.status-pill--success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-gray,
.status-pill--neutral {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-blue,
.status-pill--info {
  background: var(--info-bg);
  color: var(--info);
}

.badge-orange,
.status-pill--warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.badge-red,
.status-pill--danger {
  background: var(--error-bg);
  color: var(--error);
}

.badge-purple,
.status-pill--purple {
  background: #f5f3ff;
  color: #7c3aed;
}

/* Upload status aliases (kvdt-uebersicht) */
.status-NEU {
  background: var(--success-bg);
  color: var(--success);
}
.status-VERARBEITUNG {
  background: var(--info-bg);
  color: #3b82f6;
}
.status-BEWERTET,
.status-KONTIERT {
  background: var(--success-bg);
  color: var(--success);
}
.status-EXPORTIERT {
  background: #f5f3ff;
  color: #7c3aed;
}
.status-FEHLER {
  background: var(--error-bg);
  color: var(--error);
}

/* ?? Alerts & empty ?? */
.page-alert {
  display: none;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #fecaca;
}

.page-alert.show {
  display: block;
}

.page-alert.info {
  background: var(--info-bg);
  color: var(--info);
  border-color: #bfdbfe;
}

.page-alert.success {
  background: var(--success-bg);
  color: var(--success);
  border-color: #bbf7d0;
}

.empty,
.empty-hint,
.loading {
  padding: 40px 24px;
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
}

.empty-hint a {
  color: var(--blue);
  font-weight: 600;
}

.link-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--blue);
  background: var(--blue-light);
  text-decoration: none;
  border: 1px solid rgba(37, 99, 168, 0.15);
}

.link-chip:hover {
  background: #dce8f8;
}

.links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
