/* Bestands-Bot — hand-written component CSS. Warm ledger, not a dashboard kit. */

:root {
  --paper: #f3efe6;
  --paper-raised: #faf8f2;
  --paper-inset: #ebe6db;
  --ink: #1c1914;
  --ink-muted: rgba(28, 25, 20, 0.62);
  --ink-faint: rgba(28, 25, 20, 0.42);
  --line: rgba(28, 25, 20, 0.12);
  --line-strong: rgba(28, 25, 20, 0.22);
  --forest: #1e4d3a;
  --forest-hover: #16382b;
  --forest-soft: rgba(30, 77, 58, 0.1);
  --terracotta: #9a3b24;
  --terracotta-hover: #7d301d;
  --terracotta-soft: rgba(154, 59, 36, 0.1);
  --gold: #b08d57;
  --gold-soft: rgba(176, 141, 87, 0.16);
  --ok: #1e4d3a;
  --radius: 10px;
  --space: 1.25rem;
  --max: 68rem;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: system-ui, "Segoe UI", sans-serif;
  --focus: 2px solid var(--forest);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
}

/* Subtle grain — light, not a texture overlay that fights the type. */
body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

img,
svg {
  max-width: 100%;
  display: block;
}

h1,
h2,
h3,
.brand {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--ink);
}

h1 {
  font-size: 1.85rem;
  margin: 0 0 0.4rem;
}

h2 {
  font-size: 1.25rem;
  margin: 0 0 0.75rem;
}

h3 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
}

p {
  margin: 0 0 0.85rem;
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--forest);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--forest-hover);
}

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

.num,
.stat-value,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Shell --------------------------------------------------------------- */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding: 0.85rem 1.5rem;
  background: rgba(243, 239, 230, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  font-size: 1.2rem;
  color: var(--ink);
  text-decoration: none;
  margin-right: 0.5rem;
}

.brand:hover {
  color: var(--forest);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.15rem;
  flex: 1 1 auto;
}

.nav a {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  color: var(--ink-muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.95rem;
}

.nav a:hover {
  color: var(--ink);
  background: var(--forest-soft);
}

.nav a.is-active {
  color: var(--forest);
  background: var(--forest-soft);
  font-weight: 600;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  font-size: 0.9rem;
}

.topbar-user form {
  margin: 0;
}

.main {
  flex: 1 1 auto;
  width: min(var(--max), calc(100% - 2.5rem));
  margin: 0 auto;
  padding: 2.25rem 0 4rem;
}

.site-footer {
  width: min(var(--max), calc(100% - 2.5rem));
  margin: 0 auto 1.5rem;
  color: var(--ink-faint);
  font-size: 0.8rem;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.stack-tight {
  gap: 0.55rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
}

.row-end {
  justify-content: flex-end;
}

.row-spread {
  justify-content: space-between;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  margin: 0;
}

.form-narrow {
  max-width: 28rem;
}

.form-mid {
  max-width: 36rem;
}

.table-wrap.nested {
  border: 0;
  background: transparent;
}

.grid-stats {
  margin-bottom: 1.5rem;
}

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}

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

.muted {
  color: var(--ink-muted);
}

.kicker {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header .lead {
  max-width: 38rem;
  color: var(--ink-muted);
}

/* --- Card ---------------------------------------------------------------- */

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
}

a.card {
  color: inherit;
  text-decoration: none;
  display: block;
}

a.card:hover {
  border-color: var(--line-strong);
}

a.card:focus-visible {
  outline-offset: 3px;
}

.card-link-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.65rem;
  font-size: 0.9rem;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: rgba(28, 25, 20, 0.04);
  color: var(--ink);
}

.btn-primary {
  background: var(--forest);
  border-color: var(--forest);
  color: #f7f3ea;
}

.btn-primary:hover {
  background: var(--forest-hover);
  border-color: var(--forest-hover);
  color: #f7f3ea;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-muted);
}

.btn-ghost:hover {
  color: var(--ink);
  background: rgba(28, 25, 20, 0.05);
}

.btn-danger {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #f7f3ea;
}

.btn-danger:hover {
  background: var(--terracotta-hover);
  border-color: var(--terracotta-hover);
  color: #f7f3ea;
}

.btn-small {
  min-height: 2rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}

/* --- Forms --------------------------------------------------------------- */

form {
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.fields-2 {
  display: grid;
  gap: 0 1rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

label,
.field > span.label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

.req {
  color: var(--terracotta);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fffef9;
  color: var(--ink);
  font-family: inherit;
  font-size: 16px; /* iOS: no zoom on focus */
  line-height: 1.4;
}

input.num,
textarea.num {
  font-variant-numeric: tabular-nums;
}

textarea {
  min-height: 6.5rem;
  resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(28, 25, 20, 0.35);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: var(--focus);
  outline-offset: 1px;
  border-color: var(--forest);
}

input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  max-width: 1.05rem;
  padding: 0;
  accent-color: var(--forest);
  cursor: pointer;
}

.field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
}

.field-check label {
  font-weight: 500;
  cursor: pointer;
}

.hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--terracotta);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.5rem;
}

