:root {
  --bg: #f3f1ec;
  --panel: #fffdf8;
  --ink: #1c2420;
  --muted: #5f6b64;
  --line: #d7d2c8;
  --accent: #0f6b4c;
  --accent-2: #c45c26;
  --danger: #a33b2d;
  --ok: #2f6b3a;
  --warn: #8a6a1f;
  --sidebar: #16352c;
  --sidebar-ink: #e8efe9;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(28, 36, 32, 0.06);
  --font: "Segoe UI", "IBM Plex Sans", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 107, 76, 0.08), transparent 40%),
    linear-gradient(180deg, #efebe3, var(--bg));
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #124435, var(--sidebar));
  color: var(--sidebar-ink);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.brand { display: flex; gap: 0.75rem; align-items: center; }
.brand strong { display: block; }
.brand small { opacity: 0.75; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: #f0c36a; color: #16352c; font-weight: 700;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.sidebar nav a {
  color: var(--sidebar-ink); padding: 0.55rem 0.75rem; border-radius: 8px; opacity: 0.85;
}
.sidebar nav a.active, .sidebar nav a:hover {
  background: rgba(255,255,255,0.1); opacity: 1; text-decoration: none;
}
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.linkish {
  background: none; border: 0; color: #f0c36a; cursor: pointer; padding: 0; font: inherit;
}

.main { padding: 1.5rem 2rem 3rem; }
.page-header h1 { margin: 0 0 1rem; font-size: 1.75rem; font-weight: 650; letter-spacing: -0.02em; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; font-size: 1.1rem; }

.stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.stat-card span { color: var(--muted); font-size: 0.9rem; }
.stat-card strong { display: block; font-size: 1.8rem; margin-top: 0.25rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 0.55rem 0.9rem; cursor: pointer; font: inherit;
}
.btn:hover { text-decoration: none; border-color: #b9b2a5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: #f8e9e6; border-color: #e2b8b1; color: var(--danger); }
.btn-small { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.filters, .row-form, .actions-bar, .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.filters { margin-bottom: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.stack.narrow { max-width: 420px; }
.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 1rem; align-items: start; }
.detail-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 1rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.92rem; }
input, select, textarea {
  font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.7rem; background: #fff;
}
.check { flex-direction: row; align-items: center; gap: 0.45rem; }
.inline-form { display: inline; }

/* Editierbare Listen: jede Zeile = eigenes Grid mit gleichen Spalten */
.edit-grid {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
  min-width: 0;
}
.edit-grid-row {
  display: grid;
  gap: 0.75rem;
  align-items: center;
  width: 100%;
  min-width: 0;
}
.edit-grid-suppliers .edit-grid-row {
  grid-template-columns: minmax(120px, 0.8fr) minmax(160px, 1.4fr) 90px auto;
}
.edit-grid-users .edit-grid-row {
  grid-template-columns: minmax(120px, 0.9fr) minmax(160px, 1.2fr) 90px minmax(150px, 1fr) auto;
}
.edit-grid-attributes .edit-grid-row {
  grid-template-columns: minmax(110px, 0.8fr) minmax(140px, 1.2fr) 110px 90px auto;
}
.edit-grid-head {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--line);
  margin: 0;
}
.edit-grid-header {
  margin-bottom: 0.15rem;
}
.edit-grid-row > input,
.edit-grid-row > select {
  width: 100%;
  min-width: 0;
}
.edit-grid-row > .check {
  margin: 0;
  white-space: nowrap;
}
.edit-grid-row > .btn,
.edit-grid-row > .actions {
  justify-self: start;
}
.edit-grid-empty {
  margin: 0.25rem 0 0;
}
.muted { color: var(--muted); }
.alert { padding: 0.8rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: #e8f4ea; border-color: #b7d8be; color: var(--ok); }
.alert-error { background: #f8e9e6; border-color: #e2b8b1; color: var(--danger); }

.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.78rem;
  background: #ece8df; color: var(--muted);
}
.badge-active, .badge-success { background: #e5f3ea; color: var(--ok); }
.badge-inactive, .badge-failed { background: #f8e9e6; color: var(--danger); }
.badge-partial, .badge-running { background: #f7f0da; color: var(--warn); }

.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #eee; }
.thumb.placeholder { display: inline-grid; place-items: center; color: var(--muted); }
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.6rem; }
.image-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 0.45rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.pagination { display: flex; gap: 0.35rem; margin-top: 1rem; flex-wrap: wrap; }
.pagination a {
  padding: 0.3rem 0.55rem; border: 1px solid var(--line); border-radius: 6px; color: var(--ink);
}
.pagination a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.small-code { display: inline-block; max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.auth-body {
  display: grid; place-items: center; min-height: 100vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(240, 195, 106, 0.25), transparent 35%),
    linear-gradient(160deg, #12382d, #1d4d3d 45%, #0f2a22);
}
.auth-card {
  width: min(420px, 92vw); background: var(--panel); border-radius: 16px; padding: 1.5rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-brand { margin-bottom: 1.25rem; }

/* API Tester */
.api-tester-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.code-block {
  margin: 0;
  padding: 0.85rem 1rem;
  background: #17231f;
  color: #e7f0ea;
  border-radius: 8px;
  overflow: auto;
  font-size: 0.86rem;
  line-height: 1.45;
}
.code-block code {
  font-family: ui-monospace, Consolas, monospace;
  color: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-meta { margin-bottom: 0.5rem; }
.break-all { word-break: break-all; white-space: pre-wrap; }
.response-block {
  max-height: 480px;
  min-height: 140px;
}
.small-note { margin: 0.75rem 0 0; font-size: 0.9rem; }

.api-key-cell { min-width: 220px; }
.api-key-full { display: inline-block; max-width: 100%; word-break: break-all; }
.reveal-details { margin-top: 0.4rem; }
.reveal-details > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
}
.reveal-details > summary::-webkit-details-marker { display: none; }
.reveal-form {
  margin-top: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f4ee;
  max-width: 280px;
}

.key-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fffcf7;
}
.key-card-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}
.whitelist-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.whitelist-box h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}
.ip-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0.75rem;
}
.ip-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid #eee8dc;
}
.inline-add-ip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.inline-add-ip input,
.inline-add-ip select {
  min-width: 140px;
}
.stacked-actions {
  flex-direction: column;
  align-items: stretch;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 5; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .stats-grid, .split, .detail-grid, .api-tester-split, .param-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .main { padding: 1rem; }
}
