:root {
  color-scheme: dark;
  --bg: #0a0e12;
  --surface: #12171d;
  --surface-raised: #1a2129;
  --border: #232b33;
  --border-soft: #1a2027;
  --text: #e7ebee;
  --muted: #7c8896;
  --muted-dim: #566068;
  --accent: #4fd1a5;
  --accent-dim: #2a7a5c;
  --accent-text: #06120d;
  --warn: #e8a33d;
  --danger: #e2594c;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Consolas, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Standalone-Seiten (Login) ────────────────────────────────────────── */

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 800px 500px at 50% -10%, rgba(79, 209, 165, 0.08), transparent);
}

/* ─── App-Shell (Dashboard) ─────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

.menu-toggle {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  padding: 0 0.5rem;
  margin-bottom: 2rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 0.4rem;
  background: rgba(79, 209, 165, 0.14);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 15px;
  height: 15px;
  fill: var(--accent);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.88rem;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-raised);
  color: var(--accent);
}

.nav-item .icon {
  font-family: var(--mono);
  font-size: 0.85rem;
  width: 1.1rem;
  opacity: 0.8;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sync-readout {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted-dim);
  border-top: 1px solid var(--border-soft);
  padding-top: 0.75rem;
  line-height: 1.5;
}

.sync-readout .value {
  color: var(--accent);
}

/* ─── Main-Content ──────────────────────────────────────────────────────── */

.main {
  padding: 2rem 2.5rem 3rem;
  width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.page-header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  letter-spacing: -0.01em;
}

.page-header .subtitle {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.search-input {
  width: 220px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ─── Panels / Cards ────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  overflow: hidden;
}

.panel + .panel {
  margin-top: 1.25rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0;
}

/* ─── Forms ─────────────────────────────────────────────────────────────── */

label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.3rem;
}

input, select {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.88rem;
}

input:focus, select:focus, button:focus-visible, .nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field {
  margin-bottom: 0.85rem;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.field-wide {
  grid-column: span 2;
}

.field-checkbox label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.field-checkbox input[type="checkbox"] {
  width: auto;
}

.field-checkbox.disabled {
  opacity: 0.5;
}

.field-hint {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

button {
  appearance: none;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.15s ease;
}

button:hover {
  background: #63dbb2;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

button.secondary:hover {
  background: var(--surface-raised);
}

button.ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 500;
  padding: 0.35rem 0.6rem;
}

button.ghost:hover {
  background: var(--surface-raised);
  color: var(--text);
}

button.danger-ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 500;
  padding: 0.35rem 0.6rem;
}

button.danger-ghost:hover {
  background: rgba(226, 89, 76, 0.12);
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0.75rem 1.25rem 0;
}

.error:not([hidden]) {
  margin-bottom: 0.75rem;
}

/* ─── Create-Mandant (einklappbar) ─────────────────────────────────────── */

.create-form {
  padding: 1.25rem;
}

.create-form .field-row {
  margin-bottom: 0.85rem;
}

.create-form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ─── Tabellen ──────────────────────────────────────────────────────────── */

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

th:first-child, td:first-child {
  padding-left: 1.1rem;
}

th:last-child, td:last-child {
  padding-right: 1.1rem;
}

th {
  color: var(--muted-dim);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: var(--surface-raised);
}

.empty-row td {
  color: var(--muted-dim);
  font-style: italic;
  text-align: center;
  padding: 1.75rem;
}

.token {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mono {
  font-family: var(--mono);
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 0.3rem;
  letter-spacing: 0.03em;
}

.badge-interval {
  background: rgba(79, 209, 165, 0.12);
  color: var(--accent);
}

.badge-test {
  background: rgba(232, 163, 61, 0.14);
  color: var(--warn);
}

.badge-summary {
  background: rgba(99, 102, 241, 0.14);
  color: #818cf8;
}

.row-actions {
  display: flex;
  gap: 0.15rem;
  white-space: nowrap;
}

.row-actions button {
  padding: 0.3rem 0.45rem;
  font-size: 0.72rem;
}

/* ─── Inline-Edit-Zeile ─────────────────────────────────────────────────── */

.edit-row input, .edit-row select {
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
}

.edit-row td {
  padding: 0.5rem 0.75rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ─── Login-Panel ───────────────────────────────────────────────────────── */

.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
}

.login-panel .brand {
  margin-bottom: 1.5rem;
}

.login-panel h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-panel button {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0.85rem;
    left: 0.85rem;
    z-index: 40;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    border-radius: 0.5rem;
  }

  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 30;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5);
  }

  .brand {
    margin-top: 2.6rem;
  }

  .sidebar-footer {
    display: flex;
  }

  .main {
    padding: 4.5rem 1.25rem 2.5rem;
  }

  .page-header {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }
  .field-wide {
    grid-column: span 1;
  }
}
