/* ===================================================================
   Stundenplanung – Design System
   =================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-50: #eef0ff;
  --primary-rgb: 99, 102, 241;

  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-border: #86efac;

  --danger: #e11d48;
  --danger-bg: #ffe4e6;
  --danger-border: #fda4af;

  --warning: #d97706;
  --warning-bg: #fef3c7;

  --bg: #f4f5fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f8f9fd;
  --border: #e5e7f0;
  --border-strong: #d3d6e3;

  --text: #1e2233;
  --text-muted: #6b7086;
  --text-faint: #9498ab;

  --shadow-sm: 0 1px 2px rgba(30, 34, 51, 0.06);
  --shadow-md: 0 4px 16px rgba(30, 34, 51, 0.08);
  --shadow-lg: 0 12px 32px rgba(30, 34, 51, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #12131c;
  --bg-elevated: #181a26;
  --surface: #1b1d2a;
  --surface-alt: #20222f;
  --border: #2c2f42;
  --border-strong: #3a3d54;

  --text: #eef0fb;
  --text-muted: #a3a7c2;
  --text-faint: #6f7390;

  --primary-50: #24243f;
  --success-bg: #113222;
  --success-border: #1f7a44;
  --danger-bg: #3a1420;
  --danger-border: #a83250;
  --warning-bg: #3a2c0c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12131c;
    --bg-elevated: #181a26;
    --surface: #1b1d2a;
    --surface-alt: #20222f;
    --border: #2c2f42;
    --border-strong: #3a3d54;

    --text: #eef0fb;
    --text-muted: #a3a7c2;
    --text-faint: #6f7390;

    --primary-50: #24243f;
    --success-bg: #113222;
    --success-border: #1f7a44;
    --danger-bg: #3a1420;
    --danger-border: #a83250;
    --warning-bg: #3a2c0c;

    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

button, input, select, textarea { font: inherit; margin: 0; }
form { margin: 0; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; color: var(--text-muted); }

/* ---------------- Layout ---------------- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 64px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand, .brand:hover {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  white-space: nowrap;
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 4px rgba(255,255,255,.25);
}

.nav-links { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav-links a {
  color: rgba(255,255,255,.82);
  padding: .5rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.nav-links a:hover { background: rgba(255,255,255,.14); color: #fff; }
.nav-links a.active { background: rgba(255,255,255,.22); color: #fff; }

.topbar-right { display: flex; align-items: center; gap: .6rem; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  transition: background .15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,.28); color: #fff; }

.user-chip {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.14);
  padding: .35rem .7rem .35rem .4rem;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
}
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .78rem;
}
.role-badge {
  font-size: .68rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: rgba(255,255,255,.25);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.main {
  flex: 1;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header .subtitle { color: var(--text-muted); font-size: .92rem; margin-top: .15rem; }

/* ---------------- Cards ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card + .card { margin-top: 1.25rem; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
  align-items: stretch;
  gap: 1rem;
}
.grid-cards > .card { margin-top: 0; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { color: var(--text-muted); font-size: .85rem; font-weight: 600; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); color: var(--text); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), .35);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(var(--primary-rgb), .45); color: #fff; }

.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------------- Forms ---------------- */

label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .35rem; color: var(--text); }
.field { margin-bottom: 1rem; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 160px; }
.hint { color: var(--text-faint); font-size: .78rem; margin-top: .3rem; }

input[type=text], input[type=password], input[type=number], input[type=time],
input[type=email], input[type=search], select, textarea {
  width: 100%;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
select { color-scheme: inherit; }
select option { background-color: var(--surface); color: var(--text); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-50);
}
input[type=color] { width: 46px; height: 38px; padding: 2px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg-elevated); cursor: pointer; }

.checkbox-row { display: flex; align-items: center; gap: .5rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

form .actions { display: flex; align-items: center; gap: .6rem; margin-top: 1.25rem; }

/* ---------------- Tables ---------------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .75rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--text-muted); font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--surface-alt); }
.table-actions { display: flex; align-items: center; gap: .4rem; justify-content: flex-end; }
.table-actions form { display: inline-flex; margin: 0; }
.table-actions .btn { line-height: 1; white-space: nowrap; }

/* ---------------- Chips / Badges ---------------- */

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  color: #fff;
}
.chip-swatch { width: 9px; height: 9px; border-radius: 50%; background: #fff; opacity: .85; }
.badge { display: inline-flex; padding: .15rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--border); color: var(--text-muted); }

.diff-positive { color: var(--success); font-weight: 700; }
.diff-negative { color: var(--danger); font-weight: 700; }

/* ---------------- Flash messages ---------------- */

.flash-stack { position: fixed; top: 78px; right: 1.25rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; max-width: 340px; }
.flash {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: .87rem;
  font-weight: 600;
  animation: flash-in .2s ease;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }
