/* ARGOS-App - schlichtes Grundgeruest, keine externen Abhaengigkeiten */

/* Diese Vorgabewerte muessen mit THEME_DEFAULTS in app.py uebereinstimmen. */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --sidebar: #ffffff;
  --sidebar-ink: #1d2125;
  --ink: #1d2125;
  --ink-soft: #5c6771;
  --line: #dfe3e8;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --radius: 8px;

  /* Linien und Hover-Flaechen innerhalb der Navigationsleiste leiten sich aus
     deren Schriftfarbe ab. Dadurch passen sie sich jeder eingestellten
     Hintergrundfarbe an, ohne dass es dafuer eigene Farbfelder braucht. */
  --sidebar-line: rgba(128, 128, 128, .35);
  --sidebar-hover: rgba(128, 128, 128, .18);
}

@supports (color: color-mix(in srgb, red 50%, transparent)) {
  :root {
    --sidebar-line: color-mix(in srgb, var(--sidebar-ink) 22%, transparent);
    --sidebar-hover: color-mix(in srgb, var(--sidebar-ink) 12%, transparent);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --panel: #1e2227;
    --sidebar: #1e2227;
    --sidebar-ink: #e8eaed;
    --ink: #e8eaed;
    --ink-soft: #9aa4ae;
    --line: #2e343b;
    --accent: #4a90c2;
    --accent-ink: #0f1215;
    --danger: #f2857c;
  }
}

* { box-sizing: border-box; }

/* Muss vor allen display-Regeln stehen und !important tragen: das
   hidden-Attribut setzt display:none nur im Browser-Stylesheet, jede eigene
   display-Angabe (.login-wrap, .shell) hat höhere Priorität und würde die
   ausgeblendete Ansicht sonst trotzdem zeigen. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

/* ------------------------------------------------------------ Anmeldung */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.card {
  width: 100%;
  max-width: 22rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
}

.brand {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: .16em;
  font-weight: 600;
}

.sub {
  margin: .25rem 0 1.75rem;
  color: var(--ink-soft);
}

label {
  display: block;
  margin-bottom: .35rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input {
  width: 100%;
  padding: .6rem .7rem;
  margin-bottom: 1.1rem;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  cursor: pointer;
}

#login-btn {
  width: 100%;
  padding: .65rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
}

#login-btn[disabled] { opacity: .6; cursor: default; }

.error {
  margin: 0 0 1rem;
  padding: .55rem .7rem;
  font-size: .88rem;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
}

.hint {
  margin: 1rem 0 0;
  font-size: .78rem;
  color: var(--ink-soft);
}

/* --------------------------------------------------------- App-Grundgeruest */

/* App-Shell: die Seite selbst scrollt nicht. Die Navigationsleiste steht fest,
   gescrollt wird nur der Inhaltsbereich - und bei zu vielen Menüpunkten die
   Menüliste innerhalb der Leiste. */
.shell {
  display: grid;
  grid-template-columns: 15rem 1fr;
  height: 100vh;
  height: 100dvh;             /* dvh wegen der Adressleiste auf Mobilgeräten */
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;              /* damit das Kind scrollen darf statt zu wachsen */
  overflow: hidden;
  color: var(--sidebar-ink);
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-line);
}

/* --- Kopfzeile: bleibt immer sichtbar --- */
.sidebar-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex: 0 0 auto;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--sidebar-line);
}

.brand-small {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .16em;
  white-space: nowrap;
}

.hamburger {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 6px;
}

.hamburger:hover { background: var(--sidebar-hover); }

/* --- Mitte: die Menüliste, scrollt bei Bedarf --- */
nav {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: .75rem .6rem;
}

nav button {
  display: flex;
  align-items: center;
  gap: .65rem;
  text-align: left;
  padding: .5rem .6rem;
  color: inherit;                 /* folgt --sidebar-ink */
  background: none;
  border: 0;
  border-radius: 6px;
  white-space: nowrap;
}

nav button:hover { background: var(--sidebar-hover); }

nav button[aria-current="page"] {
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
}

