:root {
  color-scheme: light dark;
  --border: #d0d0d5;
  --bg-subtle: #f5f5f7;
  --accent: #068993;
  --danger: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --border: #3a3a3f;
    --bg-subtle: #1c1c1f;
  }
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0;
  color: canvastext;
  background: canvas;
}

.auth-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background-image: url("assets/background.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.auth-screen.active {
  display: flex;
}

#screen-app {
  display: none;
}

#screen-app.active {
  display: block;
}

.auth-form {
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  .auth-form {
    background: rgba(24, 24, 27, 0.88);
  }
}

.auth-logo {
  display: block;
  max-width: 190px;
  height: auto;
  margin: 0 auto 1.1rem;
}

.auth-form h1 {
  font-size: 1.15rem;
  margin: 0 0 1rem;
  text-align: center;
}

.auth-form button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
}

.auth-form .auth-link {
  display: block;
  margin: 0.75rem auto 0;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.85rem;
  cursor: pointer;
}

.auth-form .auth-link:hover {
  text-decoration: underline;
}

.totp-qr {
  display: block;
  width: 180px;
  height: 180px;
  margin: 0.75rem auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  padding: 0.5rem;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: canvas;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
}

.header-user button {
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  border-radius: 6px;
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.sync-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

#trigger-sync-button,
#full-sync-button {
  min-width: 9.7rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 110px;
  width: auto;
  border-radius: 8px;
}

header h1 {
  font-size: 1.25rem;
  margin: 0;
}

nav {
  display: flex;
  gap: 0.5rem;
}

.tab-button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.tab { display: none; }
.tab.active { display: block; }

fieldset {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
}

