/*
 * Dateien - monochrome.
 *
 * Structure is inherited from GRATICULE (sharp corners, hairlines instead of
 * borders, no shadows, Archivo + JetBrains Mono, the app's own scrollbar), but
 * the palette is pure greyscale: there is no hue anywhere. Emphasis is carried
 * by luminance alone, which means the scale has to do all the work - hence the
 * deliberate gaps between --text-muted, --text-secondary and --text-primary.
 *
 * White is the accent. It is expensive, so it is spent only on the active nav
 * item, the primary button and focus rings.
 */

:root {
  color-scheme: dark;

  /* Echte Neutralgrautoene: R = G = B, kein Stich in irgendeine Richtung. */
  --canvas: #0a0a0a;
  --panel: #131313;
  --panel-header: #0f0f0f;
  --well: #0e0e0e;
  --hairline: #262626;
  --rule-strong: #3d3d3d;
  --band: #1c1c1c;

  --text-primary: #f2f2f2;
  --text-secondary: #a8a8a8;
  --text-muted: #757575;

  --accent: #ffffff;
  --accent-ink: #0a0a0a;

  --radius: 0px;
  --control-radius: 2px;

  --row-h: 34px;
  --pad: 16px;
  --side-w: 232px;
  --top-h: 52px;

  --font-sans: "Archivo", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;

    --canvas: #f4f4f4;
    --panel: #ffffff;
    --panel-header: #fafafa;
    --well: #f7f7f7;
    --hairline: #e1e1e1;
    --rule-strong: #c4c4c4;
    --band: #ececec;

    --text-primary: #111111;
    --text-secondary: #575757;
    --text-muted: #868686;

    --accent: #111111;
    --accent-ink: #ffffff;
  }
}

/*
 * Before the layout rules: a bare `display: flex/grid` on a selector outranks
 * the user agent's `[hidden] { display: none }`, which would leave every hidden
 * view painted on top of the visible one.
 */
[hidden] { display: none !important; }

/* Aus demselben Grund: ein geschlossener Dialog ist per Voreinstellung
   display:none, und ein eigenes display:flex weiter unten wuerde ihn sonst
   dauerhaft sichtbar machen. */
dialog:not([open]) { display: none !important; }

* {
  box-sizing: border-box;
  border-color: var(--hairline);
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--rule-strong);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 0;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-muted); }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }

/*
 * Markieren nur dort, wo Text auch gemeint ist. Sonst faerbt jeder Doppelklick
 * auf eine Zeile die Beschriftung blau ein, und das Ziehen von Dateien beginnt
 * mit einer versehentlichen Textauswahl.
 */
body { user-select: none; -webkit-user-select: none; }
#f-text, #f-info, .pth, .mono, input, textarea, .titel, dialog pre {
  user-select: text;
  -webkit-user-select: text;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
}

