:root {
  --primary: #4338ca;
  --primary-dark: #3730a3;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #cbd5e1;
  --card-bg: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --border: #94a3b8;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Navbar ── */
.navbar {
  background: var(--primary);
  color: #fff;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  position: relative;
  z-index: 200;
}
.brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .4px;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: .25rem;
  align-items: center;
}
.nav-links a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  padding: .35rem .7rem;
  border-radius: 6px;
  font-size: .88rem;
  white-space: nowrap;
}
.nav-links a:hover, .nav-active { background: rgba(255,255,255,.2) !important; color: #fff !important; }
.nav-user { font-size: .8rem; color: rgba(255,255,255,.7); padding: 0 .4rem; white-space: nowrap; }
.btn-logout {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  cursor: pointer;
  padding: .35rem .75rem;
  border-radius: 6px;
  font-size: .85rem;
  white-space: nowrap;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* Hamburger – nur auf Mobile sichtbar */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: .25rem .4rem;
  line-height: 1;
}

/* ── Layout ── */
.container { max-width: 960px; margin: 1.75rem auto; padding: 0 1.25rem; }
.container-sm { max-width: 420px; margin: 3.5rem auto; padding: 0 1rem; }

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 1.4rem; }

/* ── Login ── */
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo h1 { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.login-logo p { color: var(--muted); font-size: .9rem; margin-top: .25rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .83rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=datetime-local], select {
  width: 100%;
  padding: .6rem .9rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  transition: border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  border: none;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { opacity: .88; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { opacity: .88; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover  { background: var(--bg); }
.btn-full { width: 100%; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }

/* ── Alert ── */
.alert { padding: .7rem 1rem; border-radius: 7px; font-size: .9rem; margin-bottom: 1rem; display: none; }
.alert.show { display: block; }
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }

/* ── Table ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 480px; }
th { background: var(--bg); padding: .65rem 1rem; text-align: left; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
td { padding: .7rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #f8fafc; }

/* ── Badge ── */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-user  { background: #e0f2fe; color: #075985; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.4rem; }
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; padding: .25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.5rem; }

/* ── Divider ── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Section header ── */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; flex-wrap: wrap; gap: .5rem; }
.section-title { font-size: 1.05rem; font-weight: 700; }

/* ── Checkbox ── */
.checkbox-group { display: flex; align-items: center; gap: .5rem; }
.checkbox-group input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary); }
.checkbox-group label { margin: 0; font-weight: 500; color: var(--text); font-size: .9rem; cursor: pointer; }

/* ── Meta ── */
.meta { font-size: .8rem; color: var(--muted); margin-top: 1rem; }

/* ── Back link ── */
.back-link {
  display: inline-flex; align-items: center; gap: .4rem;
  color: var(--muted); font-size: .88rem; text-decoration: none; margin-bottom: 1.25rem;
}
.back-link:hover { color: var(--text); }

