:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f1f4;
  --border: #e2e4e9;
  --text: #1c1e21;
  --text-muted: #6b7280;
  --primary: #3457d5;
  --primary-hover: #2a44ad;
  --danger: #d1453d;
  --danger-bg: #fdecea;
  --success: #1f8a54;
  --success-bg: #e7f6ee;
  --sidebar-bg: #171a21;
  --sidebar-text: #cbd0dc;
  --sidebar-text-active: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 21, 26, 0.08), 0 1px 2px rgba(20, 21, 26, 0.06);
  font-size: 17px;
}

/*
 * Accent-color themes, selected in Einstellungen and applied via
 * [data-accent] on <html>. Keep this list in sync with
 * App\Support\Theme::OPTIONS.
 */
[data-accent="slate"]  { --primary: #3457d5; --primary-hover: #2a44ad; }
[data-accent="blue"]   { --primary: #2563eb; --primary-hover: #1d4ed8; }
[data-accent="indigo"] { --primary: #4f46e5; --primary-hover: #4338ca; }
[data-accent="teal"]   { --primary: #0d9488; --primary-hover: #0f766e; }
[data-accent="green"]  { --primary: #16a34a; --primary-hover: #15803d; }
[data-accent="purple"] { --primary: #9333ea; --primary-hover: #7e22ce; }
[data-accent="rose"]   { --primary: #e11d48; --primary-hover: #be123c; }
[data-accent="amber"]  { --primary: #d97706; --primary-hover: #b45309; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-section { margin-top: 1.25rem; }
.sidebar-section:first-child { margin-top: 0; }
.sidebar-section h4 {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: #7c8296;
  padding: 0 0.5rem;
  margin: 0 0 0.4rem;
}

.sidebar-accordion > summary {
  cursor: pointer;
  list-style: none;
}
.sidebar-accordion > summary::-webkit-details-marker { display: none; }
.sidebar .sidebar-accordion > summary.btn { justify-content: space-between; }
.sidebar-accordion > summary::after {
  content: '▸';
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.sidebar-accordion[open] > summary::after { transform: rotate(90deg); }
.sidebar-accordion .nav-link { margin-top: 0.15rem; }

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 0.9rem;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar a.nav-link:hover { background: rgba(255, 255, 255, 0.08); text-decoration: none; color: var(--sidebar-text-active); }
.sidebar a.nav-link.active { background: var(--primary); color: #fff; }
.sidebar .nav-link .icon { width: 15px; height: 15px; flex-shrink: 0; fill: currentColor; opacity: 0.8; }
.sidebar .nav-link .badge { margin-left: auto; }
.sidebar .nav-user-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar .btn.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  border-color: rgba(255, 255, 255, 0.12);
  justify-content: flex-start;
}
.sidebar .btn.btn-secondary:hover { background: rgba(255, 255, 255, 0.16); color: var(--sidebar-text-active); }

.icon { width: 1em; height: 1em; fill: currentColor; vertical-align: -0.125em; }
.btn .icon { width: 0.9em; height: 0.9em; }
.sidebar .badge {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.72rem;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}
.topbar-left { display: flex; align-items: center; }
.topbar-title-link {
  color: inherit;
  text-decoration: none;
  text-align: center;
  min-width: 0;
}
.topbar-title-link:hover { text-decoration: none; }
.topbar-title-link:hover .topbar-title { opacity: 0.8; }
.topbar-title {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transition: opacity 0.12s ease;
}
.topbar-subtitle {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  line-height: 1.3;
  margin-top: 0.2rem;
}
.topbar-right { flex-shrink: 0; justify-self: end; }
.topbar-logo { max-height: 60px; max-width: 240px; object-fit: contain; }

.content { padding: 1.5rem; max-width: 1200px; width: 100%; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2, .card h3 { margin-top: 0; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.btn-secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn.btn-secondary:hover { background: #e7e8ec; }
.btn.btn-danger { background: var(--danger); }
.btn.btn-danger:hover { background: #b53a33; }
.btn.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn.btn-block { width: 100%; justify-content: center; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.3rem; font-size: 0.88rem; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=tel], input[type=url], input[type=color],
select, textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

input[type=file] {
  width: 100%;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-family: inherit;
}
input[type=file]::file-selector-button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  margin-right: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease;
}
input[type=file]::file-selector-button:hover { background: #e7e8ec; }
input[type=file]:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
table th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.alert { padding: 0.7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: var(--success-bg); color: var(--success); }

.badge-pill { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.75rem; background: var(--surface-alt); color: var(--text-muted); }

.text-muted { color: var(--text-muted); }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #171a21, #2a3352);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 2.25rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-card h1 { margin-top: 0; font-size: 1.4rem; }

.item-icon { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #fff; flex-shrink: 0; }
.item-list-icon { width: 60px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #fff; }
.item-list-table td { vertical-align: top; }
tr.row-link { cursor: pointer; transition: background 0.1s ease; }
tr.row-link:hover { background: var(--surface-alt); }

.mobile-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text); }
.hidden { display: none !important; }

/* --- Item detail: read-only by default, click-to-edit in edit mode --- */
.btn-icon { padding: 0; width: 2.15rem; height: 2.15rem; justify-content: center; flex-shrink: 0; }
.btn-icon .icon { width: 1rem; height: 1rem; }
.item-actions { flex-wrap: wrap; }
.item-actions form, .field-row dd form { display: contents; }

.editable-name { font-size: 1.3rem; font-weight: 700; margin: 0; }
.editable { border-radius: 6px; padding: 0.05rem 0.3rem; margin: -0.05rem -0.3rem; }
.editable:empty::before { content: '—'; color: var(--text-muted); }
body.edit-mode .editable { cursor: text; box-shadow: 0 0 0 1px var(--border) inset; }
body.edit-mode .editable:hover { background: var(--surface-alt); box-shadow: 0 0 0 1px var(--primary) inset; }
.editable-input { font: inherit; padding: 0.15rem 0.4rem; width: 100%; max-width: 320px; }
.editable-name-input { font-size: 1.3rem; font-weight: 700; }

.edit-only { display: none; }
body.edit-mode .edit-only { display: inline-flex; }
body.edit-mode .edit-only.block { display: block; }

.field-list { margin: 0; }
.field-list.field-list-2col { column-count: 2; column-gap: 2rem; }
.field-list.field-list-2col .field-row { break-inside: avoid-column; }
@media (max-width: 640px) {
  .field-list.field-list-2col { column-count: 1; }
}
.field-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.field-row:last-child { border-bottom: none; }
.field-row-empty { display: none; }
body.edit-mode .field-row-empty { display: flex; }
.field-row dt { font-weight: 600; font-size: 0.82rem; color: var(--text-muted); width: 38%; flex-shrink: 0; }
.field-row dd { margin: 0; flex: 1; display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.field-row dd .editable { flex: 1; min-width: 0; }
.field-delete {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  flex-shrink: 0;
}
.field-delete:hover { background: var(--danger-bg); color: var(--danger); }
body.edit-mode .field-delete { display: inline-block; }

.save-flash {
  display: inline-flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--success);
  flex-shrink: 0;
}
.save-flash.show { opacity: 1; }
.save-flash.error { color: var(--danger); }
.save-flash .icon { width: 0.9rem; height: 0.9rem; }

.log-table tbody tr:nth-child(even) { background: var(--surface-alt); }
.log-table td { vertical-align: middle; white-space: nowrap; }
.log-table td.log-time { color: var(--text-muted); font-size: 0.8rem; width: 1%; }
.log-table td.log-undo { width: 1%; }
.log-table td.log-message { white-space: normal; width: 100%; }
.log-table td.log-message .user { font-weight: 600; }
.log-table form { display: inline-flex; }
.btn-link-undo {
  background: none; border: none; color: var(--primary); cursor: pointer;
  font-size: 0.8rem; text-decoration: underline; flex-shrink: 0; padding: 0;
}
.btn-link-undo:hover { color: var(--primary-hover); }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.75rem; }
.image-tile { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 1; }
.image-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-tile .image-delete {
  position: absolute; top: 4px; right: 4px;
  background: rgba(20,21,26,0.65); color: #fff; border: none; border-radius: 6px;
  width: 1.6rem; height: 1.6rem; display: none; align-items: center; justify-content: center; cursor: pointer;
}
body.edit-mode .image-tile .image-delete { display: flex; }
.image-tile .image-delete .icon { width: 0.75rem; height: 0.75rem; }

details.card summary { cursor: pointer; font-weight: 600; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: '▸'; display: inline-block; margin-right: 0.4rem; color: var(--text-muted); }
details.card[open] summary::before { content: '▾'; }
details.card summary { margin: -1.25rem -1.5rem; padding: 1.25rem 1.5rem; }
details.card[open] summary { margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.75rem; }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.pagination input[type=number] { padding: 0.3rem 0.5rem; }
.btn.btn-disabled { opacity: 0.4; pointer-events: none; cursor: default; }

@media (max-width: 880px) {
  .sidebar { position: fixed; left: -280px; top: 0; z-index: 40; transition: left 0.2s ease; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .mobile-toggle { display: inline-flex; }
  .content { padding: 1rem; }
  .card { padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0.6rem 1rem; }
  .login-card { padding: 1.5rem; margin: 1rem; }
  table th, table td { padding: 0.45rem 0.5rem; font-size: 0.82rem; }
}

@media (max-width: 480px) {
  .flex-between { flex-wrap: wrap; gap: 0.5rem; }
  .btn { width: 100%; justify-content: center; }
  .btn.btn-sm { width: auto; }
}
