:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #dfe2e6;
  --accent: #1fa774;
  --accent-strong: #178a5f;
  --accent-soft: #e6f6ef;
  --danger: #c62828;
  --focus: 0 0 0 3px rgba(31, 167, 116, .28);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1d2024;
    --text: #e8eaed;
    --muted: #9aa1aa;
    --line: #30343a;
    --accent: #2bbd85;
    --accent-strong: #36d295;
    --accent-soft: #1b3229;
    --danger: #ef6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

h1, h2 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
a { color: var(--accent); }
code {
  font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  word-break: break-all;
}

/* Bedienelemente */
input, textarea, select {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: none; box-shadow: var(--focus); border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }

button, .button {
  font: inherit;
  font-weight: 600;
  border-radius: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-strong); }
.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.ghost:hover { background: var(--bg); }
.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.danger:hover { border-color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.req { color: var(--danger); }
.field-error { color: var(--danger); min-height: 0; }
.field-error:empty { display: none; }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
legend { font-weight: 600; font-size: 13px; padding: 0; margin-bottom: 4px; }

.hint { color: var(--muted); margin: 0 0 12px; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }
.saved { color: var(--accent); font-weight: 600; }

/* Anmeldung */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-card img { align-self: center; border-radius: 4px; }
.login-card h1 { text-align: center; margin: 0; }
.login-card button { justify-content: center; }

/* Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 4px; margin-left: 16px; flex: 1; }
.tabs button { background: transparent; color: var(--muted); border-radius: 6px; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-strong); }

/* Inhalt */
.tab-panel { padding: 20px; max-width: 1400px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 20px; align-items: start; }
[data-panel="template"].layout { grid-template-columns: minmax(360px, 1fr) minmax(360px, 1.2fr); }
/* Beim Bearbeiten der langen Vorlage bleibt die Vorschau im Blick. */
[data-panel="template"] > .card:last-child { position: sticky; top: 76px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.detail-pane { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.actions { display: flex; align-items: center; gap: 10px; margin-top: 18px; }

/* Liste */
.list-pane { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-tools { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.employee-list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 170px); overflow-y: auto; }
.employee-list li button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  text-align: left;
  gap: 0 8px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-weight: 400;
}
.employee-list li button:hover { background: var(--bg); }
.employee-list li button[aria-current="true"] { background: var(--accent-soft); }
.employee-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.employee-list .email { grid-column: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.employee-list .badge { grid-row: span 2; align-self: center; font-size: 12px; color: var(--muted); }
.employee-list .inactive .name { text-decoration: line-through; color: var(--muted); }
.list-pane .hint { padding: 14px; margin: 0; }

/* Vorschau: immer hell, wie eine Mail */
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.preview-head h2 { margin: 0; }
.preview-head select { width: auto; }
.preview { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border-radius: 0; background: transparent; color: var(--muted); padding: 5px 12px; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-strong); }

.color-field { display: flex; gap: 8px; }
.color-field input[type="color"] { width: 44px; padding: 2px; height: 36px; flex: none; }

/* Einrichtung */
.setup { display: flex; flex-direction: column; gap: 20px; max-width: 900px; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.copy-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.status-table { width: 100%; border-collapse: collapse; }
.status-table th, .status-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.status-table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.status-table .never { color: var(--muted); }

@media (max-width: 900px) {
  .layout, [data-panel="template"].layout { grid-template-columns: 1fr; }
  [data-panel="template"] > .card:last-child { position: static; }
  .tabs { margin-left: 0; order: 3; flex-basis: 100%; }
  .tab-panel { padding: 16px; }
  .employee-list { max-height: 280px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .status-table th:nth-child(2), .status-table td:nth-child(2) { display: none; }
}
#logout { margin-left: auto; }
