/* ════════════════════════════════════════════════════════════════
   DIHAG Richtlinienmanagementsystem – Design-System
   Tokens & Komponenten übernommen aus dem Vorbild (bedarfsanfrage).
   Inter · Primärblau #1a56db · helle Sidebar + Topbar
════════════════════════════════════════════════════════════════ */

:root {
  --c-bg:        #f0f2f5;
  --c-surface:   #ffffff;
  --c-text:      #1e2939;
  --c-muted:     #6b7280;
  --c-faint:     #9ca3af;
  --c-border:    #e5e9ef;
  --c-border-2:  #f0f2f5;
  --c-primary:   #1a56db;
  --c-primary-d: #1648c5;
  --c-primary-l: #eff3ff;
  --c-success:   #16a34a;
  --c-success-d: #15803d;
  --c-warn:      #ea580c;
  --c-danger:    #ef4444;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
}
a { color: inherit; }

/* ── Boot Screen ── */
#boot {
  position: fixed; inset: 0; background: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; z-index: 9999;
}
.boot-title { font-size: 1.3rem; font-weight: 700; color: var(--c-text); }
.boot-sub   { font-size: .9rem; color: var(--c-muted); }
.boot-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-err { color: #b91c1c; font-size: .85rem; max-width: 380px; text-align: center; line-height: 1.5; }
.boot-btn {
  padding: 10px 28px; background: var(--c-primary); color: #fff;
  border: none; border-radius: 8px; font-size: .95rem; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.boot-btn:hover { background: var(--c-primary-d); }

/* ── App Layout ── */
#app { display: flex; min-height: 100vh; }
.hidden { display: none !important; }

/* ── Sidebar ── */
.sidebar {
  width: 224px; min-width: 224px;
  background: #fff; border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: transform .25s ease;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 700; font-size: 1.05rem; color: var(--c-primary);
  border-bottom: 1px solid var(--c-border);
}
.sidebar-nav {
  flex: 1; padding: 10px 8px;
  display: flex; flex-direction: column; gap: 1px; overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: 8px;
  text-decoration: none; color: #4b5563;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover  { background: #f0f4ff; color: var(--c-primary); }
.nav-item.active { background: var(--c-primary-l); color: var(--c-primary); font-weight: 600; }
.nav-sep { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--c-faint); padding: 14px 11px 6px; }
.sidebar-user {
  padding: 12px 14px; border-top: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 9px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--c-primary); color: #fff;
  font-weight: 700; font-size: .78rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-name { font-size: .83rem; font-weight: 600; }
.user-sub  { font-size: .72rem; color: var(--c-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.logout-btn {
  margin-left: auto; background: none; border: none;
  cursor: pointer; color: var(--c-faint); padding: 4px;
  border-radius: 4px; display: flex;
}
.logout-btn svg { width: 16px; height: 16px; }
.logout-btn:hover { color: #374151; background: #f3f4f6; }

/* ── Main ── */
.main { flex: 1; margin-left: 224px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--c-border);
  height: 54px; padding: 0 22px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 1rem; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--c-muted); }
.menu-toggle svg { width: 20px; height: 20px; display: block; }
.menu-toggle:hover { background: #f3f4f6; }

.content { padding: 22px; flex: 1; }
.view { display: none; }
.view.active { display: block; }

/* ── Warning banner ── */
.col-warning {
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px;
  padding: 10px 14px; font-size: .82rem; color: #92400e; line-height: 1.5; margin-bottom: 16px;
}

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--c-border); border-radius: 12px; padding: 16px 18px; display: flex; align-items: center; gap: 12px; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1.2rem; }
.stat-icon.blue   { background: #eff3ff; color: #1a56db; }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }
.stat-icon.green  { background: #f0fdf4; color: #16a34a; }
.stat-icon.purple { background: #faf5ff; color: #9333ea; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--c-muted); margin-top: 2px; }

/* ── Cards ── */
.card { background: #fff; border: 1px solid var(--c-border); border-radius: 12px; overflow: hidden; }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--c-border-2); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: .92rem; font-weight: 600; }
.card-body { padding: 16px 18px; }

/* ── View toolbar ── */
.view-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 7px; background: #fff; border: 1px solid #d1d5db; border-radius: 8px; padding: 7px 11px; flex: 1; max-width: 320px; }
.search-box svg { width: 15px; height: 15px; color: var(--c-faint); flex-shrink: 0; }
.search-box input { border: none; outline: none; font-size: .875rem; background: transparent; width: 100%; }
.sort-select { border: 1px solid #d1d5db; border-radius: 8px; padding: 7px 10px; font-size: .82rem; background: #fff; cursor: pointer; color: #374151; outline: none; }
.sort-select:focus { border-color: var(--c-primary); }
.toolbar-spacer { flex: 1; }

/* ── Item Cards (Richtlinien-Liste) ── */
.item-cards { display: flex; flex-direction: column; gap: 8px; }
.item-card { background: #fff; border: 1px solid var(--c-border); border-radius: 10px; padding: 14px 16px; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.item-card:hover { border-color: #a5b4fc; box-shadow: 0 2px 8px rgba(99,102,241,.08); }
.ic-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.ic-title { font-size: .95rem; font-weight: 600; flex: 1; min-width: 0; }
.ic-topright { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.ic-desc { font-size: .83rem; color: var(--c-muted); line-height: 1.45; margin-bottom: 8px; }
.ic-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 6px; }
.ic-tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: #f3f4f6; color: #374151; white-space: nowrap; }
.ic-tag.cat { background: #eff3ff; color: #3730a3; }
.ic-footer { display: flex; align-items: center; gap: 8px; font-size: .73rem; color: var(--c-faint); }
.ic-footer .grow { flex: 1; }

/* ── Status Badge ── */
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .73rem; font-weight: 600; white-space: nowrap; }
.sb-open      { background: #fff7ed; color: #c2410c; }       /* Offen */
.sb-read      { background: #eff6ff; color: #1d4ed8; }       /* Gelesen, Quiz offen */
.sb-done      { background: #f0fdf4; color: #15803d; }       /* Abgeschlossen */
.sb-draft     { background: #f3f4f6; color: #4b5563; }       /* Entwurf */
.sb-review    { background: #fefce8; color: #a16207; }       /* InReview */
.sb-published { background: #ecfdf5; color: #047857; }       /* Veröffentlicht */
.sb-archived  { background: #f1f5f9; color: #64748b; }       /* Archiviert */

/* ── Progress bar ── */
.progress { height: 8px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--c-primary); border-radius: 999px; transition: width .3s; }
.progress.done > span { background: var(--c-success); }

/* ── Buttons ── */
.btn { padding: 8px 16px; border-radius: 7px; font-size: .85rem; font-weight: 600; border: none; cursor: pointer; transition: all .13s; display: inline-flex; align-items: center; gap: 5px; font-family: inherit; white-space: nowrap; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-d); }
.btn-success { background: var(--c-success); color: #fff; }
.btn-success:hover { background: var(--c-success-d); }
.btn-ghost   { background: #f3f4f6; color: #374151; }
.btn-ghost:hover { background: #e5e7eb; }
.btn-outline { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-outline:hover:not(:disabled) { background: #f9fafb; }
.btn-danger  { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn-lg { padding: 11px 22px; font-size: .92rem; }
.btn:disabled, button:disabled { opacity: .42; cursor: not-allowed; }

/* ── Form ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1/-1; }
.form-group label { font-size: .8rem; font-weight: 600; color: #374151; display: flex; align-items: center; gap: 5px; }
.form-group input, .form-group select, .form-group textarea {
  border: 1px solid #d1d5db; border-radius: 7px; padding: 8px 11px; font-size: .875rem;
  font-family: inherit; background: #fff; color: var(--c-text);
  transition: border-color .15s, box-shadow .15s; outline: none; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
.form-group textarea { resize: vertical; min-height: 64px; }
.req { color: var(--c-danger); }
.field-hint { font-size: .74rem; color: var(--c-muted); }

/* ── Rollen-Chips (Einstellungen) ── */
.ur-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  border: 1.5px solid var(--c-border); background: #f9fafb;
  color: #4b5563; font-size: .8rem; font-weight: 500;
  cursor: pointer; user-select: none; position: relative;
}
.ur-chip:hover { border-color: #9ca3af; }
.ur-chip.on { border-color: var(--c-primary); background: var(--c-primary-l); color: var(--c-primary); }

/* ── Detail / Reader ── */
.back-btn { margin-bottom: 14px; }
.detail-header { margin-bottom: 16px; }
.detail-header h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; }
.detail-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

/* ── Document preview ── */
.doc-frame-wrap { background: #fff; border: 1px solid var(--c-border); border-radius: 12px; overflow: hidden; }
.doc-frame-head { padding: 10px 16px; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.doc-frame-head .t { font-size: .82rem; font-weight: 600; color: #374151; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-frame { width: 100%; height: 70vh; min-height: 480px; border: none; display: block; background: #f8fafc; }
.doc-loading { padding: 40px; text-align: center; color: var(--c-muted); font-size: .9rem; }

/* ── Acknowledge / completion card ── */
.ack-card { background: #fff; border: 1px solid var(--c-border); border-radius: 12px; padding: 18px; }
.ack-step { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--c-border-2); }
.ack-step:last-child { border-bottom: none; }
.ack-dot { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: .78rem; font-weight: 700; background: #f3f4f6; color: #9ca3af; }
.ack-dot.ok { background: #dcfce7; color: #15803d; }
.ack-dot.active { background: #dbeafe; color: #1d4ed8; }
.ack-step-body { flex: 1; }
.ack-step-body .t { font-size: .88rem; font-weight: 600; }
.ack-step-body .s { font-size: .78rem; color: var(--c-muted); margin-top: 2px; line-height: 1.45; }
.ack-step-body .actions { margin-top: 10px; }
.ack-check { display: flex; align-items: flex-start; gap: 9px; font-size: .85rem; color: #374151; line-height: 1.45; cursor: pointer; }
.ack-check input { margin-top: 3px; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--c-primary); }

/* ── Quiz ── */
.quiz-wrap { max-width: 720px; margin: 0 auto; }
.quiz-progress { font-size: .8rem; color: var(--c-muted); margin-bottom: 10px; }
.quiz-q { background: #fff; border: 1px solid var(--c-border); border-radius: 12px; padding: 20px; margin-bottom: 14px; }
.quiz-q-title { font-size: 1rem; font-weight: 600; margin-bottom: 14px; line-height: 1.5; }
.quiz-q-num { color: var(--c-primary); font-weight: 700; margin-right: 6px; }
.quiz-opt { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border: 2px solid var(--c-border); border-radius: 9px; margin-bottom: 8px; cursor: pointer; transition: border-color .12s, background .12s; font-size: .9rem; }
.quiz-opt:hover { border-color: #a5b4fc; background: #f9fafb; }
.quiz-opt input { margin-top: 2px; accent-color: var(--c-primary); width: 16px; height: 16px; flex-shrink: 0; }
.quiz-opt.sel { border-color: var(--c-primary); background: var(--c-primary-l); }
.quiz-opt.correct  { border-color: #16a34a; background: #f0fdf4; }
.quiz-opt.wrong    { border-color: #ef4444; background: #fef2f2; }
.quiz-result { text-align: center; padding: 30px 20px; }
.quiz-result .big { font-size: 2.4rem; font-weight: 800; margin-bottom: 6px; }
.quiz-result.pass .big { color: var(--c-success); }
.quiz-result.fail .big { color: var(--c-danger); }
.quiz-result .msg { font-size: .95rem; color: var(--c-muted); margin-bottom: 18px; }

/* ── Quiz editor (admin) ── */
.qe-item { border: 1px solid var(--c-border); border-radius: 10px; padding: 14px; margin-bottom: 10px; background: #fafbfc; }
.qe-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.qe-head .t { font-size: .8rem; font-weight: 700; color: var(--c-muted); }
.qe-opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.qe-opt-row input[type=radio] { accent-color: var(--c-success); width: 16px; height: 16px; flex-shrink: 0; }
.qe-opt-row input[type=text] { flex: 1; border: 1px solid #d1d5db; border-radius: 6px; padding: 6px 9px; font-size: .84rem; font-family: inherit; }

/* ── Table (Compliance) ── */
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tbl th { text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--c-faint); padding: 9px 12px; border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--c-border-2); }
.tbl tr:hover td { background: #f9fafb; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.quote-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-weight: 700; font-size: .78rem; }
.quote-hi { background: #f0fdf4; color: #15803d; }
.quote-mid { background: #fefce8; color: #a16207; }
.quote-lo { background: #fef2f2; color: #b91c1c; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #fff; border-radius: 13px; width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal.wide { max-width: 820px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #f3f4f6; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--c-faint); padding: 2px 6px; border-radius: 4px; line-height: 1; }
.modal-close:hover { background: #f3f4f6; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #f3f4f6; display: flex; gap: 7px; justify-content: flex-end; flex-shrink: 0; }

/* ── Document picker (admin) ── */
.dp-list { border: 1px solid var(--c-border); border-radius: 9px; overflow: hidden; max-height: 320px; overflow-y: auto; }
.dp-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--c-border-2); cursor: pointer; font-size: .85rem; }
.dp-row:last-child { border-bottom: none; }
.dp-row:hover { background: #f9fafb; }
.dp-row.sel { background: var(--c-primary-l); }
.dp-row .ic { flex-shrink: 0; }
.dp-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-row.folder .nm { font-weight: 600; }
.dp-crumbs { font-size: .8rem; color: var(--c-muted); margin-bottom: 10px; display: flex; gap: 5px; flex-wrap: wrap; }
.dp-crumbs a { cursor: pointer; color: var(--c-primary); }

/* ── Empty state ── */
.empty-state { padding: 44px 20px; text-align: center; color: var(--c-faint); }
.empty-state .icon { font-size: 2.4rem; margin-bottom: 10px; opacity: .5; }
.empty-state p { font-size: .9rem; }

/* ── Toast ── */
#toast-c { position: fixed; bottom: 22px; right: 22px; z-index: 4000; display: flex; flex-direction: column; gap: 7px; }
.toast { background: #1e2939; color: #fff; padding: 11px 16px; border-radius: 9px; font-size: .85rem; font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,.22); display: flex; align-items: center; gap: 8px; animation: toastIn .22s ease; max-width: 320px; transition: opacity .26s, transform .26s; }
.toast.success { background: #166534; }
.toast.error   { background: #991b1b; }
.toast.out     { opacity: 0; transform: translateY(10px); }
@keyframes toastIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:none; } }

/* ── Sync-Hinweis (beim Reiter-Wechsel / Aktualisieren) ── */
.sync-hint {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 8000; background: #1e2939; color: #fff;
  padding: 7px 15px; border-radius: 999px;
  font-size: .82rem; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
  display: flex; align-items: center; gap: 8px;
  animation: toastIn .18s ease;
}
.sync-spinner {
  width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite; flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.15); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .form-grid { grid-template-columns: 1fr; }
}

/* Deeplink aus Erinnerungs-Mail: Karte kurz hervorheben */
.item-card.fg-highlight {
  animation: fgPulse 1.5s ease-in-out 3;
  border-color: #1a56db;
}
@keyframes fgPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(26,86,219,0); }
  50% { box-shadow: 0 0 0 4px rgba(26,86,219,.28); }
}
