/* KanzleiCloud – gemeinsames Theme (hell, folgt dem dunklen Gerätemodus) */

:root {
  color-scheme: light dark;
  /* Hell und freundlich als Standard; folgt dem dunklen Modus des Geräts */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #d8dfe9;
  --text: #1f2933;
  --muted: #62707f;
  --accent: #1f5fa8;
  --accent-dim: #1a4f8c;
  --green: #1b8a4b;
  --err: #c0392b;
  --ok: #1b8a4b;
  --on-accent: #ffffff;
  --accent-rgb: 31, 95, 168;
  --err-rgb: 192, 57, 43;
  --ok-rgb: 27, 138, 75;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101826;
    --surface: #182233;
    --surface-2: #202d42;
    --border: #2d3c54;
    --text: #e7edf5;
    --muted: #97a5b8;
    --accent: #6db1f0;
    --accent-dim: #3f84cc;
    --green: #5fd39a;
    --err: #f28b82;
    --ok: #5fd39a;
    --accent-rgb: 109, 177, 240;
    --err-rgb: 242, 139, 130;
    --ok-rgb: 95, 211, 154;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}
.brand:hover { text-decoration: none; color: var(--accent); }
.brand .ver { color: var(--muted); font-size: 12px; font-weight: 400; }

.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a {
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.topnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topnav a.active { color: var(--accent); background: var(--surface-2); }
.topnav a.logout:hover { color: var(--err); }
.topnav { align-items: center; }
.topnav .nav-label { color: var(--muted); font-size: 13px; padding: 6px 2px 6px 8px; }
.topnav .nav-sep { width: 1px; align-self: stretch; margin: 6px 8px; background: var(--border); }

.nav-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 6px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--on-accent);
  font-family: var(--sans);
  font-size: 11px;
  text-align: center;
  vertical-align: 2px;
}

/* ---------- Layout ---------- */

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 22px 40px;
  flex: 1;
}

.narrow { max-width: 420px; margin: 48px auto 0; }
/* Listenseiten (Mandanten/Akten): die volle Seitenbreite nutzen */
.container.wide { max-width: 1680px; }
table.files td.nowrap, table.files th.nowrap { white-space: nowrap; }
table.files td.wide-col { width: 100%; }

