:root {
  --navy: #003b6f;
  --blue: #1267e8;
  --yellow: #f5bf00;
  --bg: #f4f7fb;
  --line: #dfe6ef;
  --text: #12233f;
  --muted: #68758a;
  --green: #21a35b;
  --danger: #c93838;
}

* { box-sizing: border-box; }

/* Muss vor den Layoutregeln stehen: eigene display-Angaben (etwa flex oder grid)
   überstimmen sonst die Standardregel des Browsers für [hidden]. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }

/* --- Grundgerüst --- */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 254px 1fr; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 254px;
  background: linear-gradient(180deg, #00345f 0%, #003f73 65%, #002f58 100%);
  color: #fff;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 10px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
}
.brand-block strong { display: block; font-size: 18px; letter-spacing: .35px; }
.brand-block span { display: block; font-size: 12px; color: #dce9f7; margin-top: 3px; }

.text-link.danger, .btn-link.danger { color: var(--danger); }

.menu-label { font-size: 11px; color: #9ebbd6; margin: 26px 10px 8px; }
.side-nav { display: flex; flex-direction: column; gap: 5px; }

.side-link {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  border: 0; background: transparent; color: #fff;
  padding: 12px 14px; border-radius: 7px;
  text-align: left; font-size: 15px; cursor: pointer;
}
.side-link span { width: 20px; text-align: center; font-size: 18px; }
.side-link:hover { background: rgba(255, 255, 255, .08); }
.side-link.active { background: rgba(255, 255, 255, .12); color: #ffd43b; font-weight: 700; }

.sidebar-foot {
  margin-top: auto;
  padding: 18px 10px 0;
  border-top: 1px solid rgba(255, 255, 255, .14);
  line-height: 1.6;
}
.sidebar-foot small { color: #c7d8e8; }

.main-shell { grid-column: 2; min-width: 0; }

.topbar {
  height: 68px; background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center;
  padding: 0 30px;
  position: sticky; top: 0; z-index: 100;
}
.top-title { font-size: 20px; font-weight: 800; color: #0b315c; }
#status-indicator { margin-left: auto; color: var(--muted); font-size: 13px; }
#status-indicator.error { color: var(--danger); font-weight: 700; }

.content-page { padding: 26px 30px 90px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head h1 { margin: 0 0 5px; font-size: 25px; color: #0b315c; }
.page-head p { margin: 0; color: var(--muted); }

/* --- Kacheln und Panels --- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }

.kpi, .panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(20, 45, 75, .05);
}
.kpi { padding: 20px; display: flex; align-items: center; gap: 16px; min-height: 112px; }
.kpi-icon { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-size: 25px; }
.kpi-icon.blue { background: #e8f1ff; color: var(--blue); }
.kpi-icon.yellow { background: #fff5d8; color: #d99f00; }
.kpi-icon.green { background: #e3f7ec; color: var(--green); }
.kpi span, .kpi small { display: block; color: var(--muted); }
.kpi strong { display: block; font-size: 29px; line-height: 1.1; margin: 5px 0; color: #0d2442; }

.panel { padding: 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel h2, .panel-head h2 { font-size: 17px; margin: 0; color: #0b315c; }

/* --- Bedienelemente --- */
.btn-primary, .btn-secondary, .btn-danger {
  border: 0; border-radius: 5px;
  padding: 10px 15px;
  font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #0759cd; }
.btn-primary:disabled { background: #9aa8bb; cursor: not-allowed; }
.btn-secondary { background: #fff; border: 1px solid #cbd5e1; color: #26364c; }
.btn-secondary:disabled { color: #9aa8bb; cursor: not-allowed; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.text-link, .btn-link { border: 0; background: transparent; color: var(--blue); cursor: pointer; padding: 0; }
.button-group { display: flex; gap: 10px; flex-wrap: wrap; }

input[type=text], input[type=number], input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 96px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: 190px 1fr; gap: 13px 16px; align-items: center; max-width: 760px; }
.form-grid label { font-weight: 700; text-align: right; }
.form-panel { max-width: 900px; }

/* --- Tabellen --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #e6ebf2; vertical-align: middle; }
th { font-size: 12px; color: #536176; font-weight: 800; }
td .btn-link { margin-right: 10px; }

.badge { display: inline-block; padding: 4px 9px; border-radius: 999px; background: #e9f1ff; color: #0f5ec7; font-size: 12px; font-weight: 700; }
.badge.grey { background: #eef1f5; color: #5d6b80; }

.state { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; }
.state::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #c2cbd8; }
.state.online { color: var(--green); }
.state.online::before { background: var(--green); }
.state.offline { color: var(--muted); }

/* --- Medienraster --- */
.media-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.media-toolbar .spacer { margin-left: auto; }

.dropzone {
  border: 2px dashed #b9c7d9;
  border-radius: 9px;
  background: #fff;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 18px;
}
.dropzone.dragover { border-color: var(--blue); background: #eef5ff; color: var(--blue); }
.dropzone strong { display: block; color: #0b315c; font-size: 16px; margin-bottom: 4px; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }

.media-card {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.media-card.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(18, 103, 232, .18); }
.media-card .preview { height: 118px; background: #0d1b2c; display: grid; place-items: center; }
.media-card .preview img, .media-card .preview video { width: 100%; height: 100%; object-fit: cover; }
.media-card .preview .kind { color: #8fa6c0; font-size: 30px; }
.media-card .body { padding: 10px 11px; display: grid; gap: 6px; }
.media-card .body strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-card .body small { color: var(--muted); }
.media-card .row { display: flex; align-items: center; gap: 8px 12px; justify-content: space-between; flex-wrap: wrap; }
.media-card .select-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.bulk-bar {
  position: sticky; bottom: 0;
  background: #0b315c; color: #fff;
  border-radius: 8px;
  padding: 13px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 16px;
}
.bulk-bar strong { color: var(--yellow); }
.bulk-bar .spacer { margin-left: auto; }

/* --- Playlist-Editor --- */
.editor-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.editor-columns { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }

.library { max-height: 70vh; overflow: auto; display: grid; gap: 9px; }
.library-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.library-item img { width: 52px; height: 38px; object-fit: cover; border-radius: 4px; background: #0d1b2c; }
.library-item .meta { min-width: 0; flex: 1; }
.library-item .meta strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-item .meta small { color: var(--muted); }

.slot-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.slot-tab { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 9px 13px; cursor: pointer; font-weight: 700; color: #35485f; }
.slot-tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }

.slot-settings { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.slot-settings label { font-weight: 700; }
.slot-settings select { width: auto; min-width: 170px; }

.playlist { display: grid; gap: 10px; min-height: 90px; }

.playlist-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 11px;
  display: grid;
  grid-template-columns: 26px 62px 1fr auto;
  gap: 12px;
  align-items: center;
}
.playlist-item.dragging { opacity: .45; }
.playlist-item.drop-target { border-color: var(--blue); box-shadow: 0 -2px 0 var(--blue); }
.playlist-item .handle { cursor: grab; color: #98a6ba; font-size: 19px; text-align: center; user-select: none; }
.playlist-item .thumb { width: 62px; height: 44px; object-fit: cover; border-radius: 4px; background: #0d1b2c; }
.playlist-item .thumb-html { width: 62px; height: 44px; border-radius: 4px; background: #0d1b2c; color: #8fa6c0; display: grid; place-items: center; font-size: 19px; }
.playlist-item .info { min-width: 0; }
.playlist-item .info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.playlist-item .info small { color: var(--muted); }
.playlist-item .controls { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.playlist-item .controls input[type=number] { width: 92px; }

.schedule-row { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding-top: 11px; display: grid; gap: 10px; }
.schedule-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.schedule-fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 700; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: #35485f; }

.empty-hint { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 7px; }

.publish-bar {
  position: fixed; left: 254px; right: 0; bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 12px 30px;
  display: flex; gap: 10px; align-items: center;
  z-index: 90;
  box-shadow: 0 -2px 8px rgba(20, 45, 75, .08);
}
.publish-bar .spacer { margin-left: auto; color: var(--muted); }

/* --- Dialoge --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 24, 48, .62);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  width: min(640px, 94vw);
  max-height: 88vh; overflow: auto;
  background: #fff; border-radius: 9px;
  padding: 24px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .24);
}
.modal h3 { margin-top: 0; color: #0b315c; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.check-list { max-height: 42vh; overflow: auto; background: #f5f7fa; padding: 12px; border: 1px solid var(--line); border-radius: 6px; display: grid; gap: 8px; }
.check-list label { display: flex; align-items: center; gap: 9px; }

.shop-group { border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 9px 11px; display: grid; gap: 7px; }
.shop-head { padding-bottom: 7px; border-bottom: 1px solid var(--line); }
.shop-head small { color: var(--muted); }
.shop-child { padding-left: 22px; }

#upload-progress { width: 100%; }

/* --- Anpassung an kleine Fenster --- */
@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-columns { grid-template-columns: 1fr; }
  .library { max-height: 320px; }
  .schedule-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: relative; width: 100%; height: auto; }
  .main-shell { grid-column: auto; }
  .kpi-grid { grid-template-columns: 1fr; }
  .content-page { padding: 20px 15px 90px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label { text-align: left; }
  .publish-bar { left: 0; }
  .playlist-item { grid-template-columns: 26px 62px 1fr; }
  .playlist-item .controls { grid-column: 1 / -1; justify-content: flex-start; }
}

/* --- Anmeldung --- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #00345f 0%, #003f73 60%, #002f58 100%);
  padding: 20px;
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border-radius: 11px;
  padding: 32px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .28);
}
.login-card h1 { margin: 0; font-size: 24px; color: #0b315c; }
.login-sub { margin: 4px 0 24px; color: var(--muted); }
.login-form { display: grid; gap: 7px; }
.login-form label { font-weight: 700; margin-top: 8px; }
.login-form button { margin-top: 18px; }
.login-error { margin: 12px 0 0; color: var(--danger); font-weight: 700; }
.login-hint { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.6; }

/* --- Seitenleiste unten --- */
.sidebar-setup { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .14); }
.sidebar-foot { margin-top: 14px; }
.sidebar-foot #current-user { color: #fff; font-weight: 700; font-size: 13px; }
.sidebar-foot .btn-link { color: #ffd43b; font-size: 13px; margin: 4px 0 10px; }

/* --- Filter und Sortierung --- */
.filter-bar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 14px; margin-bottom: 14px;
}
.filter-bar input[type=text] { width: auto; min-width: 230px; flex: 1 1 230px; }
.filter-bar select { width: auto; min-width: 140px; }
.filter-bar .spacer { margin-left: auto; }
.filter-bar.compact { margin: 12px 0 0; padding: 10px; }

table.sortable th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
table.sortable th[data-sort]:hover { color: var(--blue); }
table.sortable th[data-sort]::after { content: " ⇅"; opacity: .3; font-size: 11px; }
table.sortable th.sorted { color: var(--blue); }
table.sortable th.sorted[data-dir="asc"]::after { content: " ↑"; opacity: 1; }
table.sortable th.sorted[data-dir="desc"]::after { content: " ↓"; opacity: 1; }

/* --- Setup --- */
.permission-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
/* text-align und font-weight kommen sonst von .form-grid label. */
.permission-grid label { display: flex; align-items: center; gap: 8px; font-weight: 400; text-align: left; }
.permission-grid.disabled { opacity: .5; }

.inline-field { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-field select { width: auto; min-width: 190px; }
.inline-field small { color: var(--muted); }

small.warn { color: #b26a00; font-weight: 700; }
small.err { color: var(--danger); font-weight: 700; }
