/* DEGKA — Dashboard-Layout. Light + Dark (System + manueller Toggle). Akzent REWE-Rot #cd1719. */
:root {
  color-scheme: light dark;
  --bg: #eef0f4; --surface: #ffffff; --surface2: #f1f3f7; --border: #e4e7ee;
  --text: #1a1d24; --muted: #6b7385;
  --accent: #cd1719; --accent-hover: #a81214; --on-accent: #ffffff;
  --accent-soft: color-mix(in srgb, #cd1719 12%, transparent);
  --okText: #166534; --okbg: #dcfce7; --okborder: #86efac;
  --errText: #991b1b; --errbg: #fee2e2; --errborder: #fca5a5;
  --warnText: #92400e;
  --shadow: 0 6px 24px rgba(20, 28, 50, .08);
  --shadow-sm: 0 1px 3px rgba(20, 28, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014; --surface: #181b21; --surface2: #21252e; --border: #2c313c;
    --text: #e7e9ee; --muted: #98a1b0;
    --accent: #e83a3c; --accent-hover: #ff5557; --on-accent: #1a0204;
    --accent-soft: color-mix(in srgb, #e83a3c 18%, transparent);
    --okText: #bbf7d0; --okbg: #14532d; --okborder: #166534;
    --errText: #fecaca; --errbg: #450a0a; --errborder: #7f1d1d;
    --warnText: #fbbf24;
    --shadow: 0 10px 40px rgba(0, 0, 0, .45); --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1014; --surface: #181b21; --surface2: #21252e; --border: #2c313c;
  --text: #e7e9ee; --muted: #98a1b0;
  --accent: #e83a3c; --accent-hover: #ff5557; --on-accent: #1a0204;
  --accent-soft: color-mix(in srgb, #e83a3c 18%, transparent);
  --okText: #bbf7d0; --okbg: #14532d; --okborder: #166534;
  --errText: #fecaca; --errbg: #450a0a; --errborder: #7f1d1d;
  --warnText: #fbbf24;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45); --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .9rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }

/* ---- Buttons / Inputs ---- */
.btn { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 10px; padding: .65rem 1.1rem; font-weight: 600; }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--accent); background: var(--surface2); }
label { display: block; font-size: .85rem; color: var(--muted); }
label span { display: block; margin-bottom: .35rem; }
input[type=text], input[type=password], input[type=search], input[type=file] {
  width: 100%; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.msg { font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }
.msg.error { color: var(--errText); } .msg.ok { color: var(--okText); } .msg.busy { color: var(--warnText); }
.muted { color: var(--muted); }

/* ---- Brand ---- */
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.25rem; letter-spacing: .02em; }
.brand img { border-radius: 7px; }
.brand--login { font-size: 1.6rem; justify-content: flex-start; }

/* ---- Login ---- */
#loginView { min-height: 100vh; display: grid; place-items: center; padding: 1rem; position: relative; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.25rem 1.4rem; box-shadow: var(--shadow); min-width: 0; }
#loginForm { width: 370px; max-width: 100%; padding: 2rem 2.25rem; }
#loginForm label { margin-bottom: 1rem; }
#loginForm .sub { margin: .4rem 0 1.7rem; color: var(--muted); font-size: .9rem; }
.login-title { font-size: 1.85rem; font-weight: 800; letter-spacing: .02em; margin: 0; }
.login-title::before {
  content: ""; display: inline-block; width: .45rem; height: 1.3rem; margin-right: .55rem;
  background: var(--accent); border-radius: 2px; vertical-align: -2px;
}
.login-stack { display: flex; flex-direction: column; align-items: center; }
.login-logo { display: block; margin: 0 0 1.2rem; border-radius: 16px; }
#loginView .footer { position: absolute; bottom: 0; left: 0; right: 0; margin: 0; }

/* ---- App shell ---- */
#appView { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1.1rem .9rem; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: .2rem .4rem 1.2rem; gap: .7rem; }
.sidebar .brand img { border-radius: 11px; }
.nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.navitem {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--muted); font-weight: 600;
  padding: .65rem .75rem; border-radius: 10px;
}
.navitem:hover { background: var(--surface2); color: var(--text); }
.navitem.active { background: var(--accent-soft); color: var(--accent); }
.ico { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

.sidebar-foot { display: flex; flex-direction: column; gap: .6rem; padding-top: .8rem; border-top: 1px solid var(--border); }
.userbox { display: flex; align-items: center; gap: .6rem; padding: .1rem .2rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.userinfo { display: flex; flex-direction: column; line-height: 1.2; overflow: hidden; }
.userinfo .uname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userinfo .urole { font-size: .75rem; color: var(--muted); }
.sidebar-foot .select { width: 100%; justify-content: space-between; }

/* ---- Content ---- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1.1rem 1.5rem .4rem; }
.topbar .spacer { flex: 1; }
.greeting { color: var(--muted); font-size: .9rem; }
.period { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: .3rem .9rem; font-size: .82rem; color: var(--muted); box-shadow: var(--shadow-sm); }
main { padding: 1rem 1.5rem 1.5rem; flex: 1; min-width: 0; }
.section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; }
#detailPanel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; min-width: 0; }
.row { display: flex; gap: .7rem; flex-wrap: wrap; align-items: end; }
.grow { flex: 1; min-width: 200px; }

/* ---- Stat cards ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.stat .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.9rem; font-weight: 800; margin-top: .25rem; }
.stat .s { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.stat.accent .v { color: var(--accent); }

/* ---- Tables ---- */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; max-height: 72vh; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; white-space: nowrap; }
th, td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); }
thead th { background: var(--surface2); position: sticky; top: 0; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface2); }
tr.clickable { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge.ok { background: var(--okbg); color: var(--okText); }
.badge.cur { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface2); color: var(--muted); white-space: nowrap; }
.tag.unter { background: var(--errbg); color: var(--errText); }
.tag.warn { background: color-mix(in srgb, var(--warnText) 16%, transparent); color: var(--warnText); }

