:root {
  --bg: #f3efe6;
  --bg-accent: #e7edf2;
  --ink: #1c2430;
  --muted: #5c6b7a;
  --line: #d5dbe3;
  --panel: rgba(255, 255, 255, 0.82);
  --brand: #0f4c5c;
  --brand-2: #e36414;
  --ok: #1b7f4c;
  --err: #a11d33;
  --shadow: 0 18px 40px rgba(28, 36, 48, 0.08);
  --radius: 14px;
  --font: "Avenir Next", "Segoe UI", "Helvetica Neue", sans-serif;
  --display: Georgia, "Times New Roman", serif;
  --status-planung: #94a3b8;
  --status-arbeit: #f59e0b;
  --status-freigabe: #ec4899;
  --status-frei: #22c55e;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #dce8ef 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #f7d9c4 0%, transparent 50%),
    linear-gradient(180deg, var(--bg), var(--bg-accent));
  line-height: 1.45;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(243, 239, 230, 0.85);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0.85rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem;
}
.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--brand);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--ink); font-weight: 500; }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.92rem; }

.main { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.main-auth {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-family: var(--display); margin: 0.2rem 0 0.6rem; font-size: 2rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; color: var(--brand-2); font-weight: 700; margin: 0; }

.page-head {
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start;
  margin-bottom: 1.25rem;
}
.page-head h1, .panel h2, .auth-card h1 { font-family: var(--display); }
.page-head h1 { margin: 0.15rem 0; font-size: 2rem; }
.lead { color: var(--muted); margin: 0.25rem 0 0; }
.breadcrumb { margin: 0; color: var(--muted); font-size: 0.9rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.meta-row { display: flex; flex-wrap: wrap; gap: 0.85rem 1.25rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}
.panel-wide { max-width: 860px; }
.issue-meta { max-width: none; }
.issue-meta-form { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
.issue-header { flex-wrap: wrap; }
.issue-summary { flex: 1; width: 100%; min-width: 0; max-width: 100%; }
.issue-settings { margin-top: 0.75rem; }
.issue-settings summary { list-style: none; }
.issue-settings summary::-webkit-details-marker { display: none; }
.issue-settings summary::after { content: "▾"; margin-left: 0.5rem; }
.issue-settings[open] summary::after { transform: rotate(180deg); }
.issue-settings-panel {
  margin-top: 0.65rem; padding: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel);
}
.panel-head-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.panel-head-row h2 { margin: 0; }
.grid-2 {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem;
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

.stack { display: grid; gap: 0.85rem; }
label { display: grid; gap: 0.35rem; font-weight: 560; font-size: 0.92rem; }
input, select, textarea, button {
  font: inherit; color: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: #fff;
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 0.55rem; font-weight: 500; }
.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  background: #fff;
}
.btn:hover { text-decoration: none; filter: brightness(0.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { background: #fff; color: var(--err); border-color: #f0c2ca; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.88rem; }
.issue-archive { padding: 0.85rem 1rem; font-size: 0.82rem; }
.issue-archive h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.issue-archive label, .issue-archive .btn { font-size: inherit; }
.issue-archive .btn { padding: 0.35rem 0.75rem; }
.issue-archive details { margin-top: 0.75rem; }
.issue-archive summary { color: var(--muted); cursor: pointer; }
.issue-archive input:not([type="checkbox"]) { padding: 0.45rem 0.6rem; }
.inline { display: inline; }

.flash {
  border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 1rem; font-weight: 500;
}
.flash-success { background: #e5f6ec; color: var(--ok); }
.flash-error { background: #fde8ec; color: var(--err); }

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { text-align: left; padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.issue-articles { border-collapse: separate; border-spacing: 0; }
.issue-articles thead th {
  position: sticky; top: var(--table-top-offset, 4.5rem); z-index: 10;
  background: #f8f6f0; box-shadow: 0 1px 0 var(--line);
}
/* Cover the band above a stuck header too, including browser rounding/gaps. */
.issue-articles.filters-stuck thead th::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 100%;
  height: var(--table-top-offset, 4.5rem); background: #f8f6f0;
}

.table-tools th[data-col] {
  vertical-align: bottom;
  min-width: 7.5rem;
}
.table-tools .th-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0 0 0.35rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.table-tools .th-sort:hover { color: var(--brand); }
.table-tools th[aria-sort] .th-sort { color: var(--brand); }
.table-tools .sort-ind {
  display: inline-block;
  min-width: 0.85em;
  margin-left: 0.2rem;
  color: var(--brand);
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1;
}
.table-tools .th-filter {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.table-tools .th-filter:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 35%, white);
  outline-offset: 1px;
}

.material-panel { margin-top: 1rem; }
.material-panel h2 { margin-top: 0; }
.material-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 0.85rem;
}
@media (max-width: 1100px) {
  .material-grid { grid-template-columns: 1fr; }
}
.material-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem 1rem;
  background: rgba(255, 255, 255, 0.55);
}
.material-block h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}
.file-list {
  list-style: none;
  margin: 0.65rem 0 0.85rem;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}
.file-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.file-meta { display: grid; gap: 0.15rem; min-width: 0; }
.file-meta strong {
  overflow-wrap: anywhere;
}
.file-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.file-upload-form {
  display: flex;
  gap: 0.55rem;
  align-items: end;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}
.file-upload-label {
  flex: 1;
  min-width: 12rem;
  font-weight: 560;
  font-size: 0.88rem;
}
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list a { display: block; padding: 0.85rem 0.15rem; color: inherit; text-decoration: none; }
.list a:hover { background: rgba(15, 76, 92, 0.04); }
.list .meta { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }
.rubrik-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.55rem 0.1rem;
}
.rubrik-add { max-width: 28rem; margin-top: 1rem; }
.rubrik-field { display: flex; flex-direction: column; gap: 0.45rem; }
.rubrik-field select { margin-bottom: 0; }

.badge {
  display: inline-block; margin-left: 0.35rem;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  background: #e8eef1; color: var(--brand); padding: 0.15rem 0.4rem; border-radius: 999px;
}
.badge-std { background: #fff1e6; color: var(--brand-2); }
.pill {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  background: #eef2f5; font-size: 0.8rem; font-weight: 600;
}
.pill.status-planung { background: color-mix(in srgb, var(--status-planung) 28%, white); }
.pill.status-arbeit { background: color-mix(in srgb, var(--status-arbeit) 28%, white); }
.pill.status-freigabe { background: color-mix(in srgb, var(--status-freigabe) 25%, white); }
.pill.status-frei { background: color-mix(in srgb, var(--status-frei) 28%, white); }

.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.hint { color: var(--muted); font-size: 0.88rem; margin-top: 1.25rem; }
.nowrap { white-space: nowrap; }
.row-planung { background: rgba(15, 76, 92, 0.03); }

.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

/* Blattplanung */
.blatt-chrome {
  flex-shrink: 0;
}
.legend {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.1rem; align-items: center;
  margin-bottom: 1rem; color: var(--muted); font-size: 0.9rem;
}
.legend-title { font-weight: 700; color: var(--ink); }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend-item i {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
}
.legend-item i.status-planung { background: var(--status-planung); }
.legend-item i.status-arbeit { background: var(--status-arbeit); }
.legend-item i.status-freigabe { background: var(--status-freigabe); }
.legend-item i.status-frei { background: var(--status-frei); }

.blatt-head .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
#blatt-refresh-previews:disabled {
  opacity: 0.65;
  cursor: wait;
}
.blatt-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin-left: auto;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}
.blatt-progress[hidden] { display: none !important; }
.blatt-progress-spinner {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid color-mix(in srgb, var(--brand) 25%, white);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: blatt-spin 0.7s linear infinite;
}
.blatt-progress-count { color: var(--muted); font-weight: 500; }
.blatt-progress-bar {
  width: 4.5rem;
  height: 0.35rem;
  border-radius: 999px;
  background: #e8eef1;
  overflow: hidden;
}
.blatt-progress-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width 0.2s ease;
}
@keyframes blatt-spin {
  to { transform: rotate(360deg); }
}
body.page-blattplan.blatt-busy {
  cursor: progress;
}

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

