@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600&display=swap');

:root {
  --bg: #f4efe6;
  --bg-alt: #f9f6f1;
  --card: #ffffff;
  --text: #1e1b18;
  --muted: #6d6256;
  --accent: #f2645a;
  --accent-dark: #d34b43;
  --shadow: 0 20px 40px rgba(40, 32, 24, 0.12);
  --radius: 18px;
  --pipi: #ffd166;
  --aa: #a97455;
  --essen: #70c1b3;
  --spiel: #7ea6e0;
  --training: #f4a259;
  --schlafen: #4a5b7c;
  --einschlafhilfe: #9db4b6;
  --aufwachen: #f89c74;
  --notiz: #b0b7c3;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, rgba(242, 100, 90, 0.12), transparent 60%),
    radial-gradient(circle at 20% 20%, rgba(112, 193, 179, 0.2), transparent 55%),
    linear-gradient(160deg, var(--bg), var(--bg-alt));
  min-height: 100vh;
}

.page-week {
  min-height: 100vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px 20px 10px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.brand-title {
  font-weight: 600;
}

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

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

.top-info {
  font-size: 0.9rem;
  background: rgba(242, 100, 90, 0.12);
  padding: 6px 12px;
  border-radius: 999px;
}

.ghost-button,
.ghost-link {
  border: 1px solid rgba(30, 27, 24, 0.15);
  background: rgba(255, 255, 255, 0.7);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
}

.ghost-button:hover,
.ghost-link:hover {
  border-color: rgba(30, 27, 24, 0.3);
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  animation: fadeUp 0.35s ease;
}

.hero-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-card h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.hero-card p {
  margin: 0;
  color: var(--muted);
}

.last-event {
  padding: 12px;
  border-radius: 14px;
  background: rgba(242, 100, 90, 0.08);
}

.last-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.last-value {
  font-weight: 600;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.sleep-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.event-button {
  border: none;
  padding: 16px;
  border-radius: 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.event-button:active {
  transform: scale(0.98);
}

.type-pipi { background: var(--pipi); color: #3b2f0b; }
.type-aa { background: var(--aa); }
.type-essen { background: var(--essen); color: #0f2d29; }
.type-spiel { background: var(--spiel); }
.type-training { background: var(--training); color: #3d2409; }
.type-einschlafhilfe { background: var(--einschlafhilfe); color: #1f2a2b; }
.type-schlafen { background: var(--schlafen); }
.type-aufwachen { background: var(--aufwachen); color: #3b1e0b; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  padding: 12px;
  border-radius: 14px;
  background: rgba(109, 98, 86, 0.08);
  cursor: pointer;
}

.history-item strong {
  display: block;
}

.history-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

textarea,
input[type="text"],
input[type="password"] {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(30, 27, 24, 0.15);
  padding: 12px;
  font-family: inherit;
  font-size: 1rem;
}

textarea {
  resize: vertical;
  min-height: 70px;
  margin: 10px 0 14px;
}

.primary-button {
  border: none;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(242, 100, 90, 0.28);
}

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

.danger-button {
  border: none;
  padding: 12px 18px;
  border-radius: 999px;
  background: #2f2a26;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.danger-button:hover {
  background: #1e1b18;
}

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

.small {
  font-size: 0.85rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 20, 16, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 30;
}

.hidden {
  display: none;
}

.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  width: min(420px, 95vw);
  box-shadow: var(--shadow);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.event-meta {
  margin: 8px 0 12px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 0.95;
}

.week-container {
  padding-bottom: 10px;
  min-height: 0;
}

.week-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.week-shell {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.time-column {
  width: 46px;
  font-size: 0.65rem;
  color: var(--muted);
  height: 1100px;
  display: flex;
  flex-direction: column;
}

.time-spacer {
  flex: 0 0 auto;
}

.time-scale {
  position: relative;
  flex: 1 1 auto;
}

.time-label {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  transform: translateY(-50%);
  pointer-events: none;
}

.week-range {
  font-weight: 600;
}

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
  height: 1100px;
}

.page-day .week-grid {
  grid-template-columns: minmax(0, 1fr);
}

.page-day .container {
  max-width: 1200px;
}

.page-day .week-shell,
.page-day .week-grid,
.page-day .day-column {
  width: 100%;
}

.day-column {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  overflow: hidden;
  min-width: 0;
  height: 100%;
}

.day-label {
  text-align: center;
  padding: 8px;
  font-size: 0.75rem;
  background: rgba(30, 27, 24, 0.05);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day-title {
  font-weight: 600;
}

.awake-info {
  font-size: 0.65rem;
  color: var(--muted);
}

.day-body {
  flex: 1;
  position: relative;
  height: 100%;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(30, 27, 24, 0.06) 0px,
    rgba(30, 27, 24, 0.06) 1px,
    transparent 1px,
    transparent calc(100% / 24)
  );
}

.event-marker {
  position: absolute;
  left: 12%;
  width: 76%;
  height: 18px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: #1e1b18;
  cursor: pointer;
  z-index: 3;
}

.event-marker.type-pipi { color: #8a6a13; }
.event-marker.type-aa { color: #6b3f25; }
.event-marker.type-essen { color: #2f6f64; }
.event-marker.type-spiel { color: #3f5e8f; }
.event-marker.type-training { color: #9a5b1a; }
.event-marker.type-aufwachen { color: #b05a2e; }
.event-marker.type-notiz { color: #4c5668; }

.duration-bar {
  position: absolute;
  left: 18%;
  width: 64%;
  border-radius: 12px;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.duration-bar.type-schlafen {
  background: rgba(74, 91, 124, 0.7);
  color: #fff;
}

.duration-bar.type-einschlafhilfe {
  background: rgba(157, 180, 182, 0.8);
  color: #1f2a2b;
}

.login-container {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 95vw);
}

.login-error {
  margin-top: 10px;
  color: #b42318;
  font-weight: 600;
}

@media (min-width: 720px) {
  .button-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .hero-card {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

@media (max-width: 680px) {
  .time-column {
    width: 32px;
    font-size: 0.55rem;
  }
  .week-grid {
    font-size: 0.6rem;
  }
  .event-marker {
    font-size: 0.55rem;
  }
}

@keyframes fadeUp {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