.icon {
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Eingeklappt: nur Icons --- */
.shell.collapsed { grid-template-columns: 3.75rem 1fr; }

.shell.collapsed .brand-small,
.shell.collapsed .label,
.shell.collapsed .who-text,
.shell.collapsed .pw-warn { display: none; }

.shell.collapsed .sidebar-head { justify-content: center; padding: .9rem .5rem; }

.shell.collapsed nav { padding: .75rem .5rem; }

.shell.collapsed nav button,
.shell.collapsed .who-btn,
.shell.collapsed #logout-btn { justify-content: center; padding: .5rem 0; }

.shell.collapsed .who { padding: .8rem .5rem; }

.shell.collapsed .who-btn { margin-left: 0; }

/* --- Fußzeile: bleibt immer sichtbar --- */
.who {
  flex: 0 0 auto;
  padding: .8rem 1rem;
  font-size: .85rem;
  border-top: 1px solid var(--sidebar-line);
}

/* Umschalter hell / dunkel / automatisch - steht in Einstellungen > Farbschema */
.mode-switch {
  display: inline-flex;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.mode-switch button {
  padding: .35rem 1rem;
  font-size: .82rem;
  color: var(--ink);
  opacity: .8;
  background: var(--panel);
  border: 0;
  border-left: 1px solid var(--line);
}

.mode-switch button:first-child { border-left: 0; }

.mode-switch button:hover { background: var(--bg); opacity: 1; }

.mode-switch button[aria-pressed="true"] {
  font-weight: 600;
  opacity: 1;
  color: var(--accent-ink);
  background: var(--accent);
}

/* Der eigene Name ist der Zugang zu den persönlichen Einstellungen */
.who-btn {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .4rem .5rem;
  margin: 0 0 .4rem -.5rem;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 6px;
}

.who-text { min-width: 0; }

.who-btn:hover { background: var(--sidebar-hover); }

.who-btn:hover #who-name { text-decoration: underline; }

.who-btn[aria-current="page"] { background: var(--sidebar-hover); font-weight: 600; }

.who-btn #who-name { display: block; }

.pw-warn {
  margin: 0 0 .5rem;
  font-size: .78rem;
  color: var(--danger);
}

.role-badge {
  display: inline-block;
  margin: .3rem 0 .5rem;
  padding: .05rem .45rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: inherit;
  opacity: .7;
  border: 1px solid var(--sidebar-line);
  border-radius: 99px;
}

/* "Abmelden" - erbt die Schriftfarbe der Leiste statt --accent, damit es auch
   bei einem Navigationshintergrund in Akzentfarbe lesbar bleibt. */
.link {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: 0;
  color: inherit;
  background: none;
  border: 0;
}

.link .label { text-decoration: underline; }

/* Der einzige senkrechte Scrollbereich der Anwendung */
.content {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  padding: 1.75rem 2rem;
}

.content-head { border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }

.content-head h2 { margin: 0 0 1rem; font-size: 1.25rem; font-weight: 600; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.panel h3 { margin: 0 0 .5rem; font-size: .95rem; }

.panel p { margin: 0; color: var(--ink-soft); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.tile .value { font-size: 1.7rem; font-weight: 600; }

.tile .label { font-size: .8rem; color: var(--ink-soft); }

table { width: 100%; border-collapse: collapse; font-size: .86rem; }

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

th { color: var(--ink-soft); font-weight: 600; }

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

/* ------------------------------------------------- Verwaltung / Formulare */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0 1rem;
  margin-bottom: .5rem;
}

textarea {
  width: 100%;
  padding: .6rem .7rem;
  margin-bottom: 1.1rem;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  resize: vertical;
}

.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.panel button[type="submit"] {
  padding: .5rem 1rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
}

button.mini,
button.secondary {
  padding: .3rem .6rem;
  font-size: .8rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

button.secondary { padding: .5rem 1rem; font-size: .9rem; }

button.mini:hover,
button.secondary:hover { border-color: var(--accent); }

button[disabled] { opacity: .5; cursor: default; }

.pill {
  display: inline-block;
  padding: .05rem .5rem;
  font-size: .75rem;
  border: 1px solid var(--line);
  border-radius: 99px;
}

.pill.aktiv { color: #1d6b3a; border-color: #1d6b3a; }
.pill.inaktiv { color: var(--ink-soft); }

/* An data-theme statt an prefers-color-scheme: das Attribut setzt app.js nach
   dem gewählten Modus, damit der Umschalter auch diese Regel erfasst. */
:root[data-theme="dark"] .pill.aktiv { color: #6cc48c; border-color: #6cc48c; }

td.pre { white-space: pre-line; font-size: .8rem; }

.muted { font-size: .78rem; color: var(--ink-soft); }

.banner {
  padding: .7rem .9rem;
  margin-bottom: 1rem;
  font-size: .88rem;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--panel);
}

.banner.ok { border-left-color: #1d6b3a; }
.banner.err { border-left-color: var(--danger); }
.banner.pw {
  border-left-color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

/* ---------------------------------------------- Mein Konto / Farbeinstellungen */

table.kv { width: auto; }

table.kv th {
  padding-right: 1.5rem;
  font-weight: 600;
  white-space: nowrap;
}

.panel form,
form.panel { max-width: 32rem; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: .35rem 1.5rem;
}

.color-row {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.color-row label {
  margin: 0;
  flex: 1;
  font-weight: 400;
  color: var(--ink);
  font-size: .85rem;
}

.color-row input[type="color"] {
  width: 2.6rem;
  height: 1.8rem;
  padding: 0;
  margin: 0;
  flex: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

.hex {
  font-size: .75rem;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------- Tabs */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  padding: .5rem .95rem;
  font-size: .9rem;
  color: var(--ink-soft);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs button:hover { color: var(--ink); }

.tabs button[aria-selected="true"] {
  font-weight: 600;
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* ------------------------------------------------- Baum der Datenbankstruktur */

.tree, .tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree ul {
  margin-left: .55rem;
  padding-left: .75rem;
  border-left: 1px solid var(--line);
}

.tree li { margin: .1rem 0; }

.tree summary,
.tree-leaf {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .22rem .35rem;
  border-radius: 5px;
  font-size: .87rem;
}

.tree summary { cursor: pointer; list-style: none; }

.tree summary::-webkit-details-marker { display: none; }

/* Dreieck als Aufklapp-Anzeige, dreht beim Öffnen */
.tree summary::before {
  content: "";
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: .55;
  transition: transform .12s;
}

.tree details[open] > summary::before { transform: rotate(90deg); }

.tree summary:hover { background: var(--bg); }

.tree-leaf { padding-left: 1.3rem; }

.tree-name { font-weight: 500; }

.tree-meta {
  font-size: .78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.tree .icon { width: 1rem; height: 1rem; opacity: .8; }

/* "Daten"-Knopf im Baum: erst beim Überfahren der Zeile sichtbar, damit die
   Struktur ruhig bleibt. Auf Touch-Geräten (kein Hover) immer sichtbar. */
.tree-btn {
  margin-left: auto;
  opacity: 0;
  transition: opacity .1s;
}

.tree summary:hover .tree-btn,
.tree-btn:focus-visible { opacity: 1; }

@media (hover: none) {
  .tree-btn { opacity: 1; }
}

/* --------------------------------------------------------- Popup-Fenster */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, .55);
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(96vw, 90rem);
  max-height: 88vh;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}

.modal-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  flex: 0 0 auto;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--line);
}

.modal-title { font-size: .95rem; }

.modal-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
  margin-left: auto;
}

.modal-tools select {
  padding: .25rem .4rem;
  font-size: .8rem;
  max-width: 12rem;
}

.tool-label {
  font-size: .78rem;
  color: var(--ink-soft);
  margin-left: .4rem;
}

.modal-close {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.modal-close:hover { color: var(--ink); border-color: var(--accent); }

/* Der einzige Scrollbereich des Popups */
.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0;
}

.modal-body > p { padding: 1rem; }

.modal-foot {
  flex: 0 0 auto;
  padding: .55rem 1rem;
  font-size: .78rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
}

/* --------------------------------------------------------- Datentabelle */

.data-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: .3rem .6rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Kopfzeile bleibt beim Scrollen stehen */
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  border-bottom: 2px solid var(--line);
  text-align: left;
  font-weight: 600;
  color: var(--ink);
}

.data-table tbody tr:hover td { background: var(--bg); }

.data-table td.null { color: var(--ink-soft); font-style: italic; }

select {
  padding: .5rem .6rem;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  max-width: 30rem;
}

/* Beschriftung über einem Bedienelement, das kein <input> ist */
.field-label {
  display: block;
  margin: 1rem 0 .35rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

@media (max-width: 40rem) {
  /* Auf schmalen Geräten kein festes Zwei-Spalten-Gitter: die Leiste läuft
     oben mit und die Seite scrollt wieder als Ganzes. */
  .shell,
  .shell.collapsed { grid-template-columns: 1fr; height: auto; }

  .sidebar {
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--sidebar-line);
  }

  nav { overflow: visible; }

  .content { height: auto; overflow: visible; padding: 1.25rem; }
}
