:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #dfe3ea;
  --text: #1f2733;
  --muted: #6b7787;
  --primary: #00549f;        /* RWTH-Blau */
  --primary-dark: #003d75;
  --accent: #57ab27;
  --danger: #cc3311;
  --danger-bg: #fdecea;
  --warn: #b8860b;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 28px; }
.brand h1 { font-size: 18px; }
.brand .subtitle { margin: 0; font-size: 12px; color: var(--muted); }
.session { display: flex; align-items: center; gap: 12px; }
.lang-select {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
}
.lang-select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

/* ---- Layout ---- */
#main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
#view-login { max-width: 520px; margin: 40px auto; }
#view-login h2 { margin-bottom: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 14px 0; }
.field span { font-size: 13px; color: var(--muted); }
input[type=text], input[type=url], input[type=password] {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }

.row { display: flex; gap: 10px; margin-top: 8px; }

/* ---- Buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: #f2f5f9; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: #eef1f5; color: var(--text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn.success { color: var(--accent); border-color: var(--accent); }
.btn.success:hover:not(:disabled) { background: #eef7e8; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- Notices / errors ---- */
.notice {
  display: flex; align-items: center; gap: 12px;
  background: #eef4fb; border: 1px solid #cfe0f2;
  padding: 12px 14px; border-radius: 8px; margin-top: 16px;
}
.notice.small { padding: 8px 12px; }
.error { color: var(--danger); background: var(--danger-bg); padding: 10px 12px; border-radius: 8px; margin-top: 12px; }
.how-it-works {
  margin: 14px 0; border: 1px solid var(--primary); border-radius: 8px;
  overflow: hidden;
}
.how-it-works > summary {
  cursor: pointer; padding: 10px 14px; font-weight: 600; color: #fff;
  background: var(--primary); list-style: none;
}
.how-it-works > summary::-webkit-details-marker { display: none; }
.how-it-works > summary::before { content: '▸ '; }
.how-it-works[open] > summary::before { content: '▾ '; }
.how-it-works > summary:hover { background: var(--primary-dark); }
.how-body { padding: 12px 14px; font-size: 13px; line-height: 1.55; }
.how-body p { margin: 0 0 10px; }
.how-body p:last-child { margin-bottom: 0; }
.how-good {
  background: #edf7ec; border-left: 3px solid var(--accent);
  padding: 8px 10px; border-radius: 4px;
}
.how-warn {
  background: #fdf0ec; border-left: 3px solid var(--danger);
  padding: 8px 10px; border-radius: 4px;
}
#login-waiting { align-items: flex-start; }
.waiting-body { width: 100%; }
.fallback-block { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.fallback-block .steps-hint { margin-top: 0; }
#show-fallback { color: var(--primary); font-weight: 500; }
.steps-hint {
  background: #fff7e6; border: 1px solid #f0d9a8; color: #6b5320;
  padding: 10px 12px; border-radius: 8px; margin: 14px 0; font-size: 13px; line-height: 1.5;
}
.steps-row { flex-wrap: wrap; }
.alt-login { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 12px; }
.alt-login summary { cursor: pointer; color: var(--primary); font-weight: 500; }

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2.5px solid #cfe0f2; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Workspace ---- */
.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.3fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) { .workspace { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 480px;
  max-height: calc(100vh - 140px);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 15px; }
.panel-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; border-bottom: 1px solid var(--border); background: #fafbfc;
}
.tree-actions { justify-content: flex-start; gap: 8px; }
/* Info-Balken beim Sammeln – gleiche Optik wie die Baum-Toolbar */
.collect-bar { justify-content: flex-start; gap: 10px; }
.collect-bar #collect-status-text { font-size: 13px; color: var(--muted); }
.panel-foot {
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.apply-foot { justify-content: space-between; align-items: center; }
.collect-foot { justify-content: space-between; align-items: center; gap: 12px; }
.collect-foot .checkbox { flex: 1; }

.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.checkbox.inline { font-size: 13px; }

/* ---- Tree ---- */
.tree { flex: 1; overflow: auto; padding: 8px 6px; }
.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px; border-radius: 6px; cursor: default;
}
.tree-row:hover { background: #f2f5f9; }
.tree-row .twisty {
  width: 18px; height: 18px; flex: none; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
  color: var(--muted); font-size: 11px; border-radius: 4px;
}
.tree-row .twisty:hover { background: #e5e9ef; }
.tree-row .twisty.leaf { visibility: hidden; }
/* Tri-State-Checkbox */
.tree-row .tri-check {
  flex: none; width: 17px; height: 17px; border-radius: 4px;
  border: 1.5px solid #b6becb; background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative;
}
.tree-row .tri-check::after {
  content: ''; display: none;
  width: 5px; height: 9px; margin-top: -2px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.tree-row .tri-check.checked { background: var(--primary); border-color: var(--primary); }
.tree-row .tri-check.checked::after { display: block; }
.tree-row .tri-check.partial { background: #9aa4b2; border-color: #9aa4b2; }
.tree-row .tri-check.partial::after { display: block; }
.tree-row .tri-check:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.tree-row .icon { flex: none; }
.tree-row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .badge {
  flex: none; font-size: 11px; color: var(--muted);
  background: #eef1f5; padding: 0 6px; border-radius: 10px;
}
.tree-row.file .label { color: #334; }
.tree-children { margin-left: 18px; border-left: 1px dashed var(--border); }
.tree-loading { padding: 4px 10px; color: var(--muted); font-size: 12px; }
.tree-empty { padding: 4px 10px; color: var(--muted); font-size: 12px; font-style: italic; }

/* ---- Accounts ---- */
.accounts-body { flex: 1; display: flex; overflow: hidden; }
.accounts-list { width: 46%; overflow: auto; border-right: 1px solid var(--border); padding: 6px; }
.account-detail { flex: 1; overflow: auto; padding: 12px 14px; }
.empty { text-align: center; padding: 30px 10px; }

.account-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.account-item:hover { background: #f2f5f9; }
.account-item.active { background: #e7f0fa; }
.account-item .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--primary); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 600;
}
.account-item .avatar.link { background: var(--warn); }
.account-item .avatar.group { background: #6b47b8; }
.account-item .a-main { flex: 1; overflow: hidden; }
.account-item .a-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item .a-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item .a-count { font-size: 11px; color: var(--muted); background: #eef1f5; padding: 1px 7px; border-radius: 10px; }
.account-item.has-changes .a-count { background: #fff3d6; color: var(--warn); }

/* Detail */
.detail-head { margin-bottom: 12px; }
.detail-head h3 { font-size: 16px; word-break: break-all; }
.detail-head .type-tag {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px;
  background: #eef1f5; color: var(--muted); margin-top: 4px;
}
.share-card {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px;
}
.share-card.to-delete { opacity: .55; background: var(--danger-bg); border-color: #f3c6bf; }
.share-card.modified { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn) inset; }
.share-path { display: flex; align-items: center; gap: 6px; font-weight: 500; word-break: break-all; }
.share-path .icon { flex: none; }
.share-meta { font-size: 11px; color: var(--muted); margin: 2px 0 8px; }
/* Sammel-Feld "Rechte fuer alle Ordner einstellen" */
.master-perm {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 12px; background: #f7f9fc;
}
.master-perm.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.master-head { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.master-check { color: var(--accent); font-weight: 700; }
.dimmed { opacity: .4; }

.perm-grid { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 8px; }
.perm-grid label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }
.perm-grid label.disabled { opacity: .4; cursor: not-allowed; }
.share-actions { display: flex; justify-content: space-between; align-items: center; }
.perm-summary { font-size: 11px; color: var(--muted); }
.changed-flag { color: var(--warn); font-weight: 500; }

.detail-placeholder { color: var(--muted); text-align: center; padding: 40px 10px; }

.detail-hint {
  font-size: 12px; color: var(--muted); background: #f2f5f9;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; margin-bottom: 12px; line-height: 1.5;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-box {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.3);
  width: 100%; max-width: 520px; max-height: 85vh; overflow: auto; padding: 20px 22px;
}
.modal-box h3 { font-size: 17px; margin-bottom: 12px; }
.modal-body { font-size: 14px; }
.modal-section { font-weight: 600; margin: 12px 0 4px; }
.modal-list { margin: 0 0 8px; padding-left: 18px; }
.modal-list li { margin-bottom: 6px; }
.danger-text { color: var(--danger); }
.danger-list li { color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-solid:hover:not(:disabled) { background: #a82a0e; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 100; max-width: 90vw;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--accent); }

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181e; --panel: #1c222b; --border: #2c333e;
    --text: #e6eaf0; --muted: #94a0b0; --primary: #3a8fd6; --primary-dark: #2f74af;
    --danger-bg: #3a1e1a;
  }
  input[type=text], input[type=url], input[type=password] { background: #131820; }
  .lang-select { background: #131820; }
  .panel-actions { background: #171d25; }
  .master-perm { background: #1a2029; }
  .steps-hint { background: #2b2413; border-color: #4a3d1c; color: #d8c58c; }
  .how-good { background: #16241a; }
  .how-warn { background: #2a1a16; }
  .detail-hint { background: #171d25; }
  .btn.success:hover:not(:disabled) { background: #16241a; }
  .tree-row .tri-check { background: #131820; border-color: #3a4552; }
  .tree-row .tri-check.checked { background: var(--primary); border-color: var(--primary); }
  .tree-row .tri-check.partial { background: #58657a; border-color: #58657a; }
  .tree-row:hover, .account-item:hover { background: #232b36; }
  .account-item.active { background: #223247; }
  .tree-row .badge, .account-item .a-count, .detail-head .type-tag { background: #2a323d; }
}
