:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #283548;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.16);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --ai-bg: linear-gradient(135deg, rgba(37, 99, 235, 0.15) 0%, rgba(124, 58, 237, 0.15) 100%);
  --ai-border: rgba(99, 102, 241, 0.45);
  --ai-title: #93c5fd;
  --kpi-warn-bg: rgba(245, 158, 11, 0.1);
  --kpi-warn-border: rgba(245, 158, 11, 0.35);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

body.light {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ai-bg: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
  --ai-border: #c7d2fe;
  --ai-title: #1e40af;
  --kpi-warn-bg: #fffaf5;
  --kpi-warn-border: #fed7aa;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 16px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Nav Pills & Views */
.nav-pills {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.nav-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-pill:hover {
  color: var(--text);
}

.nav-pill.active {
  background: var(--primary);
  color: #fff;
}

.main-views {
  display: block;
}

.form-page-card {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 28px;
}

.form-actions-bar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.form-actions-bar .btn {
  min-width: 200px;
  padding: 10px 20px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.req {
  color: var(--danger);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.time-helper {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 12px;
}

.time-helper summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.time-helper-row {
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 10px;
}

.time-helper-row .form-group {
  margin-bottom: 0;
}

.live-total {
  padding: 8px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  text-align: right;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-alt);
  border-color: #cbd5e1;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
  padding: 10px 16px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 6px;
  border-radius: 6px;
}

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

/* KPIs */
.content-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.muted {
  color: var(--text-muted);
  font-weight: 400;
}

.input-with-btn {
  display: flex;
  gap: 6px;
  align-items: center;
}

.input-with-btn input {
  flex: 1;
}

.work-items-list {
  list-style: none;
  margin: 6px 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.work-item-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
}

.work-items-inline {
  margin: 4px 0 0 16px;
  padding: 0;
  font-size: 0.79rem;
  color: var(--text-muted);
}

.customer-db-form {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 14px;
}

.customer-form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cust-search-wrap {
  margin-bottom: 10px;
}

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

/* KI Preiskalkulation */
.ai-calc-box {
  background: var(--ai-bg);
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}

.ai-calc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ai-title);
  margin-bottom: 8px;
}

.ai-result-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--ai-border);
  font-size: 0.84rem;
}

.ai-summary {
  margin: 0 0 8px 0;
  color: var(--text);
}

.ai-preview-list {
  margin: 0 0 8px 16px;
  padding: 0;
  color: var(--text-muted);
}

.ai-error {
  color: var(--danger);
  font-weight: 600;
}

/* Line Items (Posten) */
.line-items-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.line-item-row {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 1.8fr 1.6fr;
  gap: 8px;
  align-items: center;
}

.line-item-top {
  display: flex;
  gap: 6px;
  align-items: center;
}

.line-item-top input {
  flex: 1;
}

.line-item-nums {
  display: grid;
  grid-template-columns: 0.85fr 0.9fr 1fr auto;
  gap: 6px;
  align-items: center;
}

@media (max-width: 720px) {
  .line-item-row {
    grid-template-columns: 1fr;
  }
}

.line-item-total {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  text-align: right;
  white-space: nowrap;
  min-width: 68px;
}

.line-items-table-list {
  margin: 4px 0 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.78rem;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-highlight {
  border-color: var(--kpi-warn-border);
  background: var(--kpi-warn-bg);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Filters */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.filter-search {
  flex: 1 1 200px;
}

.filter-item select {
  min-width: 140px;
}

.filter-dates {
  display: flex;
  align-items: center;
  gap: 4px;
}

.filter-dates input {
  width: 135px;
}

/* Table */
.table-wrap {
  overflow-x: auto;
}

.entries-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.entries-table th {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.entries-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.entries-table tbody tr:hover {
  background: var(--surface-alt);
}

.entries-table th.num,
.entries-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.entries-table td.exp-cell {
  white-space: normal;
  max-width: 240px;
  min-width: 110px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.entries-table td.exp-cell .activity-note {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: normal;
  line-height: 1.35;
}

.activity-cell {
  max-width: 440px;
  min-width: 220px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.activity-cell .activity-title {
  font-weight: 600;
  white-space: normal;
}

.activity-cell .activity-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: normal;
}

.line-items-table-list,
.work-items-inline {
  margin: 4px 0 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.79rem;
  color: var(--text-muted);
}

.line-items-table-list li,
.work-items-inline li {
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.4;
  margin-bottom: 2px;
}

.status-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.status-offen {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-abgerechnet {
  background: var(--info-soft);
  color: var(--info);
}

.status-bezahlt {
  background: var(--success-soft);
  color: var(--success);
}

.actions-col {
  text-align: right;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
}

/* Modals */
dialog.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
  width: min(680px, 95vw);
  max-height: 90vh;
  background: var(--surface);
  color: var(--text);
}

dialog.modal-lg {
  width: min(900px, 96vw);
}

dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(90vh - 60px);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 12px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.inline-form {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 1.4fr 1.2fr auto;
  gap: 8px;
  margin-bottom: 16px;
}

@media (max-width: 680px) {
  .inline-form {
    grid-template-columns: 1fr;
  }
}

.customers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.customer-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.customer-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.file-label {
  cursor: pointer;
}

/* Invoice Preview */
.invoice-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.invoice-controls select {
  width: auto;
  min-width: 170px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: 0.82rem;
  cursor: pointer;
}

.invoice-paper {
  padding: 36px 40px;
  background: #fff;
  color: #111827;
  overflow-y: auto;
  max-height: calc(90vh - 70px);
}

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 2px solid #e5e7eb;
}

.inv-company {
  font-size: 0.85rem;
  color: #4b5563;
  white-space: pre-line;
}

.inv-company strong {
  font-size: 1.05rem;
  color: #111827;
}

.inv-meta {
  text-align: right;
  font-size: 0.85rem;
}

.inv-meta h2 {
  margin: 0 0 6px 0;
  font-size: 1.4rem;
  color: #111827;
}

.inv-customer {
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.88rem;
}

.inv-table th {
  text-align: left;
  padding: 8px;
  border-bottom: 2px solid #111827;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.inv-table td {
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
}

.inv-table th.num,
.inv-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-totals {
  margin-left: auto;
  width: min(320px, 100%);
  font-size: 0.9rem;
}

.inv-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
}

.inv-totals-row.grand {
  border-top: 2px solid #111827;
  margin-top: 6px;
  padding-top: 8px;
  font-size: 1.05rem;
  font-weight: 700;
}

.inv-footer {
  margin-top: 32px;
  padding-top: 14px;
  border-top: 1px solid #e5e7eb;
  font-size: 0.82rem;
  color: #4b5563;
}

/* Print Rules */
@media print {
  body {
    background: #fff;
  }

  .no-print {
    display: none !important;
  }

  dialog#modal-invoice {
    position: static;
    border: none;
    box-shadow: none;
    width: 100%;
    max-width: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
  }

  .invoice-paper {
    padding: 0;
    max-height: none;
    overflow: visible;
  }
}