.status-section-queue { border-left: 4px solid #eab308; }
.status-section-changes { border-left: 4px solid #16a34a; }
.status-section-errors { border-left: 4px solid #b91c1c; }
.status-section-mails { border-left: 4px solid #2563eb; }
.status-section-logins { border-left: 4px solid #0891b2; }

.user-actions {
  text-align: left;
  white-space: nowrap;
}

.icon-button {
  padding: 0.3rem 0.45rem;
  margin: 0 0.25rem 0 0;
  font-size: 1rem;
  line-height: 1;
}

.icon-button-small {
  font-size: 0.7rem;
  padding: 0.25rem 0.35rem;
}

.users-table {
  table-layout: fixed;
  width: 100%;
}

.users-table th:nth-child(1), .users-table td:nth-child(1) { width: 115px; word-break: break-word; }
.users-table th:nth-child(2), .users-table td:nth-child(2) { width: 115px; }
.users-table th:nth-child(3), .users-table td:nth-child(3) { width: 185px; word-break: break-word; }
.users-table th:nth-child(4), .users-table td:nth-child(4) { width: 185px; }
.users-table th:nth-child(5), .users-table td:nth-child(5) { width: 40px; text-align: center; }
.users-table th:nth-child(6), .users-table td:nth-child(6) { width: 85px; }
.user-notification { width: 100%; min-width: 0; }
.users-table th:last-child, .users-table td:last-child { width: 190px; }
.users-table th { white-space: nowrap; }
.users-table select {
  margin-top: 0;
  padding: 0.3rem 0.35rem;
  font-size: 0.85rem;
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: 1.25rem;
}

.queue-table th:nth-child(2) { white-space: nowrap; }
.queue-table td:nth-child(2) { word-break: break-all; }

.nowrap { white-space: nowrap; }

.table-scroll table {
  margin-bottom: 0;
}

legend {
  font-weight: 600;
  padding: 0 0.4rem;
}

label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

label.checkbox {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 0.5rem;
}

label.checkbox input {
  margin-top: 0.2em;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
select,
textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  color: inherit;
  font-size: 0.95rem;
  font-family: inherit;
}

.hint {
  font-weight: 400;
  font-size: 0.8rem;
  opacity: 0.7;
}

.fieldset-hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  opacity: 0.75;
}

.fixed-mapping {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.fixed-mapping th,
.fixed-mapping td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.fixed-mapping th {
  opacity: 0.7;
  font-weight: 600;
}

.fixed-mapping input {
  width: auto;
  max-width: 220px;
  margin-top: 0;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

button {
  white-space: nowrap;
}

.mapping-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
}

.mapping-column {
  min-width: 0;
}

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

button[type="submit"], #mail-test-button, #entra-test-button, #matrix-test-button,
#mapping-check-button, #mapping-cancel-button, #preview-button {
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

.button-danger {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--danger);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
}

.button-danger.icon-button {
  padding: 0.3rem 0.45rem;
  font-size: 1rem;
  background: transparent;
  border: none;
}

.banner {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.banner.ok {
  background: #dcfce7;
  color: #166534;
}

.banner.warn {
  background: #fef9c3;
  color: #854d0e;
}

.banner.error {
  background: #fee2e2;
  color: #991b1b;
}

#save-banner,
#users-banner,
#backup-banner,
#mappings-banner {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(92vw, 480px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.status-block .table-scroll:last-child,
.status-block .table-toolbar:last-child {
  margin-bottom: 0;
}

.status-summary {
  display: flex;
  gap: 0.75rem;
  flex-wrap: nowrap;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.stat {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.6rem;
  flex: 1 1 auto;
}

.stat-small {
  flex: 0 0 auto;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  opacity: 0.7;
  text-align: center;
  white-space: nowrap;
}

.stat-value {
  display: block;
  font-size: 1.1rem;
  white-space: nowrap;
  font-weight: 600;
  margin-top: 0.2rem;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.pagination {
  display: flex;
  gap: 0.35rem;
}

.pagination button {
  min-width: 2rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.user-role {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 0.85rem;
  padding: 0.2rem;
}

th {
  opacity: 0.7;
  font-weight: 600;
}

.mappings-table th:nth-child(1), .mappings-table td:nth-child(1) { width: 110px; }
.mappings-table th:last-child, .mappings-table td:last-child { width: 90px; }
.nowrap { white-space: nowrap; }
.import-errors {
  margin: 0.75rem 0 0;
  padding: 0.75rem 1rem 0.75rem 2rem;
  border-radius: 6px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.9rem;
}
input[type="text"][readonly],
input[type="text"]:disabled {
  border-color: transparent;
  background: transparent;
  padding-left: 0;
  cursor: default;
  outline: none;
}
input[type="text"][readonly]::placeholder {
  font-style: italic;
  opacity: 0.6;
}
.hint-error { color: #b91c1c; }
.sort-button {
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  cursor: pointer;
}
.sort-button:hover { text-decoration: underline; }
.sort-indicator { font-size: 0.75em; }
.table-search {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.table-search input[type="search"] {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  color: inherit;
  font-size: 0.95rem;
  font-family: inherit;
}
.table-search .hint { white-space: nowrap; }
.search-wrap {
  position: relative;
  flex: 1;
  display: flex;
}
.search-wrap input[type="search"] { padding-right: 2rem; }
.search-wrap input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: inherit;
  opacity: 0.6;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.2rem;
  cursor: pointer;
}
.search-clear:hover { opacity: 1; }
.mappings-table .editing-row td { vertical-align: top; }
.mappings-table .editing-row input { margin-top: 0; }
.guard-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}
#guard-confirm-button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--danger);
  color: white;
  cursor: pointer;
  white-space: nowrap;
}
.table-search select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-subtle);
  color: inherit;
  font-family: inherit;
  width: auto;
  margin-top: 0;
}
.mappings-table mark {
  background: #fde68a;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
.status-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}
.header-user button:disabled { opacity: 0.5; cursor: default; }
.status-actions { gap: 0.75rem; }
#reset-sync-button {
  padding: 0.45rem 1rem;
  border: 1px solid var(--danger);
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}
#reset-sync-button:disabled { opacity: 0.5; cursor: default; }
.matrix-reset {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
input[type="text"]:disabled { color: inherit; opacity: 1; }
.header-title h1 { margin: 0; }
.header-login {
  margin-top: 0.2rem;
  font-size: 0.85rem;
  opacity: 0.7;
}
#current-username { font-weight: 600; }
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}
.tooltip {
  position: absolute;
  z-index: 1000;
  max-width: 320px;
  padding: 0.4rem 0.6rem;
  border: 1px solid #eab308;
  border-radius: 6px;
  background: #fef08a;
  color: #422006;
  font-size: 0.8rem;
  line-height: 1.3;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  pointer-events: none;
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.preview-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.preview-chip {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-subtle);
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.preview-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.preview-chip-lock { border-color: var(--danger); color: var(--danger); }
.preview-chip-lock.active { background: var(--danger); border-color: var(--danger); color: white; }
.preview-table tr.preview-row-lock td { background: rgba(185, 28, 28, 0.08); }
.preview-table tr.preview-row-lock td:last-child { color: var(--danger); font-weight: 600; }

.info-dialog {
  max-width: min(28rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  background: canvas;
  color: inherit;
}

.info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.info-dialog .actions {
  justify-content: flex-end;
}
