/* eBON SFTP-Verwaltung – Gestaltung angelehnt an das CKV PartnerPortal (partner.ckv.de) */

:root {
  --ckv: #45545b;
  --ckv-deep: #35424a;
  --bg: #f6f8f9;
  --bg-alt: #eceff1;
  --surface: #fff;
  --text: #1b2226;
  --text-muted: #626f78;
  --border: #dde3e7;
  --accent: var(--ckv);
  --accent-contrast: #fff;
  --ring: rgba(69, 84, 91, .35);
  --shadow: 0 1px 2px rgba(27, 34, 38, .05), 0 8px 24px rgba(27, 34, 38, .06);
  --danger-bg: #fdf2f2;
  --danger-border: #e9c4c4;
  --danger-text: #8c2f2f;
  --ok-bg: #f1f8f3;
  --ok-border: #bcd9c4;
  --ok-text: #2c6138;
  --warn-bg: #fbf5e6;
  --warn-border: #ead9ad;
  --warn-text: #7a5a12;
  --marker: #1779d6;
  --ctl-border: #cdd3d8;
  --ctl-face: #fff;
  --ctl-face-hover: #f4f6f7;
  --ctl-shadow: 0 1px 1px rgba(16, 24, 32, .05);
  --ctl-height: 26px;
  --ctl-font: 13px;
  --ctl-radius: 6px;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171a; --bg-alt: #171d21; --surface: #1b2226; --text: #e7ecee; --text-muted: #98a4ab;
    --border: #2a343a; --accent: #9fb0b9; --accent-contrast: #12171a; --ring: rgba(159, 176, 185, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
    --danger-bg: #2a1b1c; --danger-border: #5c3436; --danger-text: #f0b4b4;
    --ok-bg: #16241a; --ok-border: #2f5138; --ok-text: #a7d6b4;
    --warn-bg: #2b2514; --warn-border: #54482a; --warn-text: #e9cf8f; --marker: #4f9dd9;
    --ctl-border: #39424a; --ctl-face: #232a30; --ctl-face-hover: #2b333a; --ctl-shadow: 0 1px 1px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12171a; --bg-alt: #171d21; --surface: #1b2226; --text: #e7ecee; --text-muted: #98a4ab;
  --border: #2a343a; --accent: #9fb0b9; --accent-contrast: #12171a; --ring: rgba(159, 176, 185, .35);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --danger-bg: #2a1b1c; --danger-border: #5c3436; --danger-text: #f0b4b4;
  --ok-bg: #16241a; --ok-border: #2f5138; --ok-text: #a7d6b4;
  --warn-bg: #2b2514; --warn-border: #54482a; --warn-text: #e9cf8f; --marker: #4f9dd9;
  --ctl-border: #39424a; --ctl-face: #232a30; --ctl-face-hover: #2b333a; --ctl-shadow: 0 1px 1px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
a { color: inherit; }
.muted { color: var(--text-muted); }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
code, .mono { font-family: var(--mono); }

/* Logo: dunkle Variante auf hellem Grund und umgekehrt (wie im PartnerPortal) */
.logo-on-dark { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-on-dark { display: block; }
  :root:not([data-theme="light"]) .logo-on-light { display: none; }
}
:root[data-theme="dark"] .logo-on-dark { display: block; }
:root[data-theme="dark"] .logo-on-light { display: none; }

/* ---------------------------------------------------------------- Kopfzeile */
.site-header {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .bar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 0 16px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; letter-spacing: -.01em; }
.brand img { width: 34px; height: 34px; }
.brand-name { font-weight: 650; font-size: 1.05rem; line-height: 1.15; }
.brand-name small {
  display: block; font-size: .68rem; font-weight: 500; color: var(--text-muted);
  letter-spacing: .06em; text-transform: uppercase;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.header-user { font-size: .86rem; color: var(--text-muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 4px; }

.theme-toggle {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: var(--ctl-height); height: var(--ctl-height); padding: 0;
  border: 1px solid var(--ctl-border); border-radius: var(--ctl-radius);
  background: var(--ctl-face); color: var(--text-muted); box-shadow: var(--ctl-shadow); cursor: pointer;
}
.theme-toggle:hover { background: var(--ctl-face-hover); color: var(--text); }
.theme-toggle .auto-dot {
  position: absolute; right: 3px; bottom: 3px; width: 4px; height: 4px; border-radius: 50%; background: currentColor;
}

/* --------------------------------------------------------------- Bedienung */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--ctl-height); padding: 3px 11px; border-radius: var(--ctl-radius);
  border: 1px solid var(--ctl-border); background: var(--ctl-face); color: var(--text);
  font: inherit; font-size: var(--ctl-font); font-weight: 500; line-height: 1.3; white-space: nowrap;
  box-shadow: var(--ctl-shadow); cursor: pointer; transition: background-color .1s ease, border-color .1s ease;
}
.btn:hover { background: var(--ctl-face-hover); }
.btn:focus-visible, .theme-toggle:focus-visible, .tabbar-item:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:disabled { background: var(--bg-alt); color: var(--text-muted); border-color: var(--border); box-shadow: none; opacity: .75; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { background: var(--danger-text); border-color: var(--danger-text); color: #fff; }
.btn.link-danger { color: var(--danger-text); }
.btn.link-danger:hover { background: var(--danger-bg); border-color: var(--danger-border); }
.btn-lg { width: 100%; min-height: 44px; font-size: 1rem; border-radius: var(--radius); }
.btn.small { min-height: 22px; padding: 1px 8px; font-size: 12px; border-radius: 5px; }

.field { display: grid; gap: 6px; }
.field > span, label.field { font-size: .88rem; font-weight: 550; }
.field .hint { font-size: .8rem; font-weight: 400; color: var(--text-muted); }
input, select {
  width: 100%; min-width: 0; padding: 9px 12px; font: inherit; font-size: .95rem; font-weight: 400; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
input:user-invalid { border-color: var(--danger-text); }
.input-group { display: flex; gap: 6px; }
.input-group select { width: auto; flex: none; min-width: 72px; }
.input-group .btn { flex: none; min-height: auto; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { width: auto; }

/* ------------------------------------------------------------- Anmeldung */
.auth { flex: 1; display: grid; place-items: center; padding: 32px 16px; }
.auth-card {
  width: 100%; max-width: 420px; display: grid; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px; box-shadow: var(--shadow);
}
.auth-logo { justify-self: center; width: 42px; height: 42px; }
.auth-card h1 { font-size: 1.45rem; letter-spacing: -.02em; font-weight: 650; }
.auth-card .sub { margin: -10px 0 4px; color: var(--text-muted); font-size: .94rem; }
.error {
  margin: 0; padding: 10px 12px; border-radius: var(--radius); font-size: .88rem;
  border: 1px solid var(--danger-border); background: var(--danger-bg); color: var(--danger-text);
}
.notice {
  margin: 0; padding: 10px 12px; border-radius: var(--radius); font-size: .88rem;
  border: 1px solid var(--warn-border); background: var(--warn-bg); color: var(--warn-text);
}

/* -------------------------------------------------------------- App-Layout */
.page { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding-inline: 16px; padding-block: 28px 40px; display: grid; gap: 20px; align-content: start; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.page-head h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.02em; }
.page-head .sub { margin: 2px 0 0; color: var(--text-muted); font-size: .94rem; }
.eyebrow { font-size: .74rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }

.tabbar { display: inline-flex; flex-wrap: wrap; padding: 2px; background: var(--bg-alt); border: 1px solid var(--ctl-border); border-radius: 7px; }
.tabbar-item {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 14px; border: 0; border-radius: 5px;
  background: transparent; color: var(--text); font: inherit; font-size: .9rem; font-weight: 500; cursor: pointer;
}
.tabbar-item:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.tabbar-item.is-active { background: var(--surface); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 32, .12); }
.tabbar-count {
  padding: 0 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--ctl-border);
  color: var(--text-muted); font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); display: grid; gap: 16px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.panel-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.panel-tools input[type="search"] { width: 220px; padding: 4px 10px; font-size: var(--ctl-font); border-radius: var(--ctl-radius); min-height: var(--ctl-height); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kachel { background: var(--surface); border: 1px solid var(--ctl-border); border-radius: var(--ctl-radius); padding: 12px 14px; display: grid; gap: 2px; align-content: start; }
.kachel-label { font-size: .74rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.kachel-wert { font-size: 1.35rem; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; align-items: start; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }

/* ----------------------------------------------------------------- Tabelle */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: .74rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
th.sorted-asc::after { content: " ▲"; font-size: .7em; }
th.sorted-desc::after { content: " ▼"; font-size: .7em; }
tbody tr:hover { background: var(--bg-alt); }
td.user { font-weight: 600; font-family: var(--mono); font-size: .86rem; }
td.user small, td small { display: block; font-weight: 400; color: var(--text-muted); font-family: system-ui, sans-serif; font-size: .78rem; }
.col-usage { min-width: 210px; }
.actions { display: flex; gap: 4px; flex-wrap: nowrap; justify-content: flex-end; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-alt); font-size: .72rem; font-weight: 600; letter-spacing: .04em; color: var(--text-muted); white-space: nowrap; }
.tag.ok { border-color: var(--ok-border); background: var(--ok-bg); color: var(--ok-text); }
.tag.off { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger-text); }

.usage-text { display: flex; justify-content: space-between; gap: 8px; font-size: .84rem; font-variant-numeric: tabular-nums; }
.bar { height: 5px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar-fill.warn { background: #c98a00; }
.bar-fill.crit { background: #c0352b; }
.bar-fill.none { background: var(--text-muted); opacity: .3; }

/* -------------------------------------------------------------- API-Schlüssel */
.hint-block { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-alt); font-size: .88rem; display: grid; gap: 6px; }
.hint-block dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.hint-block dt { color: var(--text-muted); }
.hint-block dd { margin: 0; font-family: var(--mono); font-size: .84rem; overflow-wrap: anywhere; }
.key-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.key-form .field { flex: 1 1 280px; }
.key-form .btn { min-height: 40px; padding: 0 16px; }
.key-result { border: 1px solid var(--ok-border); background: var(--ok-bg); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; }
.key-result h3 { font-size: .95rem; color: var(--ok-text); }
.secret {
  display: block; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--ok-border);
  background: var(--surface); color: var(--text); font-family: var(--mono); font-size: .95rem;
  letter-spacing: .02em; word-break: break-all; user-select: all;
}
.code-block {
  margin: 0; padding: 10px 12px; border: 1px solid var(--ctl-border); border-radius: var(--ctl-radius);
  background: var(--surface); font-family: var(--mono); font-size: 12px; line-height: 1.55; overflow-x: auto; white-space: pre;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ----------------------------------------------------------------- Dialoge */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(18, 23, 26, .5); }
.dialog-body { padding: 24px; display: grid; gap: 12px; }
.dialog-body h2 { font-size: 1.15rem; font-weight: 650; letter-spacing: -.01em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.cred-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: .92rem; }
.cred-list dt { color: var(--text-muted); }
.cred-list dd { margin: 0; font-family: var(--mono); word-break: break-all; }

/* ------------------------------------------------------------------ Diverses */
.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); right: 20px; max-width: min(420px, calc(100vw - 40px));
  padding: 10px 14px; border-radius: var(--radius); font-size: .9rem;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 30;
}
.toast.error { background: var(--danger-text); color: #fff; }

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 7px 16px; font-size: .78rem; line-height: 1.4; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.site-footer .version { font-family: var(--mono); font-size: 11px; margin-left: 6px; }
.site-footer nav { margin-left: auto; display: flex; gap: 18px; }
.site-footer a { color: var(--text-muted); text-underline-offset: 2px; }
.site-footer a:hover { color: var(--text); }

.kurz { display: none; }

@media (max-width: 640px) {
  .auth-card { padding: 26px 20px; }
  .header-user { display: none; }
  .site-header .bar-inner { gap: 10px; padding: 0 12px; }
  .brand { gap: 8px; }
  .brand-name small { display: none; }
  .header-right { gap: 6px; }
  .lang { display: none; }
  .kurz { display: inline; }
  .panel { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .panel-tools input[type="search"] { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.tab-section { display: grid; gap: 20px; min-width: 0; }

/* ------------------------------------------------------------- Ordneransicht */
#user-rows tr[data-user] { cursor: pointer; }
.linkish {
  padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px;
}
.linkish:hover { text-decoration-color: currentColor; }
.linkish:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-radius: 3px; }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
.files-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.files-head h2 { font-family: var(--mono); font-size: 1.05rem; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: .9rem; padding: 6px 10px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--ctl-radius); }
.crumbs .sep { color: var(--text-muted); padding: 0 4px; }
.crumbs button { padding: 1px 4px; border: 0; border-radius: 4px; background: none; color: var(--text-muted); font: inherit; cursor: pointer; }
.crumbs button:hover { color: var(--text); background: var(--surface); }
.crumbs [aria-current] { color: var(--text); font-weight: 600; padding: 1px 4px; }
.files-wrap { max-height: min(60vh, 520px); overflow-y: auto; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--ctl-radius); }
.files-wrap th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.files-wrap th, .files-wrap td { padding: 8px 12px; }
.fname { display: inline-flex; align-items: center; gap: 8px; }
.ficon { width: 16px; height: 16px; flex: none; color: var(--text-muted); }
.ficon.dir { color: var(--marker); }
.files-foot { margin: 0; font-size: .84rem; }
#files-rows tr[data-open] { cursor: pointer; }
#files-rows tr[data-open]:hover { background: var(--bg-alt); }
.linkish { text-align: left; }
.files-wrap td:nth-child(2), .files-wrap td:nth-child(3) { white-space: nowrap; }
