/* Beschaffungs-Check Bau AT – sachliches Verwaltungsdesign */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d8dee6;
  --border-strong: #b8c2ce;
  --text: #1a2332;
  --text-muted: #5a6675;
  --text-soft: #7a8694;
  --primary: #1e4a6e;
  --primary-hover: #163a57;
  --primary-soft: #e8f0f6;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --warning: #b54708;
  --warning-bg: #fffaeb;
  --warning-border: #fedf89;
  --success: #027a48;
  --success-bg: #ecfdf3;
  --success-border: #abefc6;
  --info: #175cd3;
  --info-bg: #eff8ff;
  --info-border: #b2ddff;
  --neutral: #344054;
  --neutral-bg: #f2f4f7;
  --neutral-border: #d0d5dd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
  --radius: 6px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Consolas", "Courier New", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.header-brand h1 {
  margin: 0 0 6px;
  font-size: 1.65rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.header-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
}

.header-auth {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  text-align: right;
}

.auth-meta-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  max-width: 320px;
}

.auth-meta-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  font-weight: 600;
  flex-shrink: 0;
}

.auth-email,
.auth-role {
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-role {
  font-weight: 600;
}

.unauthorized-email {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-all;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  align-self: center;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    linear-gradient(180deg, #e8eef4 0%, var(--bg) 48%, var(--bg) 100%);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 28px 28px 24px;
}

.login-title {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-subtitle {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form .form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-form .form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-form .form-field input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 100%;
}

.login-form .form-field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
}

.login-error[hidden] {
  display: none;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.app[hidden] {
  display: none;
}

.sort-wrap select,
.form-field select,
.form-field input,
.form-field textarea,
.search-wrap input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.sort-wrap select:focus,
.form-field select:focus,
.form-field input:focus,
.form-field textarea:focus,
.search-wrap input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

/* Dashboard tiles */
.dashboard {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--border-strong);
}

.tile-open { border-top-color: var(--primary); }
.tile-ok { border-top-color: var(--success); }
.tile-rueckfrage { border-top-color: var(--warning); }
.tile-ueberarbeitung { border-top-color: var(--danger); }
.tile-pruefung { border-top-color: var(--info); }

.tile-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}

.tile-value {
  display: block;
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.filter-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 550;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.search-wrap {
  flex: 1 1 260px;
  min-width: 220px;
}

.search-wrap input {
  width: 100%;
}

.sort-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sort-wrap label {
  font-size: 0.75rem;
  color: var(--text-soft);
  font-weight: 600;
}

/* Buttons */
.btn {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 550;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

/* [hidden] muss display:flex/ähnliche Button-Styles überstimmen */
.btn[hidden] {
  display: none !important;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
}

.btn-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}

.btn-warning:hover:not(:disabled) {
  background: #fef0c7;
}

.btn-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}

.btn-success:hover:not(:disabled) {
  background: #d1fadf;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #912018;
  border-color: #912018;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 4px 6px;
  font-weight: 550;
  font-size: 0.85rem;
}

.btn-link:hover {
  text-decoration: underline;
}

.btn-link + .btn-link {
  margin-left: 4px;
}

/* Table */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

.data-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  font-weight: 650;
  padding: 12px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.9rem;
}

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

.data-table tbody tr:hover {
  background: #fafbfc;
}

.data-table .col-nr {
  font-family: var(--mono);
  font-weight: 600;
  white-space: nowrap;
}

.data-table .col-hv {
  width: 3.5rem;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}

.data-table .col-summe {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.data-table th.col-summe {
  text-align: right;
}

.data-table .col-gegenstand {
  max-width: 240px;
}

.data-table .col-kommentar {
  max-width: 200px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.data-table .col-aktion {
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}

/* Status badges */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.3;
}

.badge-ok {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success-border);
}

.badge-rueckfrage {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}

.badge-ueberarbeitung {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

.badge-pruefung {
  background: var(--info-bg);
  color: var(--info);
  border-color: var(--info-border);
}

.badge-erledigt {
  background: var(--neutral-bg);
  color: var(--neutral);
  border-color: var(--neutral-border);
}

.turn-chip {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text);
}

