:root {
  --bg: #f1f2f6;
  --card-bg: #ffffff;
  --text: #14161f;
  --text-muted: #6b7080;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef0fe;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --border: #e7e8ee;
  --green: #059669;
  --green-light: #ecfdf5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1rem 0;
}

.app-header h1 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  flex: none;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  background: #f3f4f8;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.4rem 0.55rem;
  border: none;
  background: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn svg {
  width: 1.15rem;
  height: 1.15rem;
}

.tab-btn.active {
  color: var(--primary);
  background: var(--card-bg);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 3rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select {
  font-size: 1rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-variant-numeric: tabular-nums;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.rate-details {
  margin: 0.5rem 0 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
}

.rate-details summary {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.rate-details .field {
  margin-top: 0.9rem;
}

.breakdown h2 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  font-weight: 700;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.breakdown-row.total {
  border-top: 1px solid var(--border);
  margin-top: 0.4rem;
  padding-top: 0.65rem;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--green);
}

.actions {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.btn {
  flex: 1;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn.primary:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

.btn.danger {
  background: var(--danger-light);
  color: var(--danger);
  flex: 0 0 auto;
}

.btn.danger:active {
  transform: scale(0.98);
}

.btn.icon {
  flex: 0 0 auto;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.btn.icon svg {
  width: 1.1rem;
  height: 1.1rem;
}

.btn.icon:active {
  transform: scale(0.94);
}

.hidden {
  display: none !important;
}

.status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--green);
}

.status.error {
  color: var(--danger);
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.period-switch {
  display: flex;
  gap: 0.25rem;
  background: #f3f4f8;
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 0.8rem;
}

.period-btn {
  flex: 1;
  padding: 0.55rem;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.period-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.period-label {
  font-weight: 700;
  font-size: 1.02rem;
  text-align: center;
  flex: 1;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.summary-row.total {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--green);
  padding-top: 0.6rem;
}

.summary-card hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0;
}

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

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

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.08s ease;
}

.entry-item:active {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: scale(0.99);
}

.entry-item .entry-date {
  font-weight: 700;
  font-size: 0.9rem;
}

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

.entry-item .entry-total {
  font-weight: 800;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.entry-item.muted {
  opacity: 0.55;
}

.entry-item .entry-total.muted-amount {
  color: var(--text-muted);
}

h2 {
  color: var(--text);
}

/* Kalender (Monatsansicht) */

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.35rem;
}

.calendar-day {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  cursor: pointer;
  background: #fff;
  padding: 0.2rem;
  transition: transform 0.08s ease, border-color 0.15s ease;
}

.calendar-day:active {
  transform: scale(0.94);
}

.calendar-day.is-pad {
  visibility: hidden;
  pointer-events: none;
  border: none;
}

.calendar-day .day-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.calendar-day.has-entry {
  background: var(--primary-light);
  border-color: var(--primary);
}

.calendar-day.has-entry .day-num {
  color: var(--primary);
}

.calendar-day .day-amount {
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.calendar-day.is-today {
  box-shadow: 0 0 0 2px var(--primary);
}

/* Tages-Detail-Dialog */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  position: relative;
  background: #fff;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 1.25rem 1.25rem 1.5rem;
  animation: slide-up 0.2s ease;
  box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.2);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 0.85rem;
}

.modal-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: #f3f4f8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-close svg {
  width: 1rem;
  height: 1rem;
}

#day-modal-date {
  margin: 0 0 0.8rem;
  font-size: 1.1rem;
  font-weight: 800;
  padding-right: 2rem;
}

.day-modal-note {
  margin: -0.4rem 0 0.9rem;
  font-style: italic;
}

@keyframes slide-up {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (min-width: 700px) {
  #app {
    max-width: 760px;
    padding: 1.5rem;
  }

  .card {
    padding: 1.5rem;
  }

  .tabs {
    max-width: 480px;
    margin: 0 auto;
  }

  .app-header h1 {
    justify-content: center;
  }

  .modal-overlay {
    align-items: center;
  }

  .modal-sheet {
    border-radius: 20px;
    animation: fade-in 0.2s ease;
  }
}

/* Login-Seite */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.login-header h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
}

.login-card .btn.primary {
  width: 100%;
  margin-top: 0.4rem;
}

/* Rechenweg-Link + Dialog */

.calc-link {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 0.8rem;
  padding: 0.5rem;
  border: none;
  background: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.calc-link:active {
  opacity: 0.7;
}

.calc-body {
  font-size: 0.9rem;
}

.calc-section {
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--border);
}

.calc-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.calc-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.calc-step {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin: 0.1rem 0;
  font-variant-numeric: tabular-nums;
}

.calc-step strong {
  color: var(--text);
  font-weight: 600;
}

.calc-day-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.84rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.calc-day-row:last-child {
  border-bottom: none;
}

.calc-day-row .calc-day-meta {
  color: var(--text-muted);
}

.calc-total-line {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  color: var(--green);
}