/* --- Table --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table th,
.table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table th {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--paper-inset);
}

.table tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: rgba(30, 77, 58, 0.05);
}

.table a {
  font-weight: 600;
  text-decoration: none;
}

.table a:hover {
  text-decoration: underline;
}

/* --- Flash --------------------------------------------------------------- */

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 1rem;
}

.flash-ok {
  background: var(--forest-soft);
  border-color: rgba(30, 77, 58, 0.28);
  color: var(--forest);
}

.flash-err {
  background: var(--terracotta-soft);
  border-color: rgba(154, 59, 36, 0.28);
  color: var(--terracotta);
}

.flash-warn {
  background: var(--gold-soft);
  border-color: rgba(176, 141, 87, 0.45);
  color: #6b542e;
}

/* --- Empty / coming soon ------------------------------------------------- */

.empty {
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--ink-muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 254, 249, 0.5);
}

.empty h2,
.empty p {
  max-width: 28rem;
  margin-left: auto;
  margin-right: auto;
}

.empty .btn {
  margin-top: 0.85rem;
}

.coming-soon {
  padding: 1.5rem 1.4rem;
  border: 1px dashed rgba(176, 141, 87, 0.55);
  border-radius: var(--radius);
  background: var(--gold-soft);
}

.coming-soon .kicker {
  color: #8a6c3a;
}

.coming-soon h1 {
  font-size: 1.6rem;
}

.coming-soon .form-actions {
  margin-top: 1.15rem;
}

/* --- Stats / badges ------------------------------------------------------ */

.stat {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: var(--paper-inset);
  vertical-align: middle;
}

.badge-ok {
  color: var(--forest);
  background: var(--forest-soft);
  border-color: rgba(30, 77, 58, 0.2);
}

.badge-warn {
  color: var(--terracotta);
  background: var(--terracotta-soft);
  border-color: rgba(154, 59, 36, 0.22);
}

.badge-muted {
  color: var(--ink-faint);
  background: transparent;
}

.badge-kuerzel {
  font-family: var(--font-sans);
  letter-spacing: 0.08em;
  color: var(--forest);
  background: var(--forest-soft);
  border-color: rgba(30, 77, 58, 0.18);
}

.doc-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
}

.doc-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--line);
}

.doc-list li:first-child {
  border-top: 0;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.filter-row select,
.filter-row input {
  width: auto;
  min-width: 8rem;
}

.dropzone {
  position: relative;
  margin: 0.5rem 0 1rem;
  padding: 1.6rem 1.2rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-inset);
  text-align: center;
}

.dropzone p {
  margin: 0.15rem 0;
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-results {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.upload-item {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}

.upload-item.upload-queued,
.upload-item.upload-running,
.upload-item.upload-retry {
  color: var(--ink-muted);
}

.upload-item.upload-completed,
.upload-item.upload-duplikat {
  color: var(--forest);
}

.upload-item.upload-failed,
.upload-item.upload-fehler {
  color: var(--terracotta);
}

.pdf-frame {
  width: 100%;
  min-height: 28rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.doc-text {
  max-height: 28rem;
  overflow: auto;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--paper-inset);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Definition list (AfA) ---------------------------------------------- */

.facts {
  display: grid;
  grid-template-columns: minmax(10rem, 14rem) 1fr;
  gap: 0.45rem 1.25rem;
  margin: 0;
}

.facts dt {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.note {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

/* --- Login --------------------------------------------------------------- */

.page-login .topbar {
  display: none;
}

.page-login .main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: min(26rem, calc(100% - 2rem));
  padding: 2rem 0 5rem;
}

.page-login .site-footer {
  width: min(26rem, calc(100% - 2rem));
  text-align: center;
}

.login-card {
  width: 100%;
  box-shadow: 0 1px 1px rgba(28, 25, 20, 0.04), 0 10px 28px rgba(28, 25, 20, 0.06);
}

.login-card .brand {
  display: block;
  font-size: 1.65rem;
  margin-bottom: 0.2rem;
}

.login-card .subtitle {
  color: var(--ink-muted);
  margin-bottom: 1.35rem;
}

/* --- Mobile -------------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar {
    padding: 0.7rem 1rem;
  }

  .nav {
    flex-basis: 100%;
    order: 3;
  }

  .main {
    width: calc(100% - 1.5rem);
    padding-top: 1.5rem;
  }

  .site-footer {
    width: calc(100% - 1.5rem);
  }

  h1 {
    font-size: 1.5rem;
  }

  .facts {
    grid-template-columns: 1fr;
    gap: 0.15rem 0;
  }

  .facts dt {
    margin-top: 0.45rem;
  }

  .facts dt:first-child {
    margin-top: 0;
  }
}

/* --- Print (Steuer later) ------------------------------------------------ */

@media print {
  body::before {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  .topbar,
  .nav,
  .btn,
  .site-footer,
  .no-print {
    display: none !important;
  }

  .main {
    width: 100%;
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .card,
  .table-wrap,
  .stat {
    border-color: #ccc;
    background: #fff;
    box-shadow: none;
    break-inside: avoid;
  }
}
