:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2024;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #1f6feb;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --card: #1e2126;
    --ink: #e8eaed;
    --muted: #9aa3ad;
    --line: #2c3138;
    --accent: #5b9bff;
    --ok: #4ade80;
    --warn: #fbbf24;
    --err: #f87171;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
h4 { font-size: .9rem; margin: 1rem 0 .35rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.wide { max-width: 1500px; margin: 0 auto; padding: 1.25rem 1.25rem 3rem; }
.centered { display: flex; justify-content: center; align-items: center; min-height: 100vh; }

/* ---------------------------------------------------------------- Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .65rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 1.1rem; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a:hover { color: var(--ink); }
.logout { display: flex; align-items: center; gap: .6rem; }
.who { color: var(--muted); font-size: .85rem; }

/* ---------------------------------------------------------------- Bausteine */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.login { width: min(380px, 92vw); }
.login h1 { margin-bottom: .1rem; }

label { display: block; margin: .7rem 0; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem;
  padding: .55rem .6rem;
  /* 16px ist Pflicht: alles darunter laesst iOS beim Fokus in das Feld zoomen. */
  font-family: inherit; font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 44px;                 /* bequem treffbar am Touchscreen */
}
label.checkline { display: flex; align-items: center; gap: .5rem; color: var(--ink); }
label.checkline input { width: auto; min-height: 0; margin: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button { font: inherit; cursor: pointer; }
.primary, .secondary, .button {
  display: inline-block;
  padding: .6rem 1rem;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 7px;
  text-decoration: none;
}
.big { font-size: 1.05rem; padding: .85rem 1.2rem; }
.primary { background: var(--accent); color: #fff; }
.secondary, .button { background: var(--card); color: var(--ink); border-color: var(--line); }
.button.small { padding: .25rem .6rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
.linkish {
  background: none; border: none; padding: 0;
  color: var(--accent); text-decoration: underline; font-size: inherit;
}
.linkish.danger { color: var(--err); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.small { font-size: .8rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: .8rem; margin: .4rem 0; }
.empty { padding: 2rem 0; text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

.alert { padding: .7rem .9rem; border-radius: 7px; margin: .75rem 0; font-size: .9rem; }
.alert ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.alert.error { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }
.alert.warn  { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.alert.ok    { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.alert.info  { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }

/* ---------------------------------------------------------------- Upload */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.25rem;
  transition: border-color .15s, background .15s;
}
.dropzone.hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.dropzone p { margin: .25rem 0; }
.dropzone input[type=file] { display: none; }
.uploadlog { list-style: none; margin: .75rem 0 0; padding: 0; font-size: .85rem; text-align: left; }
.uploadlog li { padding: .15rem 0; }
.uploadlog .ok { color: var(--ok); }
.uploadlog .fail { color: var(--warn); }

/* ---------------------------------------------------------------- Filter */
.filters { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: 1rem; }
.chip {
  display: inline-block; padding: .3rem .7rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--muted);
  text-decoration: none; font-size: .85rem;
}
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip b { font-weight: 600; }
.monthpick { width: auto; margin: 0 0 0 auto; }

/* ---------------------------------------------------------------- Tabellen */
.list {
  width: 100%; border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.list th, .list td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.list tbody tr:last-child td { border-bottom: none; }
.list tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.list td form { display: inline; }
.detail { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block; padding: .12rem .5rem;
  border-radius: 999px; font-size: .75rem;
  background: var(--line); color: var(--ink);
}
.badge.s-in_pruefung { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.s-fehler { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }
.badge.s-geprueft { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.s-exportiert { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.warncount { display: block; font-size: .72rem; color: var(--warn); }

/* ---------------------------------------------------------------- Pruefansicht */
.review { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .review { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; } }

.preview {
  position: sticky; top: 1rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem;
}
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; font-size: .85rem; }
.preview iframe, .preview img {
  width: 100%; height: calc(100vh - 9rem);
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.preview img { object-fit: contain; height: auto; max-height: calc(100vh - 9rem); }

.fields { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.taxlines { width: 100%; border-collapse: collapse; }
.taxlines th { font-size: .75rem; color: var(--muted); text-align: left; font-weight: 500; }
.taxlines td { padding: .1rem .3rem .1rem 0; }
.taxlines input { margin-top: 0; }
.actions { display: flex; gap: .6rem; margin-top: 1.25rem; }
.sideactions { display: flex; gap: 1.25rem; margin-top: 1rem; font-size: .85rem; }
.meta { margin-top: 1.5rem; font-size: .85rem; color: var(--muted); }
.meta dl { display: grid; grid-template-columns: 8rem 1fr; gap: .2rem .5rem; margin: .5rem 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }
.history { list-style: none; padding: 0; margin: .25rem 0; }

.exportbox .summary { font-size: 1rem; margin: 1rem 0 .25rem; }

/* ---------------------------------------------------------------- Mandant + Upload */
.tenantpick { margin: 0; }
.tenantpick select {
  margin: 0; padding: .3rem 1.6rem .3rem .5rem; min-height: 0;
  font-size: .9rem; font-weight: 600; background: var(--bg);
}
.tenantname { font-size: .9rem; font-weight: 600; }

.uploadbuttons { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.dropzone input[type=file] { display: none; }

.pagestack {
  margin-top: 1rem; padding-top: .9rem;
  border-top: 1px solid var(--line); text-align: left;
}
.pagestack-title { margin: 0 0 .5rem; font-size: .9rem; }
.pagelist { list-style: none; display: flex; flex-wrap: wrap; gap: .7rem; padding: 0; margin: 0 0 .8rem; }
.pagelist li {
  width: 120px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px; padding: .4rem; background: var(--bg);
}
.pagelist img { width: 100%; height: 90px; object-fit: cover; border-radius: 5px; }
.pagenum { display: block; font-size: .75rem; color: var(--muted); margin: .25rem 0; }

.preview .mailtext {
  white-space: pre-wrap; word-break: break-word;
  max-height: calc(100vh - 9rem); overflow: auto;
  font-size: .8rem; padding: .75rem; margin: 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.preview img + img { margin-top: .6rem; }
.preview-mobile { display: none; }
.fields-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; font-size: .85rem; }
.inlineform { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.inlineform select { width: auto; margin: 0; min-height: 38px; font-size: .85rem; }

/* ---------------------------------------------------------------- Handy */
@media (max-width: 720px) {
  .wrap, .wide { padding: 1rem .75rem 5.5rem; }
  h1 { font-size: 1.25rem; }

  .topbar {
    flex-wrap: wrap; gap: .5rem .9rem;
    padding: .55rem .75rem calc(.55rem + env(safe-area-inset-bottom, 0px));
  }
  .topbar nav { order: 3; width: 100%; gap: .9rem; overflow-x: auto; padding-bottom: .15rem; }
  .topbar nav a { white-space: nowrap; font-size: .9rem; }
  .logout { margin-left: auto; }
  .who { display: none; }

  /* Am Rechner steht die Vorschau daneben, am Handy zusammengeklappt ueber dem Formular. */
  .review { grid-template-columns: 1fr; }
  .preview { display: none; }
  .preview-mobile { display: block; margin-bottom: 1rem; }
  .preview-mobile summary { padding: .6rem 0; font-weight: 600; cursor: pointer; }
  .preview-mobile img { width: 100%; border: 1px solid var(--line); border-radius: 6px; margin-bottom: .5rem; }
  .fields { padding: .9rem; }

  /* Aktionen bleiben am Daumen erreichbar, egal wie lang das Formular ist. */
  .actionbar {
    position: sticky; bottom: 0; z-index: 5;
    margin: 1.25rem -.9rem -.9rem;
    padding: .7rem .9rem calc(.7rem + env(safe-area-inset-bottom, 0px));
    background: var(--card); border-top: 1px solid var(--line);
  }
  .actionbar button { flex: 1; }

  /* Tabellen werden zu Karten — sonst muesste man waagerecht scrollen. */
  .list.cards { border: none; background: none; }
  .list.cards thead { display: none; }
  .list.cards tbody tr {
    display: grid; grid-template-columns: auto 1fr; gap: .1rem .6rem;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .7rem .85rem; margin-bottom: .6rem;
  }
  .list.cards tbody td { display: contents; border: none; padding: 0; }
  .list.cards tbody td::before {
    content: attr(data-label); color: var(--muted); font-size: .8rem; padding: .1rem 0;
  }
  .list.cards tbody td:not([data-label]) { display: block; grid-column: 1 / -1; }
  .list.cards tbody td.num { text-align: left; font-weight: 600; }
  .list.cards tbody td.strong { font-weight: 600; }
  /* Muss so spezifisch sein wie die :not()-Regel darueber, sonst gewinnt display:block. */
  .list.cards tbody td.rowaction { display: none; }   /* die ganze Karte ist klickbar */
  .list.cards tbody tr { cursor: pointer; }
  .detail { max-width: none; white-space: normal; }

  .filters { gap: .35rem; }
  .monthpick { margin: .35rem 0 0; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .pagelist li { width: calc(50% - .35rem); }
  .uploadbuttons { flex-direction: column; }
  .uploadbuttons button { width: 100%; }
}