.flash-info { background: var(--primary-50); color: var(--primary-dark); border-color: var(--primary-light); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------------- Login page ---------------- */

.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, var(--primary-dark), #12131c 60%);
  padding: 1rem;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
  border: 1px solid var(--border);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .dot { width: 46px; height: 46px; border-radius: 14px; margin: 0 auto .75rem; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 8px 20px rgba(var(--primary-rgb), .4); }
.login-logo h1 { font-size: 1.2rem; margin: 0; }
.login-logo p { margin: .2rem 0 0; font-size: .82rem; }

/* ---------------- Class switcher / toolbar ---------------- */

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.class-switcher { display: flex; align-items: center; gap: .6rem; }
.class-switcher .current-class {
  font-size: 1.15rem; font-weight: 800;
  padding: .4rem 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 140px; text-align: center;
}
.year-select { display: flex; align-items: center; gap: .5rem; }
.view-tabs { display: flex; gap: .3rem; background: var(--surface-alt); padding: .3rem; border-radius: var(--radius-md); border: 1px solid var(--border); }
.view-tabs a { padding: .4rem .85rem; border-radius: var(--radius-sm); font-size: .84rem; font-weight: 700; color: var(--text-muted); }
.view-tabs a:hover { color: var(--text); }
.view-tabs a.active, .view-tabs a.active:hover { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* ---------------- Timetable editor ---------------- */

.timetable-layout { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; align-items: start; }
@media (max-width: 980px) { .timetable-layout { grid-template-columns: 1fr; } }

.tt-grid-wrap { overflow-x: auto; }
.tt-grid {
  border-collapse: separate;
  border-spacing: 6px;
  width: 100%;
  min-width: 620px;
}
.tt-grid th {
  text-align: center;
  padding: .5rem;
  color: var(--text-muted);
  font-size: .78rem;
}
.tt-grid th.period-col { width: 64px; }
.tt-grid td.period-num {
  text-align: center;
  font-weight: 700;
  color: var(--text-faint);
  font-size: .8rem;
  vertical-align: top;
  padding-top: .6rem;
}
.tt-grid td.period-num .time { display: block; font-weight: 500; font-size: .68rem; color: var(--text-faint); }

.tt-cell {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 128px;
  min-height: 92px;
  padding: .45rem;
  vertical-align: top;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
  position: relative;
}
.tt-cell:hover { border-color: var(--primary-light); box-shadow: var(--shadow-sm); }
.tt-cell.disabled { background: repeating-linear-gradient(45deg, var(--surface-alt), var(--surface-alt) 8px, var(--bg) 8px, var(--bg) 16px); cursor: default; border-style: dashed; }
.tt-cell.disabled:hover { border-color: var(--border); box-shadow: none; }

.tt-cell.armed-free { border-color: var(--success-border); background: var(--success-bg); }
.tt-cell.armed-busy { border-color: var(--danger-border); background: var(--danger-bg); }
.tt-cell.armed-current { outline: 2px solid var(--primary); outline-offset: -2px; }

.tt-cell.filled-dim { opacity: .32; transition: opacity .12s ease; }
.tt-cell.filled-dim:hover { opacity: .75; }

.tt-cell.slot-picking { outline: 2px dashed var(--primary); outline-offset: -2px; }

.tt-slot-row { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .2rem; }
.tt-slot-row-subject { margin-top: 0; margin-bottom: .3rem; }
.tt-slot {
  font-size: .72rem; font-weight: 700; color: #fff;
  padding: .15rem .4rem; border-radius: 6px;
  display: inline-flex; align-items: center; gap: .25rem;
}
.tt-slot-subject { font-size: .8rem; padding: .25rem .5rem; }
.tt-slot .rm { cursor: pointer; opacity: .75; font-weight: 900; }
.tt-slot .rm:hover { opacity: 1; }
.tt-slot-placeholder {
  font-size: .72rem; color: var(--text-faint);
  border: 1px dashed var(--border-strong);
  padding: .15rem .4rem; border-radius: 6px;
  display: inline-block;
}

/* Sidebar picker */
.picker-panel { position: sticky; top: 80px; }
.picker-tabs { display: flex; gap: .3rem; background: var(--surface-alt); padding: .3rem; border-radius: var(--radius-md); border: 1px solid var(--border); margin-bottom: 1rem; }
.picker-tab {
  flex: 1;
  padding: .4rem .5rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .12s ease;
}
.picker-tab:hover { color: var(--text); }
.picker-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.picker-section { margin-bottom: 1.25rem; }
.picker-section h3 { display: flex; align-items: center; justify-content: space-between; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.picker-list { display: flex; flex-direction: column; gap: .4rem; max-height: 360px; overflow-y: auto; padding-right: 2px; }
.picker-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .5rem .65rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: .86rem;
  transition: all .12s ease;
}
.picker-item:hover { border-color: var(--primary-light); }
.picker-item.selected { border-color: var(--primary); background: var(--primary-50); box-shadow: 0 0 0 3px var(--primary-50); }

.picker-item.slot-current { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.picker-item.slot-busy, .picker-item.slot-over { cursor: default; opacity: .5; }
.picker-item.slot-busy:hover, .picker-item.slot-over:hover { border-color: var(--border); }
.picker-item.slot-busy { border-color: var(--danger-border); background: var(--danger-bg); }
.picker-item.slot-over { border-color: var(--warning); background: var(--warning-bg); }
.picker-swatch { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.picker-item .name { flex: 1; }
.picker-item .kbd { font-size: .68rem; color: var(--text-faint); }

.armed-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary-50); border: 1px solid var(--primary-light);
  color: var(--primary-dark); border-radius: var(--radius-sm);
  padding: .55rem .8rem; font-size: .82rem; font-weight: 700;
  margin-bottom: 1rem;
}
.armed-banner button { background: none; border: none; color: var(--primary-dark); cursor: pointer; font-weight: 800; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); margin-top: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

/* ---------------- Read-only plan grids (room/teacher) ---------------- */

.plan-grid { border-collapse: separate; border-spacing: 6px; width: 100%; min-width: 700px; }
.plan-grid th { text-align: center; padding: .5rem; color: var(--text-muted); font-size: .78rem; }
.plan-cell {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-md);
  min-width: 130px; min-height: 78px; padding: .5rem; vertical-align: top;
}
.plan-cell.empty { background: var(--surface-alt); border-style: dashed; }
.plan-cell .class-name { font-weight: 800; font-size: .88rem; }
.plan-cell .sub-line { font-size: .76rem; color: var(--text-muted); margin-top: .15rem; }

.summary-table-wrap { margin-top: 1.5rem; }

/* ---------------- Misc ---------------- */

.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }
.empty-state .big { font-size: 2.4rem; margin-bottom: .5rem; }

