@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f8f9fb;
  --border: #e2e5ea;
  --border-strong: #c8cdd6;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --green-border: #bbf7d0;
  --red: #dc2626;
  --red-light: #fef2f2;
  --red-border: #fecaca;
  --yellow: #d97706;
  --yellow-light: #fffbeb;
  --yellow-border: #fde68a;
  --purple: #7c3aed;
  --purple-light: #faf5ff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 2px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.1), 0 2px 6px rgba(0,0,0,.06);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --font: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── LOGIN ────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 360px;
  box-shadow: var(--shadow-md), 0 20px 60px rgba(0,0,0,.2);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo .school-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 14px;
  margin-bottom: .75rem;
  font-size: 1.6rem;
}

.login-logo h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── APP SHELL ────────────────────────────── */
#app { display: none; height: 100vh; flex-direction: column; }

/* TOP NAV */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.topbar-brand .badge {
  font-size: .65rem;
  background: var(--primary);
  color: white;
  padding: .15rem .45rem;
  border-radius: 99px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.topbar-nav {
  display: flex;
  gap: .25rem;
  flex: 1;
  margin-left: .75rem;
}

.nav-btn {
  padding: .4rem .85rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
  position: relative;
}

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: .5rem;
  min-width: 150px;
  z-index: 500;
}
.user-dropdown.open { display: block; }
.user-dropdown-btn {
  width: 100%;
  text-align: left;
  padding: .5rem .75rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--red);
  font-family: var(--font);
  font-size: .875rem;
  border-radius: var(--radius-sm);
}
.user-dropdown-btn:hover { background: var(--red-light); }

.user-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--text-muted);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .75rem;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem;
}

/* ── VIEWS ────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── PAGE HEADER ──────────────────────────── */
.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.page-header .subtitle {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

.page-header-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── CARDS ────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── BUTTONS ──────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary-dark); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-success { background: var(--green); color: white; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger { background: var(--red); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-xs { padding: .2rem .5rem; font-size: .75rem; border-radius: 4px; }

.btn-icon { padding: .4rem; border-radius: var(--radius-sm); }

/* ── FORMS ────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .82rem; font-weight: 500; color: var(--text-muted); margin-bottom: .35rem; }
.form-control {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control::placeholder { color: var(--text-light); }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }

/* ── TABLE ────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead { background: var(--surface2); }
th { padding: .6rem .9rem; text-align: left; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ── WEEK GRID ────────────────────────────── */
.week-grid {
  display: grid;
  grid-template-columns: 120px repeat(5, 1fr);
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: .85rem;
}

.wg-header {
  background: var(--primary);
  color: white;
  padding: .6rem .75rem;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: center;
}
.wg-header:first-child { text-align: left; background: #1d4ed8; }

.wg-name {
  padding: .65rem .75rem;
  font-weight: 500;
  background: var(--surface2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.wg-cell {
  padding: .4rem .5rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  cursor: pointer;
  transition: background .1s;
  user-select: none;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wg-cell:hover { background: var(--primary-light); }
.wg-cell:last-child { border-right: none; }

.wg-cell.normal { background: var(--green-light); }
.wg-cell.lunch { background: var(--yellow-light); }
.wg-cell.late { background: var(--purple-light); }
.wg-cell.unavailable, .wg-cell.empty { background: var(--surface2); }

.wg-cell .cell-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.cell-normal { color: var(--green); }
.cell-lunch { color: var(--yellow); }
.cell-late { color: var(--purple); }

/* Readonly cells */
.wg-cell.readonly { cursor: default; }

/* ── LEGEND ───────────────────────────────── */
.legend {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
  font-size: .78rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  color: var(--text-muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

/* ── WEEK CARD ────────────────────────────── */
.week-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.week-card-header {
  padding: .9rem 1.25rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.week-card-header h3 { font-weight: 600; font-size: .95rem; }
.week-card-body { padding: 1.25rem; }

/* ── STATUS BADGES ────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-yellow { background: var(--yellow-light); color: var(--yellow); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-gray { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

/* ── MODAL ────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md), 0 20px 60px rgba(0,0,0,.3);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-weight: 600; font-size: 1rem; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }

/* ── ALERTS ───────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid var(--green-border); }
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid var(--red-border); }
.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary-border); }
.alert-warning { background: var(--yellow-light); color: var(--yellow); border: 1px solid var(--yellow-border); }

/* ── TOAST ────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  background: var(--text);
  color: white;
  padding: .7rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
  max-width: 320px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.warning { background: var(--yellow); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ── DIVIDER ──────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1.25rem 0; }

/* ── SPINNER ──────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner-dark { border-color: rgba(37,99,235,.2); border-top-color: var(--primary); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ──────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .4; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: .35rem; }
.empty-state p { font-size: .875rem; }

/* ── INVOICE PREVIEW ──────────────────────── */
.invoice-month-section { margin-bottom: 2rem; }
.invoice-month-title {
  font-weight: 700;
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--border);
}

/* ── SETTINGS ─────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 640px) {
  .settings-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .topbar-nav { display: none; }
  .main-content { padding: 1rem; }
  .week-grid { font-size: .75rem; }
}

/* ── PLAN OVERVIEW ────────────────────────── */
.plan-day-col {
  background: var(--primary);
  color: white;
  padding: .35rem .5rem;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.person-tag {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 500;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}
.person-tag.lunch { background: var(--yellow-light); color: var(--yellow); border-color: var(--yellow-border); }
.person-tag.late { background: var(--purple-light); color: var(--purple); border-color: #ddd6fe; }

/* ── TAB GROUP ────────────────────────────── */
.tab-group { display: flex; gap: .25rem; background: var(--bg); padding: .25rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; }
.tab-btn {
  flex: 1;
  padding: .4rem .75rem;
  border: none;
  border-radius: 5px;
  font-family: var(--font);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all .15s;
}
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ── SELECT WEEK DROPDOWN ─────────────────── */
.week-selector {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

/* Mobile nav */
.mobile-only { display: none; }
.mobile-nav { display: none; }
@media(max-width:640px) {
  .mobile-nav {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    height: 64px;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  }
  .mobile-nav .nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    border-radius: 0;
    gap: .2rem;
    color: var(--text-muted);
    overflow: hidden;
  }
  .mobile-nav .nav-btn .nav-icon { font-size: 1.3rem; line-height: 1; }
  .mobile-nav .nav-btn .nav-label { font-size: 0.65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .mobile-nav .nav-btn.active { color: var(--primary); background: var(--primary-light); }
  .main-content { padding-bottom: 80px; }

  .mobile-only { display: block; }

  /* Topbar auf Mobile: nur Logo + Badge + Avatar */
  .topbar { padding: 0 .75rem; }
  .topbar-brand span:not(.badge) { font-size: .85rem; }
  #user-display-name { display: none; }
  .topbar-right .btn-ghost { display: none; }
}