::selection { background: var(--band); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

.mono, code, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.spacer { flex: 1; }
.hint { color: var(--text-muted); font-size: 12.5px; }

/* --- shell ---------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
}

nav.side {
  border-right: 1px solid var(--hairline);
  background: var(--panel-header);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.side .brand {
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--hairline);
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: none;
}
.side .brand img { border-radius: 2px; flex: none; }

.side .group { padding: 14px 0 6px; }
.side .group > .eyebrow { padding: 0 var(--pad) 6px; display: block; }

.navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 32px;
  padding: 0 var(--pad);
  background: none;
  border: 0;
  color: var(--text-secondary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.navitem:hover { background: var(--band); color: var(--text-primary); }
.navitem[aria-current="true"] {
  color: var(--text-primary);
  background: var(--band);
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Zwei Achsen, zwei Staerken: oben steht, WAS man ansieht (Dateien, Papierkorb,
   Verwaltung), unten WO man ist. Beide gleich zu betonen sah aus wie ein
   Fehler - der Ort bekommt deshalb nur den Balken, nicht die Flaeche. */
#areas .navitem[aria-current="true"] {
  background: none;
  color: var(--text-primary);
  box-shadow: inset 2px 0 0 var(--rule-strong);
}
#areas .navitem[aria-current="true"] svg { color: var(--text-primary); }
.navitem .mark {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  width: 1.4em;
}
.navitem[aria-current="true"] .mark { color: var(--text-primary); }
.navitem .ro { margin-left: auto; font-size: 10.5px; color: var(--text-muted); }
.navitem .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side .foot {
  margin-top: auto;
  border-top: 1px solid var(--hairline);
  padding: 10px var(--pad);
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.side .foot .who { min-width: 0; }
.side .foot .who div:first-child {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- content -------------------------------------------------------------- */

.content { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--top-h);
  border-bottom: 1px solid var(--hairline);
  background: var(--panel-header);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--pad);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.body { padding: var(--pad); }

.panel {
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.panel > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px var(--pad);
  background: var(--panel-header);
  border-bottom: 1px solid var(--hairline);
}
.panel > .inner { padding: var(--pad); }

/* --- breadcrumb ----------------------------------------------------------- */

.crumbs { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; min-width: 0; }
.crumbs button {
  background: none;
  border: 0;
  padding: 2px 3px;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
}
.crumbs button:last-of-type { color: var(--text-primary); }
.crumbs button:hover { color: var(--text-primary); text-decoration: underline; }
.crumbs .sep { color: var(--text-muted); font-family: var(--font-mono); }

/* --- tables --------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 8px var(--pad);
  border-bottom: 1px solid var(--hairline);
  background: var(--panel-header);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
th.right, td.right { text-align: right; }

td {
  height: var(--row-h);
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--hairline);
  color: var(--text-secondary);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--well); }
tbody tr.klickbar { cursor: pointer; }
tbody tr[aria-selected="true"] { background: var(--band); }
tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

td.name { color: var(--text-primary); width: 100%; }
td.name button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  max-width: 60ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}
td.name button:hover { text-decoration: underline; }
.glyph {
  color: var(--text-muted);
  margin-right: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.rowacts { display: flex; gap: 2px; justify-content: flex-end; opacity: 0; }
tr:hover .rowacts, tr:focus-within .rowacts { opacity: 1; }

/* --- controls ------------------------------------------------------------- */

button.btn, label.btn, a.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--text-primary);
  border: 1px solid var(--rule-strong);
  border-radius: var(--control-radius);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
button.btn:hover, label.btn:hover, a.btn:hover { background: var(--band); border-color: var(--text-muted); }

button.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
}
button.btn.primary:hover { filter: brightness(0.92); background: var(--accent); }

button.btn.ghost {
  border-color: transparent;
  background: none;
  color: var(--text-muted);
  height: 24px;
  padding: 0 6px;
  font-size: 12.5px;
}
button.btn.ghost:hover { color: var(--text-primary); background: var(--band); }
button.btn.danger:hover { color: var(--text-primary); border-color: var(--text-primary); background: none; text-decoration: line-through; }
button.btn:disabled { opacity: 0.4; cursor: not-allowed; }

input[type="text"], input[type="password"], select {
  height: 28px;
  padding: 0 8px;
  background: var(--canvas);
  color: var(--text-primary);
  border: 1px solid var(--rule-strong);
  border-radius: var(--control-radius);
  font: inherit;
  font-size: 13px;
  min-width: 0;
}
input::placeholder { color: var(--text-muted); }
select { cursor: pointer; }

/* --- tags ----------------------------------------------------------------- */

.tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 6px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--control-radius);
  color: var(--text-muted);
  white-space: nowrap;
}
.tag.strong { color: var(--text-primary); border-color: var(--text-primary); }

/* --- admin ---------------------------------------------------------------- */

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr);
  gap: var(--pad);
  align-items: start;
}
@media (max-width: 1080px) { .admin-grid { grid-template-columns: minmax(0, 1fr); } }

.detail-empty { padding: 48px var(--pad); text-align: center; color: var(--text-muted); }