/* ── Tile grid ── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 1.1rem;
}
.tile {
  background: #e2e8f0;
  border: 1px solid #94a3b8;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  text-decoration: none;
  display: block;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(0,0,0,.2); }
.tile-icon-emoji {
  height: 90px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.8rem; line-height: 1;
}
.tile-icon-img {
  height: 110px;
  background-size: cover;
  background-position: center;
}
.tile-body { padding: 1.1rem; }
.tile-name { font-size: 1rem; font-weight: 700; margin-bottom: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-desc { font-size: .82rem; color: var(--muted); margin-bottom: .8rem; min-height: 1.2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-stats { border-top: 1px solid var(--border); padding-top: .75rem; display: flex; flex-direction: column; gap: .3rem; }
.tile-stat { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.tile-stat strong { color: var(--text); }
.tile-mix {
  margin-top: .6rem; padding-top: .6rem;
  border-top: 1px solid var(--border);
}
.tile-mix-ratio {
  font-size: .85rem; font-weight: 800; letter-spacing: .04em;
  color: var(--text); margin-bottom: .35rem;
}
.tile-mix-bar {
  display: flex; height: 6px; border-radius: 999px; overflow: hidden; gap: 1px;
}
.tile-mix-bar-seg { height: 100%; }
.tile-mix-labels {
  display: flex; flex-wrap: wrap; gap: .25rem .6rem; margin-top: .35rem;
}
.tile-mix-label {
  display: flex; align-items: center; gap: .25rem;
  font-size: .72rem; color: var(--muted);
}
.tile-mix-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.tile-empty { grid-column: 1 / -1; text-align: center; padding: 2.5rem; color: var(--muted); font-size: .95rem; }

/* ── Color picker ── */
.color-picker { display: flex; gap: .5rem; flex-wrap: wrap; }
.color-swatch { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: border-color .1s, transform .1s; -webkit-tap-highlight-color: transparent; }
.color-swatch.active, .color-swatch:hover { border-color: #1e293b; transform: scale(1.15); }

/* ── Log stats ── */
.log-summary { display: flex; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.log-stat-box { background: var(--bg); border-radius: 8px; padding: .7rem 1rem; flex: 1; min-width: 100px; }
.log-stat-box .value { font-size: 1.3rem; font-weight: 800; color: var(--text); }
.log-stat-box .label { font-size: .75rem; color: var(--muted); margin-top: .1rem; }

/* ── Icon-Picker ── */
.icon-preview-btn {
  display: inline-flex; align-items: center; gap: .65rem;
  padding: .55rem 1rem; border: 1.5px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: .9rem; font-weight: 500;
  transition: border-color .15s; min-height: 48px;
}
.icon-preview-btn:hover { border-color: var(--primary); }
.icon-preview-show { font-size: 2rem; line-height: 1; }
.icon-preview-img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; display: block; }

.icon-modal { max-width: 580px; padding: 1.25rem; display: flex; flex-direction: column; gap: 0; }

.tab-bar { display: flex; border-bottom: 1px solid var(--border); margin-bottom: .9rem; }
.tab-bar button {
  flex: 1; padding: .6rem .5rem; border: none; background: none; cursor: pointer;
  font-size: .88rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-bar button.active { color: var(--primary); border-bottom-color: var(--primary); }

.cat-bar { display: flex; gap: .35rem; margin-bottom: .75rem; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: .25rem; }
.cat-bar::-webkit-scrollbar { height: 0; }
.cat-btn {
  padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 999px;
  background: #fff; font-size: .78rem; cursor: pointer; white-space: nowrap;
  min-height: 36px; -webkit-tap-highlight-color: transparent;
}
.cat-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 2px;
  overflow-y: auto;
  max-height: 300px;
  -webkit-overflow-scrolling: touch;
}
.emoji-btn {
  font-size: 1.7rem; padding: .35rem; border: 2px solid transparent;
  border-radius: 8px; background: none; cursor: pointer; line-height: 1.2;
  text-align: center; transition: background .1s; min-height: 52px; min-width: 48px;
  -webkit-tap-highlight-color: transparent;
}
.emoji-btn:hover { background: var(--bg); }
.emoji-btn.selected { border-color: var(--primary); background: #ede9fe; }

/* Bild-Upload Bereich */
.img-upload-btns { display: flex; gap: .75rem; margin-bottom: 1rem; }
.img-upload-label {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .3rem; padding: 1.2rem .75rem;
  border: 2px dashed var(--border); border-radius: 10px;
  cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--muted);
  transition: border-color .15s, background .15s; text-align: center; min-height: 90px;
}
.img-upload-label:hover { border-color: var(--primary); background: #f5f3ff; color: var(--primary); }
.img-upload-label input { display: none; }
.img-upload-icon { font-size: 2rem; }

.img-preview-wrap { display: none; margin-bottom: 1rem; }
.img-preview-wrap img { max-width: 160px; max-height: 130px; border-radius: 8px; object-fit: cover; }

/* ── Danger zone ── */
.danger-zone {
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-top: 1.5rem;
  background: #fef2f2;
}
.danger-zone-title { font-weight: 700; color: var(--danger); margin-bottom: .75rem; font-size: .95rem; }

/* ══════════════════════════════════════════
   RESPONSIVE – Mobile
══════════════════════════════════════════ */

@media (max-width: 720px) {
  /* Hamburger */
  .hamburger { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 56px; left: 0; right: 0;
    background: var(--primary-dark);
    flex-direction: column;
    padding: .5rem .75rem;
    gap: 0;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    display: block;
    padding: .8rem 1rem;
    border-radius: 7px;
    font-size: .95rem;
    color: rgba(255,255,255,.9);
  }
  .nav-user { display: block; padding: .8rem 1rem; color: rgba(255,255,255,.6); font-size: .82rem; }
  .btn-logout { display: block; width: 100%; text-align: left; padding: .8rem 1rem; border-radius: 7px; border: none; background: rgba(255,255,255,.1); }
}

@media (max-width: 600px) {
  /* Icon-Modal von unten */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .icon-modal {
    max-width: 100%;
    max-height: 88vh;
    border-radius: 18px 18px 0 0;
    padding: 1.25rem 1rem;
  }
  /* Reguläre Modals */
  .modal:not(.icon-modal) {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    margin: 0;
  }
  .emoji-grid { max-height: 42vh; }
}

@media (max-width: 480px) {
  .container { padding: 0 .875rem; margin-top: 1.25rem; }
  .container-sm { margin: 1.5rem auto; padding: 0 .875rem; }
  .card { padding: 1.25rem; }

  /* Login */
  .login-logo h1 { font-size: 1.3rem; }

  /* Log stats gestapelt */
  .log-summary { gap: .6rem; }
  .log-stat-box { min-width: 90px; padding: .55rem .8rem; }
  .log-stat-box .value { font-size: 1.1rem; }

  /* Tile */
  .tile-icon-emoji { height: 80px; font-size: 2.4rem; }
  .tile-icon-img   { height: 100px; }

  /* Buttons in Reihen */
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }

  /* Tabellen-Wrapper ragt an den Rand */
  .table-wrap { margin-left: -1.25rem; margin-right: -1.25rem; padding: 0 1.25rem; border-radius: 0; }

  /* Danger zone */
  .danger-zone { padding: 1rem; }
}
