/* NUT USV Dashboard – changeways CD (dunkel) */
:root {
  --cw-yellow: #CECB4C;
  --cw-gray: #72777A;
  --cw-dark: #2A2C2D;
  --cw-white: #FFFFFF;

  --bg: #222425;
  --surface: #2A2C2D;
  --surface-2: #34373A;
  --line: #43474A;
  --text: #FFFFFF;
  --muted: #B3B7B9;
  --accent: var(--cw-yellow);

  --ok: #5DBB7E;
  --warn: #E8913A;
  --crit: #E5574B;
  --info: #62A8E0;
  --unknown: #8A8F92;

  --radius: 10px;
  --font: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", Tahoma, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 0; height: 0; overflow: hidden; }
h1, h2, h3 { font-weight: normal; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.err { color: var(--crit); min-height: 1.2em; margin: 4px 0 10px; font-size: 13.5px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons & Inputs ---------- */
.btn { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover:not(:disabled) { border-color: var(--cw-gray); background: #3d4144; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--cw-dark); border-color: var(--accent); font-weight: bold; }
.btn-primary:hover:not(:disabled) { background: #dad75c; border-color: #dad75c; }
.btn-sm { padding: 7px 12px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn.busy { position: relative; color: transparent; }
.btn.busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { background: none; border: 1px solid transparent; color: var(--muted); width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 21px; height: 21px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input:not([type=range]):not([type=checkbox]) { display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
input:focus { border-color: var(--accent); outline: none; }

/* ---------- Branding ---------- */
.brand { display: flex; align-items: center; }
.logo { height: 22px; width: auto; background: var(--cw-white); padding: 5px 9px; border-radius: 6px; box-sizing: content-box; }
.wordmark { font-size: 18px; letter-spacing: .2px; color: var(--text); border-left: 3px solid var(--accent); padding-left: 9px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at top, #2f3233 0%, var(--bg) 70%); }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius); padding: 28px 24px 24px; }
.brand-login { margin-bottom: 22px; }
.login-card h1 { font-size: 22px; }
.login-card > .muted { margin: 2px 0 20px; font-size: 13.5px; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top)); background: rgba(42, 44, 45, .96); backdrop-filter: blur(8px); border-bottom: 3px solid var(--accent); }
.title { flex: 1; min-width: 0; }
.title h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title .sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pills { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 9px; border-radius: 999px; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.pill b { font-weight: normal; color: var(--muted); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.pill[data-s=ok] i { background: var(--ok); box-shadow: 0 0 0 3px rgba(93, 187, 126, .18); }
.pill[data-s=warn] i { background: var(--warn); }
.pill[data-s=info] i { background: var(--info); }
.pill[data-s=crit] { border-color: var(--crit); }
.pill[data-s=crit] i { background: var(--crit); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(229, 87, 75, .25); } }
.icons { display: flex; gap: 2px; }

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--info); }
.banner.warn { border-left-color: var(--warn); }
.banner.crit { border-left-color: var(--crit); background: #3a2826; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 14px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; border-top: 3px solid var(--line); }
.metric[data-s=ok] { border-top-color: var(--ok); }
.metric[data-s=warn] { border-top-color: var(--warn); }
.metric[data-s=crit] { border-top-color: var(--crit); }
.m-head { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.m-head svg { width: 17px; height: 17px; color: var(--accent); }
.m-val { font-size: 32px; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.m-val small { font-size: 15px; color: var(--muted); margin-left: 3px; }
.m-sub { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 15px; color: var(--accent); margin-bottom: 14px; letter-spacing: .2px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }

.bar-row { margin-bottom: 16px; }
.bar-label { display: flex; justify-content: space-between; font-size: 13.5px; color: var(--muted); margin-bottom: 6px; }
.bar-label b { color: var(--text); font-weight: normal; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 6px; background: var(--unknown); transition: width .6s ease, background .3s; }
.bar-fill[data-s=ok] { background: var(--ok); }
.bar-fill[data-s=warn] { background: var(--warn); }
.bar-fill[data-s=crit] { background: var(--crit); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.delay { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.delay-row { display: flex; gap: 12px; align-items: center; }
input[type=range] { flex: 1; accent-color: var(--accent); height: 28px; }

.params { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; font-size: 13.5px; }
.params dt { color: var(--muted); }
.params dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.log { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; font-size: 13px; }
.log li { display: grid; grid-template-columns: 8px auto 1fr; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); align-self: center; }
.log .dot[data-s=ok] { background: var(--ok); }
.log .dot[data-s=info] { background: var(--info); }
.log .dot[data-s=warning] { background: var(--warn); }
.log .dot[data-s=critical] { background: var(--crit); }
.log time { white-space: nowrap; color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.log .empty { display: block; color: var(--muted); }

.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- Sheet / Dialog ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 20px; }
.sheet { width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; }
.sheet-body { overflow: auto; padding: 6px 18px 20px; }
.sheet-body section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sheet-body section:last-of-type { border-bottom: 0; }
.sheet-body h3 { font-size: 14px; color: var(--accent); margin-bottom: 10px; }

.toggles { display: grid; gap: 2px; }
.trow { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.trow .tl { flex: 1; min-width: 0; }
.trow .tl b { display: block; font-weight: normal; }
.trow .tl > span { display: block; font-size: 12px; color: var(--muted); }
.sev { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.sev[data-s=critical] { background: var(--crit); }
.sev[data-s=warning] { background: var(--warn); }
.sev[data-s=ok] { background: var(--ok); }
.sev[data-s=info] { background: var(--info); }

.switch { position: relative; width: 42px; height: 24px; flex: none; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: var(--cw-white); border-radius: 50%; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); background: var(--cw-dark); }
.switch input:disabled + span { opacity: .4; cursor: not-allowed; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.tag { display: inline-block; margin-left: 6px; vertical-align: 1px; font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: rgba(93, 187, 126, .4); }

.qr { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; margin-top: 10px; }
.qr img { width: 180px; height: 180px; border-radius: 8px; background: #fff; }
.qr code { font-family: var(--mono); font-size: 12px; word-break: break-all; color: var(--accent); }
.qr .qr-side { flex: 1; min-width: 200px; }

.dialog { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius); padding: 20px; }
.dialog h2 { font-size: 17px; margin-bottom: 8px; }
.dialog p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

#toasts { position: fixed; z-index: 60; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); animation: tin .2s ease-out; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--crit); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar { flex-wrap: wrap; gap: 10px 12px; padding: 10px 14px; }
  .topbar .brand { order: 1; }
  .title { order: 2; flex-basis: calc(100% - 200px); }
  .icons { order: 3; margin-left: auto; }
  .pills { order: 4; flex-basis: 100%; }
  .pill { flex: 1; justify-content: center; }
  .logo { height: 16px; padding: 4px 7px; }
  .wrap { padding: 14px; }
  .metrics { gap: 10px; }
  .metric { padding: 12px 13px; }
  .m-val { font-size: 26px; }
  .sheet-backdrop#settings { align-items: flex-end; padding: 0; }
  .sheet { max-width: none; max-height: 92vh; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 420px) {
  .title { flex-basis: 100%; order: 5; }
  .pills { order: 6; }
}

/* ---------- v2.1: Konto, Benutzer, Tabs ---------- */
.btn-ghost { background: none; border-color: transparent; color: var(--muted); margin-top: 6px; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: #ff9a90; }
.btn-danger:hover:not(:disabled) { border-color: var(--crit); }
.center { text-align: center; }
.qr-center { justify-content: center; margin: 4px 0 6px; }
.login-card code, .hint code { font-family: var(--mono); font-size: 11.5px; color: var(--accent); word-break: break-all; }

.user-chip { color: var(--muted); font-size: 12.5px; margin-right: 6px; align-self: center; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { font: inherit; font-size: 13.5px; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); padding: 11px 12px 9px; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; align-items: end; }
.form-grid .pw-rule, .form-grid > div { grid-column: 1 / -1; }
.form-grid .pw-rule { margin: -4px 0 10px; }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .grow { flex: 1; min-width: 180px; margin-bottom: 0; }
.form-row .btn { margin-bottom: 1px; }
.inline-check { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: var(--text); font-size: 13.5px; }

.user-list { display: grid; gap: 8px; }
.user-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 11px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.user-row .un { font-size: 14.5px; }
.user-row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.user-row .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.user-row .tag { margin-left: 0; }
.tag.warn { color: var(--warn); border-color: rgba(232, 145, 58, .45); }
.user-row .ua { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.user-row .ua .inline-check { margin: 0 6px 0 0; font-size: 12.5px; color: var(--muted); }

.pw-box { display: flex; gap: 8px; margin-bottom: 6px; }
.pw-box input { margin: 0 !important; font-family: var(--mono) !important; font-size: 16px !important; letter-spacing: .5px; color: var(--accent) !important; }

@media (max-width: 680px) {
  .user-chip { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr; }
  .user-row .ua { justify-content: flex-start; }
}