/* ---- Detail ---- */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem 1rem; margin-bottom: .5rem; }
.summary .k { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.summary .v { font-size: 1rem; font-weight: 600; }
.kvgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .35rem .9rem; }
.kvgrid div { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kvgrid b { color: var(--muted); font-weight: 600; }
details { margin-top: .6rem; } summary { cursor: pointer; color: var(--accent); font-size: .85rem; }
.pill { font-size: .72rem; font-weight: 600; color: var(--accent); margin-left: .5rem; }

/* ---- Theme-Dropdown ---- */
.dropdown { position: relative; }
.select { display: inline-flex; align-items: center; gap: .45rem; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.select:hover { border-color: var(--accent); }
.select .caret { color: var(--muted); font-size: .8em; margin-left: auto; transition: transform .15s ease; }
.dropdown.open .caret { transform: rotate(180deg); }
.menu { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 30; margin: 0; padding: .3rem; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow); }
.menu li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .65rem; border-radius: 8px; cursor: pointer; font-size: .9rem; }
.menu li:hover { background: var(--surface2); }
.menu li.active { color: var(--accent); font-weight: 700; }
.menu li.active::after { content: "✓"; font-size: .9em; }
.optlabel { display: inline-flex; align-items: center; }
.emoji { margin-right: .5rem; }

/* ---- Deckungsprüfung ---- */
.deckung { border-color: var(--accent); }
.warn-banner { background: var(--surface2); color: var(--muted); border: 1px dashed var(--border);
  border-radius: 10px; padding: .55rem .8rem; font-size: .82rem; }
.num.unter { color: var(--errText); font-weight: 700; }
.num.ueber { color: var(--okText); font-weight: 700; }
.badge.abw { background: var(--surface2); color: var(--muted); }
.deckung-total { margin-top: .8rem; padding: .7rem .9rem; border-radius: 10px; font-size: 1.05rem; background: var(--surface2); }
.deckung-total.unter { background: var(--errbg); color: var(--errText); }
.deckung-total.ueber { background: var(--okbg); color: var(--okText); }

/* ---- Footer ---- */
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 1rem; }

/* ---- Toast ---- */
#toast { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px;
  padding: .7rem 1rem; box-shadow: var(--shadow); font-size: .85rem; animation: slidein .25s ease; max-width: 320px; color: var(--text); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

/* ---- Schmale Screens ---- */
@media (max-width: 720px) {
  #appView { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { border-top: 0; flex-direction: row; align-items: center; padding-top: 0; }
}
