:root {
  --bg: #edf1ea;
  --surface: #ffffff;
  --surface-soft: #f7f9f6;
  --ink: #1b2a27;
  --muted: #5a6c67;
  --brand: #0f766e;
  --brand-dark: #0a5b55;
  --accent: #c05621;
  --line: #d8e1dd;
  --ok: #1f7a3d;
  --warn: #b45309;
  --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, #f6efe4 0%, var(--bg) 35%);
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #143f3b, #1b5650);
  color: #e8f7f3;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.brand strong {
  display: block;
  font-size: 1.3rem;
}

.brand small {
  opacity: 0.75;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.menu a,
.menu-logout {
  text-decoration: none;
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  color: #e8f7f3;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
}

.menu a:hover,
.menu-logout:hover,
.menu a.active {
  background: rgba(255, 255, 255, 0.16);
}

.content-wrap {
  padding: 1rem 1.4rem 1.4rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.topbar h1 {
  margin: 0;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.session-chip {
  background: #d6ece9;
  color: #124640;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 30px rgba(14, 28, 24, 0.06);
}

.card h2 {
  margin: 0 0 0.6rem;
}

.muted {
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 0.8rem;
}

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

.four-cols {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select,
textarea,
button {
  width: 100%;
  border: 1px solid #c8d7d1;
  border-radius: 9px;
  padding: 0.58rem 0.65rem;
  font: inherit;
}

button {
  width: auto;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  min-width: 120px;
}

button:hover {
  background: var(--brand-dark);
}

button.secondary {
  background: var(--accent);
}

button.ghost {
  background: #d9e4df;
  color: #1b2a27;
}

.actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.upload-file-picker {
  position: relative;
}

.upload-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-file-label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: flex-start;
  min-height: 126px;
  padding: 1rem;
  border: 1px dashed #80a79e;
  border-radius: 14px;
  background: linear-gradient(180deg, #f5fbf9 0%, #eaf5f2 100%);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.upload-file-label:hover {
  border-color: #0f766e;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.12);
  transform: translateY(-1px);
}

.upload-file-input:focus + .upload-file-label,
.upload-file-input:focus-visible + .upload-file-label {
  outline: 2px solid rgba(15, 118, 110, 0.35);
  outline-offset: 2px;
  border-color: #0f766e;
}

.upload-file-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 170px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #0f766e 0%, #0b615a 100%);
  color: #ffffff;
  font-weight: 700;
}

.upload-file-name {
  font-size: 1rem;
  font-weight: 600;
  color: #123d38;
}

.upload-file-name.has-file {
  color: #0a5b55;
}

.upload-file-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.align-end {
  align-items: end;
}

.summary-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

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

.kpi-card {
  background: linear-gradient(180deg, #f7faf9 0%, #edf3f1 100%);
  border: 1px solid #d6e1dc;
  border-radius: 12px;
  padding: 0.85rem;
}

.kpi-card span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.kpi-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.25rem;
  color: #0f3d37;
}

.dashboard-grid-2col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.status-chart {
  display: grid;
  gap: 0.65rem;
}

.status-row {
  border: 1px solid #e3ece8;
  border-radius: 10px;
  padding: 0.6rem;
  background: #f9fcfb;
}

.status-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
}

.status-bar-track {
  height: 8px;
  border-radius: 999px;
  background: #dce8e3;
  overflow: hidden;
}

.status-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #1c8a7f, #3fa89e);
}

.project-volume-chart {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.project-volume-row {
  background: #f8fbfa;
  border: 1px solid #e3ece8;
  border-radius: 10px;
  padding: 0.5rem;
}

.project-volume-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.project-volume-head span {
  font-size: 0.85rem;
  color: var(--muted);
}

.project-volume-head strong {
  font-size: 0.92rem;
}

.project-volume-track {
  height: 9px;
  border-radius: 999px;
  overflow: hidden;
  background: #dce8e3;
}

.project-volume-fill {
  height: 100%;
  background: linear-gradient(90deg, #c05621, #e28a5a);
}

.receipt-thumb-button {
  border: 1px solid #d1dfda;
  border-radius: 10px;
  padding: 0.15rem;
  background: #f4f9f7;
  cursor: pointer;
  min-width: 0;
}

.receipt-thumb-button:hover {
  background: #e8f3ef;
}

.receipt-thumb {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
}

.receipt-preview-dialog {
  width: min(88vw, 980px);
  max-height: 90vh;
  border: 1px solid #d2dfda;
}

.receipt-preview-dialog::backdrop {
  background: rgba(16, 24, 22, 0.52);
}

.receipt-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.receipt-preview-stage {
  margin-top: 0.75rem;
  border: 1px solid #dbe7e2;
  border-radius: 12px;
  background: #f6faf8;
  max-height: 70vh;
  overflow: auto;
  padding: 0.6rem;
}

.receipt-preview-stage img {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 8px;
}

.period-picker {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid #dfe8e4;
}

.period-picker-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.period-groups {
  display: grid;
  gap: 0.65rem;
}

.status-quick-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.status-quick-button {
  min-width: 0;
  border: 1px solid #b8cbc5;
  background: #ffffff;
  color: #1b2a27;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.status-quick-button.active {
  background: #0f766e;
  border-color: #0f766e;
  color: #ffffff;
}

.period-group {
  border: 1px solid #dbe6e1;
  border-radius: 12px;
  background: #f8fbfa;
  padding: 0.6rem;
}

.period-months {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-top: 0.55rem;
}

.period-button {
  min-width: 0;
  border: 1px solid #b8cbc5;
  background: #ffffff;
  color: #1b2a27;
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

.period-button.year {
  font-weight: 600;
  background: #e9f4f1;
}

.period-button.month {
  font-size: 0.88rem;
}

.period-button.active {
  background: #0f766e;
  color: #ffffff;
  border-color: #0f766e;
}

.metric {
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 0.8rem;
}

.metric span {
  font-size: 0.82rem;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.1rem;
}

.table-wrap {
  overflow-x: auto;
}

.table-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.table-actions button,
.table-actions a {
  min-width: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.45rem;
  border-bottom: 1px solid #e4ebe8;
}

.status-badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  font-size: 0.75rem;
  background: #dbe4df;
}

/* Farbkonzept laut Testbericht - identisch zu app/core/expense_status.py.
   Aenderungen dort und hier muessen zusammenpassen (siehe test_expense_status.py). */
.status-DRAFT { background: #fdeed6; color: #8a4a05; }
.status-REJECTED { background: #fbdede; color: #8c1d1d; }
.status-SUBMITTED { background: #dcf0dd; color: #1b5e20; }
.status-IN_REVIEW { background: #dcf0dd; color: #1b5e20; }
.status-APPROVED { background: #e2e9ed; color: #40545e; }
.status-PAID { background: #eceeed; color: #5f6563; }

/* Farbbalken links am Listeneintrag; die Farbe kommt aus
   /api/meta/expense-statuses und wird als --status-color gesetzt. */
.expense-row > td:first-child {
  border-left: 4px solid var(--status-color, transparent);
}

/* Abgeschlossene Belege treten optisch zurueck. */
.expense-row.is-done {
  opacity: 0.55;
}

.expense-row.is-done:hover {
  opacity: 1;
}

.expense-row.needs-review > td:first-child {
  border-left-style: double;
  border-left-width: 6px;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.list-toolbar .actions {
  gap: 0.4rem;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.pager .muted {
  margin: 0;
}

.empty-state {
  padding: 1rem;
  border: 1px dashed #c9d8d3;
  border-radius: 10px;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

.audit-list {
  display: grid;
  gap: 0.5rem;
}

.audit-item {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e4ebe8;
}

.audit-entry {
  border: 1px solid #dce8e3;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.7rem;
  background: #fbfdfc;
}

.audit-entry-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.audit-entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 0.8rem;
  margin-bottom: 0.55rem;
}

.status-hint {
  border-radius: 10px;
  padding: 0.8rem;
  background: #f7f9f6;
}

.inline-note {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.button-loading {
  opacity: 0.75;
  cursor: wait;
}

.dialog-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  width: min(480px, 92vw);
}

.dialog-card::backdrop {
  background: rgba(8, 19, 16, 0.42);
}

.receipt-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 0.8rem;
  margin-bottom: 0.8rem;
}

.receipt-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  margin-bottom: 0.6rem;
}

.receipt-grid {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #1f453f;
  color: #fff;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  max-width: 320px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.toast.error {
  background: #8a1f1f;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .menu {
    flex-direction: row;
    overflow-x: auto;
  }

  .two-cols,
  .three-cols,
  .four-cols,
  .dashboard-grid-2col,
  .receipt-grid,
  .detail-grid,
  .audit-entry-grid {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