.kv {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 6px 12px;
  align-items: center;
  padding: var(--pad);
  border-bottom: 1px solid var(--hairline);
}
.kv > .k { color: var(--text-muted); font-size: 12.5px; }

.grantlist { border-bottom: 1px solid var(--hairline); }
.grantrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px var(--pad);
  border-bottom: 1px solid var(--hairline);
}
.grantrow:last-child { border-bottom: 0; }
.grantrow .lbl { color: var(--text-primary); }
.grantrow .pth {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.grantform { padding: var(--pad); display: grid; gap: 8px; }
.grantform .row { display: flex; gap: 8px; }
.grantform .row > * { min-width: 0; }
.grantform input { width: 100%; }

/* --- Dateibrowser --------------------------------------------------------- */

.files th[data-key] { cursor: pointer; user-select: none; }
.files th[data-key]:hover { color: var(--text-secondary); }
.files th .arrow { font-family: var(--font-mono); margin-left: 2px; }
.files th[aria-sort="none"] .arrow { opacity: 0; }

.files td.name button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.files .glyph { color: var(--text-muted); display: flex; flex: none; margin: 0; }
.files .glyph.dir { color: var(--text-secondary); }
.files tr:hover .glyph { color: var(--text-primary); }
.files .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files td.size { color: var(--text-muted); }
.files tr.up td { color: var(--text-muted); }
.files tr.up .glyph { font-family: var(--font-mono); }

/* Ziehen und Ablegen */
.dropzone { position: relative; }
.dropveil {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--canvas) 82%, transparent);
  border: 1px dashed var(--text-muted);
  pointer-events: none;
}
.dropzone.dragging .dropveil { display: grid; }
.dropveil span { color: var(--text-primary); font-size: 13px; }

/* --- Speicheranzeige ------------------------------------------------------ */

.platte { padding: var(--pad); margin-bottom: var(--pad); }
.platte .line { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }

.quota { padding: 10px var(--pad); border-top: 1px solid var(--hairline); }
.quota .line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.bar { height: 3px; background: var(--band); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--text-secondary); }
.bar.voll > i { background: var(--text-primary); }

/* --- Ordnerauswahl -------------------------------------------------------- */

dialog header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--pad);
  background: var(--panel-header);
  border-bottom: 1px solid var(--hairline);
}
dialog footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--pad);
  border-top: 1px solid var(--hairline);
  background: var(--panel-header);
}

#picker { width: min(92vw, 620px); }
.crumbs.pick { padding: 8px var(--pad); border-bottom: 1px solid var(--hairline); }
.picklist { max-height: 46vh; overflow: auto; }
.pickitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px var(--pad);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  color: var(--text-secondary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pickitem:last-child { border-bottom: 0; }
.pickitem:hover { background: var(--band); color: var(--text-primary); }
.pickitem svg { color: var(--text-muted); flex: none; }

/* --- Freischalten --------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  height: 26px;
  padding: 0 10px;
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-radius: var(--control-radius);
  color: var(--text-primary);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.chip:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip:disabled { opacity: 0.35; cursor: default; text-decoration: line-through; }

.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 14px; height: 14px; }

.grantrow svg { color: var(--text-muted); flex: none; }
.grantrow.empty-hint { color: var(--text-muted); }

.quotaform { display: flex; align-items: center; gap: 8px; }
.quotaform input { width: 84px; text-align: right; }

/* --- Mehrfachauswahl und Zurueck ------------------------------------------ */

.nav-back {
  font-family: var(--font-mono);
  font-size: 15px;
  width: 28px;
  padding: 0;
  justify-content: center;
  flex: none;
}
.nav-back:disabled { opacity: 0.3; }

th.pick, td.pick { width: 34px; padding-right: 0; }
th.pick input, td.pick input {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
}
tbody tr.gewaehlt { background: var(--band); }
tbody tr.gewaehlt td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

.auswahlleiste {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px var(--pad);
  border-bottom: 1px solid var(--hairline);
  background: var(--band);
  font-size: 13px;
}

/* --- Dateifenster: ansehen und bearbeiten --------------------------------- */

#fenster {
  width: 92vw;
  height: 88vh;
  max-width: none;
  max-height: none;
  display: flex;
  flex-direction: column;
  padding: 0;
}
#fenster[open] { display: flex; }
#fenster header { flex: none; }
#fenster footer { flex: none; }