.divider { height: 1px; background: var(--border); margin: 1.25rem 0; border: none; }

.pill-select { display: inline-flex; align-items: center; gap: .4rem; }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Print / PDF export ---------------- */

.print-header { display: none; }

@media print {
  @page { size: landscape; margin: 8mm; }

  html { font-size: 12px; }

  :root, :root[data-theme="dark"] {
    --bg: #ffffff !important;
    --surface: #ffffff !important;
    --surface-alt: #f7f7f9 !important;
    --border: #d5d7e0 !important;
    --border-strong: #b9bcc9 !important;
    --text: #111318 !important;
    --text-muted: #4a4e60 !important;
    --text-faint: #767a8c !important;
    color-scheme: light !important;
  }

  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }

  .topbar, .flash-stack, .toolbar, .picker-panel, .armed-banner,
  .legend, #theme-toggle, .tt-slot .rm, .tt-slot-placeholder, .no-print {
    display: none !important;
  }

  html, body { height: auto; }
  .app-shell { min-height: 0; display: block; }
  body { background: #fff; }
  .main { max-width: none; width: 100%; padding: 0; margin: 0; }
  .timetable-layout { display: block; }
  .card { box-shadow: none; border: none; padding: 0; margin-top: 0 !important; }
  .card + .card { margin-top: 0; }
  .tt-grid-wrap { overflow: visible; }

  .print-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 2px solid var(--text);
    padding-bottom: .35rem;
    margin-bottom: .5rem;
  }
  .print-header h1 { font-size: 1.1rem; margin: 0; }
  .print-header .print-meta { font-size: .68rem; color: var(--text-muted); text-align: right; line-height: 1.3; }

  .tt-grid, .plan-grid {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    border-spacing: 2px;
  }
  .tt-grid th, .plan-grid th { padding: .2rem; font-size: .68rem; }
  .tt-grid th.period-col { width: 42px; }
  .tt-grid td.period-num, .plan-grid td.period-num { font-size: .68rem; padding-top: .15rem; }

  .tt-cell, .plan-cell {
    min-width: 0;
    height: auto;
    min-height: 0;
    padding: .2rem .3rem;
    border-width: 1px;
  }
  .tt-slot, .tt-slot-subject { font-size: .68rem; padding: .1rem .3rem; }
  .tt-slot-row { margin-top: .1rem; }
  .tt-slot-row-subject { margin-bottom: .15rem; }
  .plan-cell .class-name { font-size: .74rem; }
  .plan-cell .sub-line { font-size: .64rem; margin-top: .05rem; }

  tr { page-break-inside: avoid; }

  .summary-table-wrap { break-inside: avoid; margin-top: .5rem; }
  .summary-table-wrap h3 { font-size: .85rem; margin-bottom: .3rem; }
}