.turn-chip.turn-wolfgang {
  color: var(--warning);
}

.turn-chip.turn-oliver {
  color: var(--primary);
}

.turn-chip.turn-none {
  color: var(--text-soft);
}

.muted {
  color: var(--text-soft);
  font-size: 0.85rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px;
  z-index: 100;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  border: 1px solid var(--border);
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.modal.modal-confirm {
  max-width: 440px;
}

.modal.modal-wide {
  max-width: 820px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-soft);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 22px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.modal-footer-split {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

.confirm-delete-text {
  margin: 0 0 8px;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field-full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text);
}

.required {
  color: var(--danger);
}

.form-field textarea {
  resize: vertical;
  min-height: 72px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 16px;
  margin: 0 0 20px;
}

.detail-grid dt {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 2px;
}

.detail-grid dd {
  margin: 0;
  font-size: 0.95rem;
}

.role-section {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.role-section h3 {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.role-readonly {
  margin-bottom: 4px;
}

.role-readonly[hidden],
.role-form[hidden] {
  display: none;
}

.detail-grid.compact {
  margin-bottom: 0;
}

.role-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
}

.form-error[hidden] {
  display: none;
}

.wolfgang-actions {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}

.wolfgang-actions[hidden] {
  display: none;
}

.wolfgang-portal-block {
  margin: 12px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
}

.wolfgang-portal-block[hidden] {
  display: none;
}

.wolfgang-portal-block + .wolfgang-actions {
  margin-top: 12px;
}

.btn-portal-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  white-space: normal;
  line-height: 1.3;
}

.btn-portal-link:hover:not(:disabled) {
  text-decoration: none;
}

.portal-flow-hint {
  margin: 10px 0 0;
  padding-left: 1.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.portal-flow-hint li + li {
  margin-top: 2px;
}

.history-block h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.hint {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-buttons[hidden],
.action-buttons button[hidden],
#wolfgang-action-hint[hidden],
#wolfgang-ablehnen-hint[hidden],
#wolfgang-comment-wrap[hidden] {
  display: none !important;
}

.detail-handlungsbedarf {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 0.95rem;
}

.handlungsbedarf-label {
  font-weight: 650;
  margin-right: 6px;
}

.workflow-notice {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.45;
}

.workflow-notice strong {
  display: block;
  margin-bottom: 4px;
}

.workflow-notice p {
  margin: 0;
}

.workflow-notice-reject {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.workflow-notice-replace {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}

.workflow-notice-rueckfrage {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

.workflow-notice-legacy {
  background: var(--neutral-bg);
  border-color: var(--border-strong);
  color: var(--text);
}

.oliver-reject-panel {
  margin: 10px 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-bg);
}

.oliver-reject-panel .hint {
  color: var(--danger);
}

.wolfgang-rework-actions {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--warning-border);
}

.rework-heading {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text);
}

.rework-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.rework-option-preferred {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--danger-border);
  background: #fff;
}

.rework-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 3px;
  padding: 2px 6px;
}

.wolfgang-idle-hint {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--neutral-bg, #f5f6f7);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.wolfgang-idle-hint p {
  margin: 0;
}

.wolfgang-idle-hint[hidden] {
  display: none;
}

.hist-meta {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-block {
  margin-top: 8px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  background: #fafbfc;
}

.history-list:empty::after {
  content: "Keine Historie vorhanden.";
  display: block;
  padding: 12px 14px;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.history-list li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text);
}

.history-list li:last-child {
  border-bottom: none;
}

.history-list .hist-time {
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.history-list .hist-user {
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  font-size: 0.9rem;
  max-width: 360px;
}

.toast[hidden] {
  display: none;
}

/* Responsive */
@media (max-width: 1100px) {
  .dashboard {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 760px) {
  .app {
    padding: 18px 14px 32px;
  }

  .header {
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    width: 100%;
  }

  .header-auth {
    justify-content: space-between;
    align-items: center;
  }

  .auth-meta {
    align-items: flex-start;
    text-align: left;
  }

  .dashboard {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }

  .detail-grid dt {
    margin-top: 8px;
  }
}

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