.dirty {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
  border: 1px solid var(--text-muted);
  border-radius: var(--control-radius);
  padding: 1px 6px;
}

.editor {
  flex: 1;
  min-height: 0;
  display: flex;
  background: var(--well);
  overflow: hidden;
}

.gutter {
  flex: none;
  padding: 12px 10px 12px 14px;
  text-align: right;
  color: var(--text-muted);
  background: var(--panel-header);
  border-right: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  overflow: hidden;
  user-select: none;
  white-space: pre;
}

#f-text {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  background: none;
  border: 0;
  outline: none;
  resize: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  tab-size: 2;
  overflow: auto;
}
#f-text.wrap { white-space: pre-wrap; word-break: break-word; }

.bildansicht {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: var(--pad);
  background: var(--well);
  background-image:
    linear-gradient(45deg, var(--band) 25%, transparent 25%),
    linear-gradient(-45deg, var(--band) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--band) 75%),
    linear-gradient(-45deg, transparent 75%, var(--band) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  overflow: auto;
}
.bildansicht img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* --- eigene Rückfrage ------------------------------------------------------ */

#frage { width: min(92vw, 420px); }
.frage-inhalt { padding: var(--pad); display: grid; gap: 10px; }
.frage-inhalt p { margin: 0; line-height: 1.5; }
.frage-inhalt input { width: 100%; height: 32px; }
#frage .betont { color: var(--text-primary); font-weight: 500; }

/* --- eigenes Rechtsklickmenü ---------------------------------------------- */

.ctx {
  position: fixed;
  z-index: 100;
  min-width: 190px;
  padding: 4px 0;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: var(--control-radius);
}
.ctx button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 12px;
  background: none;
  border: 0;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.ctx button:hover { background: var(--band); color: var(--text-primary); }
.ctx button:disabled { opacity: 0.35; cursor: default; }
.ctx button:disabled:hover { background: none; color: var(--text-secondary); }
.ctx .kbd { margin-left: auto; color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; }
.ctx hr { margin: 4px 0; border: 0; border-top: 1px solid var(--hairline); }
.ctx .titel {
  padding: 4px 12px 6px;
  color: var(--text-muted);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- auth ----------------------------------------------------------------- */

.auth { max-width: 360px; margin: 12vh auto; padding: var(--pad); }
.auth .marke {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-left: 2px;
}
.auth .marke img { border-radius: var(--control-radius); }
.auth .marke .wort { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.auth .fuss { margin: 14px 2px 0; line-height: 1.5; }
.auth .tabs { display: flex; border-bottom: 1px solid var(--hairline); }
.auth .tabs button {
  flex: 1;
  padding: 11px;
  background: var(--panel-header);
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}
.auth .tabs button[aria-selected="true"] {
  background: var(--panel);
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}
.auth .inner { display: grid; gap: 12px; }
.auth label { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-secondary); }
.auth input { width: 100%; height: 32px; }
.auth .btn.primary { height: 32px; justify-content: center; }

/* --- misc ----------------------------------------------------------------- */

.empty { padding: 48px var(--pad); text-align: center; color: var(--text-muted); }

.msg {
  padding: 9px var(--pad);
  border-left: 2px solid var(--text-muted);
  background: var(--well);
  color: var(--text-primary);
  font-size: 13px;
}
.msg.ok { border-left-color: var(--accent); }

dialog {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text-primary);
  padding: 0;
  max-width: min(92vw, 900px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.66); }
dialog pre {
  margin: 0;
  padding: var(--pad);
  overflow: auto;
  max-height: 58vh;
  background: var(--well);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  nav.side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--hairline); }
  .side .foot { margin-top: 0; }
}
