/* ===== Grundlagen & Farbpalette ===== */
:root {
  --color-bg: #f5f6f7;
  --color-surface: #ffffff;
  --color-border: #e0e2e5;
  --color-text: #23272b;
  --color-text-muted: #6b7178;
  --color-accent: #2c6e8f;
  --color-accent-dark: #204f68;
  --color-danger: #b3452c;
  --color-income: #2f7a4d;
  --color-expense: #b3452c;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

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

h1, h2, h3 {
  font-weight: 600;
  color: var(--color-text);
}

h2 {
  margin-top: 0;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.5rem;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.logo-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  border: 0px dashed var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: 0.7rem;
}

.logo-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

/* ===== Layout ===== */
.app-layout {
  display: flex;
  min-height: calc(100vh - 73px);
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.nav-btn {
  background: none;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

.nav-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.nav-btn.active {
  border-left-color: var(--color-accent);
  color: var(--color-accent-dark);
  font-weight: 600;
  background: var(--color-bg);
}

.content {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1200px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.hint {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: -0.5rem;
}

/* ===== Dashboard cards ===== */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 600;
}

.card-upnext {
  grid-column: span 2;
}

.upnext-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upnext-item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.9rem;
}

.upnext-date {
  font-weight: 600;
  color: var(--color-accent-dark);
  white-space: nowrap;
}

.upnext-title {
  color: var(--color-text);
}

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

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 0.6rem 0.9rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-weight: 600;
  white-space: nowrap;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

tbody td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--color-bg);
}

.amount-positive {
  color: var(--color-income);
  font-weight: 600;
}

.amount-negative {
  color: var(--color-expense);
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-einnahme {
  background: #e4f3e9;
  color: var(--color-income);
}

.badge-ausgabe {
  background: #f6e7e2;
  color: var(--color-expense);
}

/* ===== Forms ===== */
.entry-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

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

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* .form-grid label's `display: flex` above outranks the UA default
   [hidden]{display:none} at equal specificity - same issue as
   .auth-gate[hidden] elsewhere in this file - so it needs its own
   override or applyRoleVisibility()'s el.hidden = true has no effect. */
.form-grid label[hidden] {
  display: none;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

/* .hint's negative margin-top (below) is meant to pull a hint up snug
   under the input right above it - but a <form class="form-grid"> whose
   last child is a full-width submit button has no such buffer, so the
   hint right after the form ends up overlapping the button instead. */
form.form-grid {
  margin-bottom: 0.5rem;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 0.9rem;
}

input, select, textarea {
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-accent);
}

.receipt-preview {
  margin-top: 0.4rem;
}

.receipt-preview img {
  max-height: 80px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.75rem;
}

button {
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
}

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

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

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

.btn-secondary:hover {
  background: var(--color-bg);
}

.btn-danger {
  background: none;
  border: none;
  color: var(--color-danger);
  padding: 0.2rem 0.4rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-accent);
  padding: 0.2rem 0.4rem;
}

.row-actions {
  display: flex;
  gap: 0.3rem;
  white-space: nowrap;
}

/* ===== Filter bar ===== */
.filter-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* ===== Bilanz ===== */
.balance-columns {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.balance-column {
  flex: 1;
  min-width: 300px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.balance-table {
  width: 100%;
}

.balance-table td {
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.balance-table input {
  width: 100px;
  text-align: right;
}

.balance-value {
  text-align: right;
  font-weight: 600;
}

.balance-total td {
  border-top: 2px solid var(--color-border);
  border-bottom: none;
  font-weight: 700;
}

/* ===== Settings ===== */
.category-list {
  list-style: none;
  padding: 0;
  max-width: 420px;
}

.category-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
}

.category-list li input {
  flex: 1;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  max-width: 420px;
  margin-bottom: 1.5rem;
}

.inline-form input {
  flex: 1;
}

#page-einstellungen h3 {
  margin-top: 1.5rem;
}

/* ===== Anmeldung / Session-Auswahl ===== */
.auth-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  padding: 1.5rem;
  z-index: 100;
  overflow-y: auto;
}

/* Author CSS with an explicit `display` beats the UA default
   `[hidden] { display: none }` at equal specificity, so without this the
   overlay never actually disappears when JS sets .hidden = true. */
.auth-gate[hidden] {
  display: none;
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 440px;
}

.auth-card h1 {
  margin-top: 0;
}

.membership-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.membership-item .role-tag {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-left: 0.4rem;
}

/* ===== Session-Banner ===== */
.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.session-banner-actions {
  display: flex;
  gap: 1rem;
  white-space: nowrap;
}

/* ===== Genehmigungsstatus ===== */
.badge-pending {
  background: #fbf0d9;
  color: #8a6116;
}

.badge-approved {
  background: #e4f3e9;
  color: var(--color-income);
}

.badge-rejected {
  background: #f6e7e2;
  color: var(--color-expense);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .nav-btn {
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }

  .nav-btn.active {
    border-left-color: transparent;
    border-bottom-color: var(--color-accent);
  }

  .content {
    padding: 1rem;
  }
}

/* ===== Beleg-Vollansicht ===== */
.beleg-thumb {
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  padding: 1.5rem;
  z-index: 200;
}

/* Same reason as .auth-gate[hidden] above: an explicit `display` here
   beats the UA default [hidden]{display:none} at equal specificity. */
.lightbox[hidden] {
  display: none;
}

.lightbox-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-width: min(90vw, 900px);
  max-height: 90vh;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: var(--radius);
  background: var(--color-surface);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: -0.75rem;
  right: -0.75rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: var(--color-surface);
  cursor: pointer;
  box-shadow: var(--shadow);
  padding: 0;
}

/* Drawn from two crossed bars instead of an "x"/"times" glyph - a text
   character's ink doesn't actually sit in the center of its own box (it
   varies by font/rendering), so it always looked slightly off-center
   against the perfectly centered circle. This centers exactly instead. */
.lightbox-close::before,
.lightbox-close::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.9rem;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
}

.lightbox-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.lightbox-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
