:root {
  --umm-red: #a4133c;
  --umm-blue: #1b3a6b;
  --umm-blue-light: #6b7fa8;
  --ink: #1c2430;
  --muted: #6b7280;
  --line: #d9dee6;
  --bg: #f4f6f9;
  --used: #1a7a3c;
  --avail: #1b3a6b;
  --owner: #1b4fb0;
  --slot: #b02a37;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20,30,50,.08), 0 4px 16px rgba(20,30,50,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }

/* hidden muss ID-/Klassen-display-Regeln schlagen */
[hidden] { display: none !important; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer; font: inherit;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f2f6; }
.btn--primary { background: var(--umm-red); border-color: var(--umm-red); color: #fff; width: 100%; padding: .65rem; font-weight: 600; }
.btn--primary:hover { background: #8a1030; }
.btn--ghost { background: transparent; }
.error { color: var(--umm-red); min-height: 1.2em; margin: .4rem 0 0; }

/* ---------- Login ---------- */
#login-view {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 2rem; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { max-width: 240px; height: auto; margin-bottom: 1.2rem; }
.login-group { color: var(--umm-blue); font-size: 1.3rem; margin: .2rem 0; }
.login-sub { color: var(--muted); margin: 0 0 1.5rem; font-size: .95rem; }
#login-form { text-align: left; display: grid; gap: .8rem; }
#login-form label { display: grid; gap: .3rem; font-size: .85rem; color: var(--muted); font-weight: 600; }
#login-form input {
  padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink);
}
#login-form input:focus { outline: 2px solid var(--umm-blue-light); border-color: var(--umm-blue); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem; background: #fff;
  padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
.topbar-logo { height: 34px; }
.topbar-title { font-size: 1.05rem; color: var(--ink); }
.topbar-title span { color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.user { color: var(--muted); font-size: .9rem; }
.user b { color: var(--umm-red); }

/* ---------- Navigation ---------- */
.nav { background: #fff; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); }
.tab-row { display: flex; flex-wrap: wrap; gap: .35rem; }
.tab-row--sub { margin-top: .45rem; }
.tab {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .35rem .7rem; border-radius: 7px; cursor: pointer; font: inherit; font-size: .85rem;
}
.tab:hover { background: #eef1f6; }
.tab--sub { font-size: .8rem; padding: .3rem .6rem; }
.tab--active { background: var(--umm-blue); border-color: var(--umm-blue); color: #fff; font-weight: 600; }

/* ---------- Box head ---------- */
.box-head { display: flex; align-items: baseline; gap: 1.2rem; padding: 1rem 1.2rem .3rem; flex-wrap: wrap; }
.box-head h2 { margin: 0; font-size: 1.15rem; }
.counts { display: flex; gap: 1rem; }
.count { font-size: .9rem; }
.count--avail b { color: var(--avail); }
.count--used b { color: var(--used); }

/* ---------- Matrix ---------- */
.matrix-container { padding: .5rem 1.2rem 2rem; overflow-x: auto; }
.matrix-container.loading { opacity: .5; }
.matrix {
  display: grid; grid-template-columns: repeat(var(--cols, 10), minmax(96px, 1fr));
  gap: 6px; min-width: 980px;
}
.cell {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  min-height: 96px; padding: .35rem .4rem; font-size: .72rem; position: relative;
  display: flex; flex-direction: column; gap: 2px;
}
.cell--empty { background: #fbfcfd; }
.cell__num { color: var(--slot); font-weight: 700; font-size: .72rem; }
.cell__dash { color: var(--muted); margin-top: .3rem; }
.cell__owner { color: var(--owner); font-weight: 600; }
.cell__date { color: var(--muted); }
.cell__content { color: var(--ink); font-weight: 600; line-height: 1.25; word-break: break-word; }
.cell__icons { margin-top: auto; display: flex; align-items: center; gap: 4px; font-size: .9rem; }
.cell__status { font-size: .95rem; }
.myco-unknown {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #a9e0ff 0%, #35a4ea 45%, #1667bd 100%);
  box-shadow: inset 0 0 0 1px #0d4d94, 0 1px 1px rgba(0,0,0,.2);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
  font-family: Arial, Helvetica, sans-serif;
}
.cell__btn {
  border: none; background: transparent; cursor: pointer; font-size: .95rem;
  line-height: 1; padding: 2px 3px; border-radius: 5px; color: var(--umm-blue);
}
.cell__btn:hover { background: #eef1f6; }
.cell__btn--add { color: var(--used); font-weight: 700; }
.cell__btn--edit { color: var(--umm-blue); }
.cell__btn--move { color: var(--umm-blue); }
.cell__btn--remove { color: var(--umm-red); font-weight: 700; }
.cell__btn--history { filter: grayscale(.2); }

/* ---------- History-Panel ---------- */
.modal--history { max-width: 620px; }
.muted { color: var(--muted); }
.hist-body { max-height: 60vh; overflow: auto; }
.hist-list { margin: 0; padding-left: 1.4rem; display: grid; gap: .5rem; }
.hist-list li { font-size: .9rem; line-height: 1.4; }
.hist-content { color: var(--owner); font-style: italic; }
.hist-deleted { color: var(--umm-red); }
.hist-changed { color: var(--umm-blue); }
.hist-moved { color: var(--used); }

/* ---------- Move-Dialog ---------- */
.pos-sel { padding: .45rem .5rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

/* ---------- Toolbar ---------- */
.toolbar { background: #fff; padding: .5rem 1.2rem; border-bottom: 1px solid var(--line); display: flex; gap: 1.2rem; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--umm-blue); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.link-btn:hover { color: var(--umm-red); }

/* ---------- Statistik ---------- */
.modal--stats { max-width: 460px; }
.stats-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.stats-table td { padding: .35rem .2rem; font-size: 1rem; }
.stats-table .num { text-align: right; font-weight: 700; }
.stats-table .ok { color: var(--used); }
.stats-table .warn { color: var(--umm-red); }
.stats-empty-title { font-weight: 700; margin-bottom: .3rem; }

/* ---------- Such-Panel ---------- */
.search-panel { background: #fff; border-top: 1px solid var(--line); padding: 1.2rem; }
.search-panel h2 { margin: 0 0 .3rem; font-size: 1.15rem; }
.search-hint { color: var(--muted); font-size: .85rem; margin: 0 0 .8rem; }
.search-fields { display: flex; gap: 1.2rem; align-items: flex-end; flex-wrap: wrap; }
.search-field { display: grid; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.search-field input[type="text"] { padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 260px; }
.search-field select { padding: .3rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; min-width: 220px; }
.search-buttons { display: flex; gap: .5rem; }
.search-buttons .btn--primary { width: auto; }
.search-results { margin-top: 1rem; overflow-x: auto; }
.search-count { color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }

/* ---------- Ergebnistabelle ---------- */
.result-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.result-table th, .result-table td { border: 1px solid var(--line); padding: .4rem .5rem; text-align: left; vertical-align: top; }
.result-table th { background: #f0f2f6; font-size: .78rem; }
.result-pos { background: none; border: none; color: var(--umm-blue); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.result-pos:hover { color: var(--umm-red); }
.result-owner { color: var(--owner); font-weight: 600; white-space: nowrap; }
.result-content { min-width: 220px; }
.result-actions { white-space: nowrap; }

/* ---------- Buttons klein ---------- */
.btn--small { padding: .3rem .6rem; font-size: .8rem; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,30,50,.45);
  display: grid; place-items: center; padding: 1rem; z-index: 50;
}
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; padding: 1.4rem 1.6rem;
}
.modal h2 { margin: 0 0 1rem; font-size: 1.2rem; }
.field { margin-bottom: .9rem; }
.field > label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
.field .req { color: var(--umm-red); }
.field input[type="text"], .field textarea, .field input[type="number"] {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--umm-blue-light); border-color: var(--umm-blue); }
.date-row, .pos-row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.date-in { width: 3.2rem !important; text-align: center; }
.date-in--y { width: 4.5rem !important; }
.pos-in { width: 4rem !important; text-align: center; }
.pos-in[readonly] { background: #f0f2f6; color: var(--muted); }
.arrow { color: var(--muted); font-weight: 700; }
.hint { display: block; color: var(--muted); font-size: .75rem; margin-top: .3rem; }
.radios { display: flex; gap: 1rem; flex-wrap: wrap; }
.radios label { font-size: .9rem; font-weight: 400; color: var(--ink); display: inline-flex; align-items: center; gap: .3rem; }
.modal-actions { display: flex; gap: .6rem; margin-top: 1rem; }
.modal-actions .btn--primary { width: auto; }

/* ---------- Autocomplete ---------- */
#dlg-owner + .ac-list, .ac-list {
  position: absolute; z-index: 60; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto;
  min-width: 240px; margin-top: 2px;
}
.ac-item { padding: .4rem .6rem; cursor: pointer; font-size: .9rem; }
.ac-item:hover, .ac-item--active { background: var(--umm-blue); color: #fff; }
.field { position: relative; }