/* Fix topbar + chrome (through Layout-Status); only plan content scrolls */
body.page-blattplan {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.page-blattplan .topbar {
  position: static;
  flex-shrink: 0;
}
body.page-blattplan .main {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 1rem;
}
body.page-blattplan .blatt-layout {
  flex: 1;
  min-height: 0;
  overflow: auto;
  align-items: stretch;
  padding-bottom: 0.5rem;
}
body.page-blattplan .pool {
  position: sticky;
  top: 0;
  max-height: 100%;
  overflow: auto;
}
body.page-blattplan .spreads {
  min-height: min-content;
}
@media (max-width: 980px) {
  body.page-blattplan .pool {
    position: static;
    max-height: none;
  }
}

.pool { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.pool-list { display: grid; gap: 0.55rem; margin-top: 0.75rem; }
.pool-item {
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  background: #fff;
  cursor: grab;
  user-select: none;
}
.pool-item.status-planung { border-left-color: var(--status-planung); }
.pool-item.status-arbeit { border-left-color: var(--status-arbeit); }
.pool-item.status-freigabe { border-left-color: var(--status-freigabe); }
.pool-item.status-frei { border-left-color: var(--status-frei); }
.pool-item.dragging { opacity: 0.45; }
.pool-item { cursor: grab; }
.pool-item:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.pool-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  padding: 1.25rem;
  background: rgba(16, 24, 32, 0.48);
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none !important; }
.modal-dialog {
  width: min(720px, 100%);
  max-height: min(90vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(16, 24, 32, 0.28);
  padding: 1rem 1.15rem 1.15rem;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: 0.85rem;
}
.modal-head h2 { margin: 0; font-size: 1.25rem; }
.modal-close { font-size: 1.4rem; line-height: 1; padding: 0.15rem 0.45rem; }
.modal-form { margin-top: 0.25rem; }
.modal-error { color: #b42318; margin: 0; }
.pool-item-top, .pool-item-meta {
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
  font-size: 0.78rem; color: var(--muted);
}
.pool-item strong { display: block; margin: 0.2rem 0; font-size: 0.95rem; }
.unplaced { color: var(--brand-2); font-weight: 600; }
.placed { font-weight: 600; }

.spreads {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.1rem 0.9rem;
  padding: 0.5rem 0 2rem;
}
.spread {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-height: 180px;
}
.page-slot { display: flex; flex-direction: column; align-items: stretch; min-width: 0; }
.page-slot.side-left { align-items: flex-end; }
.page-slot.side-right { align-items: flex-start; }
.page-empty .page-phantom {
  width: 100%; height: 160px; border: 1px dashed transparent;
}
.page-label-top {
  font-size: 0.72rem; color: var(--muted); font-weight: 600;
  margin-bottom: 0.25rem; min-height: 1em; text-align: center; width: 100%;
}
.page {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  min-height: 150px;
  background: #e5e7eb;
  border: 1px solid #cbd5e1;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 8px 18px rgba(28, 36, 48, 0.08);
}
.page.drag-over { outline: 2px solid var(--brand); outline-offset: 2px; }
.page-drop {
  position: absolute; left: 0; right: 0; z-index: 2;
}
.half-top { top: 0; height: 50%; }
.half-bottom { top: 50%; height: 50%; }
.page-drop.drag-over { background: rgba(15, 76, 92, 0.12); }
.page-number {
  margin-top: 0.3rem; font-size: 0.85rem; font-weight: 700; color: var(--ink); text-align: center; width: 100%;
}
.page-article {
  position: absolute; left: 0; right: 0; z-index: 3;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8% 6% 4%;
  cursor: grab;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  overflow: hidden;
}
.page-article.has-preview {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  flex-direction: column;
}
.page-article-preview {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #fff;
  pointer-events: none;
  overflow: hidden;
}
.page-article-thumb {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: top center;
  background: #fff;
  pointer-events: none;
}
.page-article-thumb.thumb-failed {
  background:
    repeating-linear-gradient(
      -45deg,
      #f8fafc,
      #f8fafc 8px,
      #eef2f6 8px,
      #eef2f6 16px
    );
}
.page-article-empty {
  position: absolute;
  inset: auto 0 0.55rem 0;
  z-index: 0;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.page-article-box {
  position: relative;
  z-index: 1;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,0.2);
  padding: 0.35rem 0.45rem;
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.25;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.page-article.has-preview .page-article-box {
  margin: auto 6% 6%;
  width: auto;
  align-self: center;
  background: rgba(255,255,255,0.94);
}
.page-article-box .tiny {
  display: block; color: var(--muted); font-size: 0.65rem; margin-bottom: 0.15rem;
}
.page-article-box strong { font-size: 0.75rem; }
.page.has-layout-preview {
  background: #f8fafc;
}
.legend-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

code { background: #eee; padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.9em; }

.article-page-header {
  position: sticky; top: var(--article-toolbar-top, 4rem); z-index: 19;
  background: #f3efe6; border: 1px solid var(--line); border-radius: 10px;
  padding: 0.75rem; margin-bottom: 1rem;
  box-shadow: 0 5px 14px rgba(28, 36, 48, 0.08);
}
.article-page-header .page-head { margin: 0 0 0.75rem; }
.article-page-header h1 { overflow-wrap: anywhere; }
.article-page-header .breadcrumb { margin: 0 0 0.5rem; }
.article-navigation-hint { margin: 0.45rem 0 0; font-size: 0.8rem; }
.article-navigation button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
#article-edit-form input, #article-edit-form select, #article-edit-form textarea {
  scroll-margin-top: calc(var(--article-toolbar-offset, 10rem) + 1rem);
}
