:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --panel-soft: #f0f4f2;
  --text: #20231f;
  --muted: #667069;
  --line: #d9dfda;
  --accent: #176b5b;
  --accent-2: #245d90;
  --warn: #9b5b00;
  --danger: #a83434;
  --ok: #1f7a45;
  --shadow: 0 10px 30px rgba(32, 35, 31, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  /* 44px ist die Untergrenze fuer ein sicher treffbares Touch-Ziel.
     Vorher waren alle 17 interaktiven Elemente 38px hoch. */
  min-height: 44px;
  padding: 10px 14px;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button[aria-busy="true"] {
  opacity: 0.7;
  pointer-events: none;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.secondary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  /* 16px verhindert, dass iOS beim Fokussieren hineinzoomt. */
  font-size: 16px;
  padding: 10px 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-panel p {
  color: var(--muted);
  margin: 0 0 18px;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.nav button.active,
.nav button:hover {
  background: var(--panel-soft);
  border-color: var(--line);
}

.user-box {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.main {
  padding: 22px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.metric {
  display: grid;
  gap: 6px;
}

.metric strong {
  font-size: 30px;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.toolbar label {
  min-width: 150px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  /* Vorher 760px. In einem zweispaltigen Panel wurde damit ausgerechnet
     die Hinweis-Spalte abgeschnitten - also die eigentliche Information. */
  min-width: 0;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

/* Ueberschriften und Zahlen bleiben in einer Zeile, Fliesstext darf brechen. */
th {
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

td {
  white-space: normal;
  overflow-wrap: anywhere;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.status.OK,
.status.approved {
  color: var(--ok);
  background: #e8f4ed;
  border-color: #b9ddc7;
}

.status.WARN,
.status.requested {
  color: var(--warn);
  background: #fff5df;
  border-color: #efd191;
}

.status.BLOCKED,
.status.rejected {
  color: var(--danger);
  background: #fae9e9;
  border-color: #efbaba;
}

.terminal {
  min-height: 280px;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 18px;
}

.terminal strong {
  font-size: 42px;
}

.error {
  color: var(--danger);
}

/* --- Stempelzustand -------------------------------------------------- */
/* Der Zustand war vorher unsichtbar. Er ist jetzt das groesste Element
   auf dem Bildschirm und faerbt sich, damit er aus der Ferne lesbar ist. */

.clock-card {
  display: grid;
  gap: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
}

.clock-card.is-running {
  border-color: #b9ddc7;
  background: linear-gradient(180deg, #ecf7f0, var(--panel));
}

.clock-state {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.clock-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--muted);
  flex: none;
}

.is-running .clock-dot {
  background: var(--ok);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .is-running .clock-dot { animation: none; }
}

.clock-who {
  margin-top: -8px;
  font-size: 14px;
}

.clock-category {
  max-width: 320px;
}

.clock-elapsed {
  font-size: clamp(40px, 12vw, 60px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.clock-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--muted);
  font-size: 14px;
}

.clock-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.clock-actions button {
  min-height: 56px;
  font-size: 17px;
  font-weight: 700;
}

/* --- Rueckmeldung ----------------------------------------------------- */
/* Ersetzt alert(): blockiert nicht und funktioniert auf dem Handy. */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(460px, calc(100vw - 24px));
}

.toast {
  border-radius: 8px;
  padding: 13px 15px;
  font-weight: 600;
  color: #fff;
  background: var(--text);
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}

.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

.empty {
  display: grid;
  gap: 4px;
  padding: 22px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.empty strong { color: var(--text); }

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Mobil ------------------------------------------------------------ */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    /* Platz fuer die feste Navigationsleiste unten. */
    padding-bottom: 74px;
  }

  /* Die Seitenleiste belegte 340px, also 40% der Bildschirmhoehe, und
     klebte beim Scrollen fest. Navigation gehoert auf dem Handy nach
     unten in Daumenreichweite, alles andere kommt ins Profil. */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    gap: 0;
    padding: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(32, 35, 31, 0.07);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .sidebar .brand,
  .sidebar .user-box {
    display: none;
  }

  .nav {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0;
    width: 100%;
  }

  .nav button {
    min-height: 60px;
    border-radius: 0;
    border: 0;
    text-align: center;
    font-size: 12px;
    padding: 8px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav button.active {
    background: var(--panel-soft);
    color: var(--accent);
    font-weight: 700;
    box-shadow: inset 0 -3px 0 var(--accent);
  }

  .nav button.desk-only {
    display: none;
  }

  .main { padding: 16px; }

  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar h1 { font-size: 22px; }

  .toolbar { align-items: stretch; }
  .toolbar label { min-width: 0; width: 100%; }
  .segmented { display: grid; grid-auto-flow: column; width: 100%; }

  .toasts { bottom: 84px; }

  /* Tabellen als Karten. 61% der Kontotabelle waren sonst unsichtbar und
     man musste fuer jede Zeile horizontal scrollen. */
  .table-wrap { border: 0; overflow: visible; }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  tbody tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 4px 2px;
    margin-bottom: 10px;
  }

  tbody td {
    display: grid;
    grid-template-columns: minmax(0, 40%) minmax(0, 60%);
    gap: 12px;
    align-items: baseline;
    border-bottom: 1px solid var(--panel-soft);
    padding: 9px 12px;
    white-space: normal;
  }

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

  /* Spaltenname aus data-label, damit die Zelle allein verstaendlich ist. */
  tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  tbody td:empty { display: none; }
}