.hero { text-align: center; margin: 40px 0 36px; }
.hero h1 {
  font-family: var(--sans);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.hero .tagline { color: var(--muted); margin-top: 8px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card .bgicon {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  color: var(--accent);
  opacity: 0.08;
  pointer-events: none;
}
.card .bgicon svg { width: 100%; height: 100%; }
.card h1 { font-size: 20px; margin-bottom: 14px; }
.card h2 { font-size: 17px; margin-bottom: 8px; }
.card p { color: var(--muted); margin-bottom: 14px; }
.card.center { text-align: center; }
.card-link { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
.card-link:hover {
  text-decoration: none;
  border-color: var(--accent-dim);
  transform: translateY(-2px);
}
.card-link h2 { color: var(--accent); }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--sans);
  padding: 18px;
  border-top: 1px solid var(--border);
}

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

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

input[type="text"], input[type="password"], input[type="number"], input[type="email"],
input[type="url"], input[type="tel"], input[type="search"],
input[type="datetime-local"], select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.note-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--sans);
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 12px 14px;
  margin-top: 10px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.18);
}

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 18px;
  cursor: pointer;
  text-align: center;
}
.btn:hover { text-decoration: none; border-color: var(--accent-dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn-danger:hover { border-color: var(--err); color: var(--err); }
.btn-small { padding: 5px 10px; font-size: 13px; }

.msg { border-radius: 7px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.msg.err { background: rgba(var(--err-rgb), 0.12); border: 1px solid rgba(var(--err-rgb), 0.4); color: var(--err); }
.msg.ok { background: rgba(var(--ok-rgb), 0.10); border: 1px solid rgba(var(--ok-rgb), 0.35); color: var(--ok); }

.muted { color: var(--muted); }
.small { font-size: 13px; }

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

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumb {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
  word-break: break-all;
}
.breadcrumb a { color: var(--accent); }

table.files {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table.files th, table.files td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
table.files th {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: var(--surface-2);
  user-select: none;
}
table.files th.sortable { cursor: pointer; }
table.files th.sortable:hover { color: var(--text); }
table.files tr:last-child td { border-bottom: none; }
table.files tbody tr:hover { background: var(--surface-2); }
table.files td.name { font-family: var(--sans); word-break: break-all; }
table.files td.actions { white-space: nowrap; text-align: right; }
table.files td.actions a, table.files td.actions button { margin-left: 8px; }

.linklike {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: var(--err); }

.icon-btn {
  font-size: 16px;
  line-height: 1;
  padding: 4px 5px;
  vertical-align: middle;
}
a.icon-btn:hover { text-decoration: none; filter: brightness(1.35); }
table.files td.actions a, table.files td.actions button { margin-left: 2px; }

/* ---------- Animierter OTP-Code-Eingabe ---------- */

.otp-card {
  animation: otp-appear 0.45s ease-out both;
}

.otp-card .hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: -6px;
  margin-bottom: 6px;
}

.otp-fieldset {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 16px;
}

.otp-digit {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 24px;
  font-family: var(--mono);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  caret-color: var(--accent);
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.otp-digit:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.22);
  transform: translateY(-2px);
  background: var(--surface);
}

.otp-digit.filled {
  border-color: var(--accent-dim);
  background: rgba(var(--accent-rgb), 0.08);
}

.otp-submit {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.otp-shake {
  animation: otp-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes otp-appear {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes otp-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

@media (max-width: 420px) {
  .otp-fieldset { gap: 7px; }
  .otp-digit { width: 42px; height: 50px; font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .otp-card,
  .otp-digit,
  .otp-shake {
    animation: none;
    transition: none;
  }
  .otp-digit:focus { transform: none; }
}

/* ---------- Modaler Options-Dialog ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: min(380px, 90vw);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
}
.modal-card h3 { margin-bottom: 14px; font-size: 16px; }
.modal-card select { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.tool-panel {
  background: var(--surface-2);
  padding: 10px 14px !important;
}
.tool-panel .btn { margin-right: 8px; }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.green { color: var(--green); border-color: rgba(var(--ok-rgb), 0.4); }
.badge.red { color: var(--err); border-color: rgba(var(--err-rgb), 0.4); }

/* ---------- Dropzone / Fortschritt ---------- */

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
  margin-bottom: 16px;
}
.drop-zone.dragover { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.06); color: var(--text); }

.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 10px;
  display: none;
}
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- Token-Anzeige ---------- */

.token-box {
  font-family: var(--mono);
  font-size: 17px;
  letter-spacing: 1px;
  background: var(--surface-2);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  word-break: break-all;
}

.mono { font-family: var(--mono); }

.section-title {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--muted);
  margin: 30px 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

@media (max-width: 640px) {
  .hero h1 { font-size: 26px; }
  table.files th:nth-child(3), table.files td:nth-child(3) { display: none; }
  .topbar { padding: 12px 14px; }
  .container { padding: 20px 14px 32px; }
}

/* QR-Codes: dunkle Module brauchen hellen Grund, sonst nicht scanbar (auch im Dark-Mode) */
img.qr { background: #fff; padding: 12px; border-radius: 8px; box-sizing: content-box; }

/* Auswahlkarten (Zugang einrichten): die ganze Karte ist anklickbar */
.opt { display: block; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; color: inherit; }
a.opt:hover { border-color: var(--accent); background: var(--surface-2); text-decoration: none; }
.opt.sel { border-color: var(--accent); background: var(--surface-2); }

/* Aufklappbare Karte (z. B. „Mandant anlegen“): zu = nur eine Zeile */
details.aufklappen { padding: 12px 18px; }
details.aufklappen > summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details.aufklappen > summary::-webkit-details-marker { display: none; }
details.aufklappen[open] > summary { margin-bottom: 4px; }

/* Kanzlei-Logo in der Kopfzeile */
.brand .logo { height: 30px; width: auto; max-width: 160px; vertical-align: middle; margin-right: 10px; border-radius: 4px; }
input[type="color"] { width: 64px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); cursor: pointer; }
.farbwahl { display: flex; align-items: center; gap: 10px; }
details.aufklappen + details.aufklappen { margin-top: 12px; }
