/* ── Firmendaten-Scraper · Swiss Style ─────────────────────────────────────
   Strenges Raster, harte Kanten, ein roter Akzent, präzise Typo.           */

:root {
  --rot: #d5281e;
  --rot-dunkel: #b01f17;
  --tinte: #16150f;
  --papier: #f7f6f2;
  --weiss: #ffffff;
  --linie: #dcdad2;
  --linie-stark: #16150f;
  --grau: #6f6c63;
  --log-grund: #16150f;
  --font: "Helvetica Neue", Helvetica, "Neue Haas Grotesk", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--papier);
  color: var(--tinte);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--grau); }
.error { color: var(--rot); margin-top: 10px; font-size: 13px; }

/* ── Marke ── */

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  width: 13px; height: 13px; background: var(--rot);
  align-self: center; flex: none;
}
.brand-name {
  font-size: 15px; font-weight: 700; letter-spacing: 0.01em;
  text-transform: uppercase;
}
.brand-sub {
  font-size: 11px; color: var(--grau);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.brand-version {
  font-family: var(--mono); font-size: 11px; color: var(--grau);
}

/* ── Kopf & Navigation ── */

header {
  background: var(--weiss);
  border-bottom: 1px solid var(--linie-stark);
  padding: 0 32px;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; column-gap: 24px;
  min-height: 58px;
}

nav { display: flex; align-items: stretch; gap: 4px; }

button {
  font: inherit; cursor: pointer; border: none; background: none;
  color: inherit; border-radius: 0;
}

button.tab {
  padding: 19px 14px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--grau);
  border-bottom: 3px solid transparent;
  letter-spacing: 0.01em;
}
button.tab:hover { color: var(--tinte); }
button.tab.active {
  color: var(--tinte); font-weight: 700;
  border-bottom-color: var(--rot);
}

#logout { align-self: center; }

#lang-switch {
  align-self: center; display: flex;
  border: 1px solid var(--linie); margin: 0 6px;
}
#lang-switch button {
  padding: 4px 8px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; color: var(--grau);
}
#lang-switch button.active { background: var(--tinte); color: var(--weiss); }
#lang-switch button:not(.active):hover { color: var(--rot); }

/* ── Primär-Aktionen & Links ── */

button.primary {
  background: var(--tinte); color: var(--weiss);
  padding: 11px 20px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em;
  transition: background 120ms ease;
}
button.primary:hover { background: var(--rot); }
button.primary:disabled { background: var(--grau); cursor: default; }

button.danger {
  background: var(--rot); color: var(--weiss);
  padding: 11px 20px;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em;
}
button.danger:hover { background: var(--rot-dunkel); }

button.link {
  color: var(--tinte); font-size: 13px; padding: 4px 0;
  text-decoration: underline;
  text-decoration-color: var(--rot);
  text-underline-offset: 3px;
}
button.link:hover { color: var(--rot); }
button.link.back { margin-bottom: 18px; display: inline-block; }

/* ── Layout ── */

section { padding: 36px 32px 64px; max-width: 1240px; margin: 0 auto; }

.section-head {
  border-bottom: 1px solid var(--linie-stark);
  padding-bottom: 12px; margin-bottom: 28px;
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.section-head h2, #job-detail h2 {
  font-size: 26px; font-weight: 700; letter-spacing: -0.015em;
}
.section-head .muted { font-size: 13px; }

/* ── Karten ── */

