:root {
  --bg: #f4f6f7;
  --panel: #ffffff;
  --ink: #101820;
  --muted: #6b7a85;
  --line: #e2e8eb;
  --teal: #12a594;
  --teal-dark: #0d7f72;
  --amber: #e8a317;
  --red: #d94141;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 8px 24px rgba(16, 24, 32, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Space Grotesk', 'Inter', sans-serif; margin: 0; }
code, .mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

button { font: inherit; cursor: pointer; }

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

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

.login-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px;
  width: min(400px, 100%);
  text-align: center;
}

.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 22px; }

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  margin-bottom: 12px;
}

/* --------------------------------------------------------------- Grundlayout */

.app { display: none; min-height: 100vh; }
.app.ready { display: grid; grid-template-columns: 236px 1fr; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--ink); color: var(--amber);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.brand strong { font-family: 'Space Grotesk', sans-serif; font-size: 15px; display: block; line-height: 1.2; }
.brand span { font-size: 11px; color: var(--muted); }

.side-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600; margin-bottom: 8px;
}

.screen-list { display: flex; flex-direction: column; gap: 4px; }

.screen-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 11px; border-radius: 9px;
  border: 1px solid transparent; background: none;
  text-align: left; width: 100%; font-size: 14px; color: var(--ink);
}
.screen-item:hover { background: #eef2f3; }
.screen-item.active { background: rgba(18, 165, 148, .1); border-color: rgba(18, 165, 148, .3); color: var(--teal-dark); font-weight: 600; }
.screen-item small { color: var(--muted); font-size: 11px; font-weight: 400; }

.nav-tabs { display: flex; flex-direction: column; gap: 4px; }
.nav-tab {
  padding: 9px 11px; border-radius: 9px; border: none; background: none;
  text-align: left; font-size: 14px; color: var(--ink);
}
.nav-tab:hover { background: #eef2f3; }
.nav-tab.active { background: var(--ink); color: #fff; }

.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); }

/* -------------------------------------------------------------------- Main */

main { padding: 22px 26px 60px; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.topbar h2 { font-size: 20px; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 9px 15px; border-radius: 10px; font-size: 14px; font-weight: 500;
}
.btn:hover { border-color: #cbd5d8; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
.btn-danger { color: var(--red); border-color: #f0d0d0; }
.btn-danger:hover { background: #fdf1f1; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
}

.view { display: none; }
.view.active { display: block; }

/* ------------------------------------------------------------------ Editor */

.editor-grid { display: grid; grid-template-columns: 1fr 330px; gap: 18px; align-items: start; }
@media (max-width: 1180px) { .editor-grid { grid-template-columns: 1fr; } }

.canvas-card { padding: 14px; }

.canvas-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.hint { font-size: 12px; color: var(--muted); }

.canvas-outer {
  width: 100%; aspect-ratio: 16 / 9;
  border-radius: 10px; overflow: hidden; position: relative;
}

/* Die Buehne rendert 1920x1080 und wird per transform skaliert -
   dadurch sieht die Vorschau exakt aus wie der Fernseher. */
.stage-scaler { position: absolute; inset: 0; }
.stage {
  width: 1920px; height: 1080px;
  transform-origin: top left;
  position: absolute; top: 0; left: 0;
}

.grid-overlay {
  position: absolute; inset: 0; pointer-events: none;
  display: grid; opacity: 0; transition: opacity .15s;
}
.grid-overlay.on { opacity: 1; }
.grid-overlay div { border: 1px dashed rgba(255, 255, 255, .28); }

.tile-wrap { position: absolute; }
.tile-wrap.editable { cursor: grab; }
.tile-wrap.editable.dragging { cursor: grabbing; z-index: 50; }
.tile-wrap.selected { outline: 4px solid #2f6bff; outline-offset: 3px; }

.resize-handle {
  position: absolute; right: -8px; bottom: -8px;
  width: 34px; height: 34px; border-radius: 9px;
  background: #2f6bff; border: 3px solid #fff;
  cursor: nwse-resize; z-index: 60;
}

/* ---------------------------------------------------------------- Inspector */

.inspector { position: sticky; top: 22px; max-height: calc(100vh - 44px); overflow-y: auto; }
.inspector h3 { font-size: 15px; margin-bottom: 4px; }

.field { margin-bottom: 13px; }
.field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}
.field input[type="text"],
.field input[type="number"],
.field input[type="url"],
.field select,
.field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; font: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
.field textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.field input[type="color"] {
  width: 100%; height: 38px; padding: 3px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field .with-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }

.divider { height: 1px; background: var(--line); margin: 16px 0; }

.empty-note { color: var(--muted); font-size: 14px; line-height: 1.6; }

/* Medien-Auswahl im Inspector */
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; max-height: 230px; overflow-y: auto; }
.pick {
  position: relative; border: 2px solid var(--line); border-radius: 8px;
  overflow: hidden; aspect-ratio: 16/10; background: #eef2f3; padding: 0;
}
.pick.on { border-color: var(--teal); }
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pick .ph { width: 100%; height: 100%; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.pick .badge {
  position: absolute; top: 3px; left: 3px; background: var(--teal); color: #fff;
  font-size: 10px; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center;
}

.rows-editor { display: flex; flex-direction: column; gap: 6px; }
.rows-editor .rowline { display: grid; grid-template-columns: 62px 1fr 70px 28px; gap: 5px; }
.rows-editor input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 13px; min-width: 0; }
.rows-editor .del { border: none; background: none; color: var(--red); font-size: 16px; }

/* -------------------------------------------------------------- Mediathek */

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.media-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.media-thumb { aspect-ratio: 16/10; background: #11181d; display: grid; place-items: center; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .kind { color: #8fa3ad; font-size: 12px; letter-spacing: .1em; }
.media-meta { padding: 10px 11px; }
.media-meta .n { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-meta .s { font-size: 11px; color: var(--muted); margin-top: 2px; }

.dropzone {
  border: 2px dashed #c7d3d8; border-radius: var(--radius);
  padding: 34px; text-align: center; color: var(--muted);
  background: var(--panel); margin-bottom: 18px; transition: .15s;
}
.dropzone.hot { border-color: var(--teal); background: rgba(18, 165, 148, .05); color: var(--teal-dark); }
.dropzone strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 14px; display: none; }
.progress.on { display: block; }
.progress i { display: block; height: 100%; background: var(--teal); width: 0; transition: width .2s; }

/* --------------------------------------------------------------- Vorlagen */

.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.layout-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: left; }
.layout-card:hover { border-color: var(--teal); }
.layout-prev { aspect-ratio: 16/9; background: #0a0a0a; border-radius: 7px; padding: 4px; display: grid; gap: 3px; margin-bottom: 9px; }
.layout-prev span { background: #f5c53d; border-radius: 3px; }
.layout-card .t { font-size: 14px; font-weight: 600; }
.layout-card .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ----------------------------------------------------------------- Toast */

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; z-index: 999; opacity: 0; transition: .22s; pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