.cards { display: grid; gap: 1px; background: var(--linie-stark); border: 1px solid var(--linie-stark); }
.form-cards { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stat-cards { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.card {
  background: var(--weiss);
  padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
  animation: aufbau 340ms ease-out both;
}
.form-cards .card:nth-child(2) { animation-delay: 60ms; }
.form-cards .card:nth-child(3) { animation-delay: 120ms; }

@keyframes aufbau {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.card-head { display: flex; flex-direction: column; gap: 4px; }
.card-kicker {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--rot);
}
.card h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.card-desc { font-size: 13px; color: var(--grau); margin-top: -8px; }

.card .primary { margin-top: auto; align-self: flex-start; }

/* Statistik-Karten (Status-Tab, von JS erzeugt: h2 = Zahl, p = Beschriftung) */
.stat-cards .card { gap: 6px; }
.stat-cards .card h2 {
  font-size: 34px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-cards .card p { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Formulare ── */

label { display: flex; flex-direction: column; gap: 6px; font-size: 12px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
label .hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--grau); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

input, textarea {
  font: inherit; font-size: 14px;
  border: 1px solid var(--linie);
  border-radius: 0;
  background: var(--weiss);
  padding: 10px 12px;
  width: 100%;
  transition: border-color 120ms ease;
}
input:hover, textarea:hover { border-color: var(--grau); }
input:focus, textarea:focus { outline: none; border-color: var(--tinte); box-shadow: inset 0 -2px 0 var(--rot); }
input::placeholder, textarea::placeholder { color: #b4b1a8; }

textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }

.checks { display: flex; flex-direction: column; gap: 10px; }
label.check {
  flex-direction: row; align-items: flex-start; gap: 10px;
  font-weight: 400; text-transform: none; letter-spacing: 0;
  font-size: 13px; cursor: pointer;
}
label.check input { width: auto; accent-color: var(--rot); margin-top: 2px; flex: none; }
label.check em { font-style: normal; color: var(--grau); }

input[type="search"] { max-width: 300px; }
.toolbar input[type="text"] { max-width: 180px; }
select {
  font: inherit; font-size: 13px;
  border: 1px solid var(--linie); border-radius: 0;
  background: var(--weiss); padding: 9px 10px;
}
select:focus { outline: none; border-color: var(--tinte); box-shadow: inset 0 -2px 0 var(--rot); }
.toolbar .primary { padding: 9px 14px; }
.cell-trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

/* ── Tabellen ── */

table {
  width: 100%; border-collapse: collapse;
  background: var(--weiss);
  border: 1px solid var(--linie-stark);
}
th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--linie-stark);
  background: var(--weiss);
}
td {
  text-align: left; padding: 10px 14px;
  border-bottom: 1px solid var(--linie);
  font-size: 13.5px;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--papier); }
td a { color: var(--tinte); }
td a:hover { color: var(--rot); }
td .link { margin-right: 10px; }

.toolbar { display: flex; gap: 16px; align-items: center; margin: 0 0 16px; }
.toolbar.pager { margin: 16px 0 0; }
.toolbar .muted { font-size: 13px; }

/* ── Status-Badges ── */

.badge {
  display: inline-block; padding: 3px 8px 2px;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em;
  white-space: nowrap;
  border: 1px solid currentColor;
}
.badge.running    { color: var(--rot); }
.badge.pending    { color: var(--grau); }
.badge.done       { color: #1c6b3c; }
.badge.error      { color: var(--rot); background: var(--rot); color: var(--weiss); border-color: var(--rot); }
.badge.cancelled  { color: var(--grau); }
.badge.neu        { color: #1c6b3c; }
.badge.geblockt   { background: var(--rot); color: var(--weiss); border-color: var(--rot); }
.badge.kontaktiert{ color: #96650f; }
.badge.treffer    { color: #2f4b8f; }

.badge.running::before {
  content: ""; display: inline-block;
  width: 6px; height: 6px; background: var(--rot);
  margin-right: 6px; vertical-align: 1px;
  animation: puls 1s ease-in-out infinite alternate;
}
@keyframes puls { from { opacity: 1; } to { opacity: 0.25; } }

/* ── Job-Detail & Log ── */

#job-detail-meta {
  margin: 14px 0; display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  font-size: 13px;
}
#job-detail-actions { display: flex; gap: 10px; margin-bottom: 4px; }
#job-detail-actions a { text-decoration: none; }

.log {
  background: var(--log-grund); color: #e8e6dd;
  border-top: 3px solid var(--rot);
  padding: 18px 20px;
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  max-height: 520px; overflow-y: auto; white-space: pre-wrap;
  margin-top: 14px;
}

/* ── Sync-Zeile ── */

.sync-row { display: flex; gap: 18px; align-items: center; margin-top: 24px; flex-wrap: wrap; }
.sync-row .muted { font-size: 13px; }

/* ── Login ── */

#login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; }

.login-box {
  width: 360px;
  background: var(--weiss);
  border: 1px solid var(--linie-stark);
  border-top: 4px solid var(--rot);
  padding: 40px 36px;
  display: flex; flex-direction: column; gap: 8px;
  animation: aufbau 340ms ease-out both;
}
.brand-big { flex-direction: column; align-items: flex-start; gap: 14px; }
.brand-big .brand-mark { width: 18px; height: 18px; align-self: flex-start; }
.brand-big .brand-name { font-size: 19px; line-height: 1.3; }
.login-sub {
  font-size: 11px; color: var(--grau);
  text-transform: uppercase; letter-spacing: 0.09em;
  margin-bottom: 18px;
}
.google-btn {
  display: block; text-align: center; text-decoration: none;
  background: var(--tinte); color: var(--weiss);
  padding: 12px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em;
  margin-bottom: 14px;
}
.google-btn:hover { background: var(--rot); }
#password-login summary {
  font-size: 12px; cursor: pointer; list-style: none;
  text-decoration: underline; text-underline-offset: 3px;
  margin-bottom: 10px;
}
#password-login summary::-webkit-details-marker { display: none; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box button { background: var(--tinte); color: var(--weiss);
  padding: 11px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.09em; }
.login-box button:hover { background: var(--rot); }

/* ── Scrappy, die Krabbe (sichtbar nur, solange ein Job läuft) ── */

#scrappy {
  position: fixed; bottom: 2px; left: 0;
  z-index: 60; pointer-events: none;
  animation: wuseln 18s linear infinite;
}
#scrappy img {
  display: block; height: 52px; width: auto;
  /* Watscheln: ständiges Hin-und-her-Spiegeln + leichtes Wippen = Laufgefühl */
  animation: watscheln 640ms steps(1) infinite, wippen 320ms ease-in-out infinite alternate;
}
@keyframes wuseln {
  0%   { transform: translateX(-60px); }
  50%  { transform: translateX(calc(100vw + 30px)); }
  100% { transform: translateX(-60px); }
}
@keyframes watscheln {
  0%, 100% { transform: scaleX(1); }
  50%      { transform: scaleX(-1); }
}
@keyframes wippen {
  from { margin-bottom: 0; }
  to   { margin-bottom: 3px; }
}
/* Der Ruf: taucht periodisch als kleine Sprechblase über Scrappy auf */
#scrappy::after {
  content: "whoop whoop whoop";
  position: absolute; bottom: 56px; left: -80%;
  font-family: var(--mono); font-size: 10px; white-space: nowrap;
  color: var(--tinte); background: var(--weiss);
  border: 1px solid var(--linie-stark);
  padding: 2px 6px;
  opacity: 0;
  animation: rufen 18s linear infinite;
}
@keyframes rufen {
  0%, 18%  { opacity: 0; }
  22%, 40% { opacity: 1; }
  44%, 68% { opacity: 0; }
  72%, 90% { opacity: 1; }
  94%, 100%{ opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #scrappy { display: none; }
}

/* ── Schmale Bildschirme ── */

@media (max-width: 720px) {
  header { padding: 0 16px; }
  section { padding: 24px 16px 48px; }
  button.tab { padding: 15px 10px 12px; }
  .field-row { grid-template-columns: 1fr; }
}
