/* ======================================================================
   TimeControl — Komponenten
   Buttons, Formulare, Chips, Karten, Tabellen, Meldungen, Modals.
   Setzt tokens.css voraus.
   ====================================================================== */

/* ----------------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);

  height: var(--control-md);
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid transparent;

  font-family: inherit;
  font-weight: 540;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;

  cursor: pointer;
  text-decoration: none;
  transition: transform .08s ease, background var(--t-fast),
              border-color var(--t-fast), color var(--t-fast),
              box-shadow var(--t-fast);
}

.btn:active { transform: translateY(1px); }

/* Primär: tiefes Schwarz statt Blau — ruhiger und wertiger */
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: var(--accent); }

.btn-accent { background: var(--accent); color: var(--accent-fg); }
.btn-accent:hover { background: var(--accent-ink); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--field-border);
}
.btn-ghost:hover { background: var(--bg-elev); border-color: var(--ink-3); }

.btn-danger {
  background: var(--bad-soft);
  color: var(--bad-ink);
  border-color: transparent;
}
.btn-danger:hover { background: var(--bad); color: #fff; }

.btn-link {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 0;
  height: auto;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.btn-sm { height: var(--control-sm); padding: 0 13px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: var(--control-lg); padding: 0 22px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* Nur ein Symbol: quadratisch, aber in derselben Höhe wie alles andere */
.btn-icon {
  width: var(--control-md);
  height: var(--control-md);
  padding: 0;
  flex-shrink: 0;
}
.btn-icon.btn-sm { width: var(--control-sm); height: var(--control-sm); }
.btn-icon.btn-lg { width: var(--control-lg); height: var(--control-lg); }

/* ----------------------------------------------------------------------
   Formulare
   ---------------------------------------------------------------------- */
.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-md);
  padding: 0 14px;

  background: var(--bg-elev);
  border: 1px solid var(--field-border);
  border-radius: 10px;

  font-family: inherit;
  font-size: 15px;
  color: var(--ink);

  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

/* Kleine Variante – passt zu .btn-sm */
.input-sm,
.select-sm {
  height: var(--control-sm);
  padding: 0 12px;
  font-size: 14px;
  border-radius: 9px;
}
.select-sm { padding-right: 34px; background-size: 15px; }

.input-lg { height: var(--control-lg); font-size: 16px; border-radius: 12px; }

.textarea {
  height: auto;
  min-height: 104px;
  padding: 12px 14px;
  line-height: 1.5;
  resize: vertical;
}

/* Feldbreiten, damit Filterzeilen nicht ausfransen */
.input-auto { width: auto; min-width: 150px; }
.field-grow { flex: 1 1 180px; min-width: 150px; }

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder,
.textarea::placeholder { color: var(--ink-4); }

.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--bg-sunken);
  color: var(--ink-3);
  cursor: not-allowed;
}

.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235B5E68' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  cursor: pointer;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239AA0AB' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 540;
  color: var(--ink-2);
}

.field { margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }

.hint { font-size: 12px; color: var(--ink-3); margin-top: 6px; }

/* ----------------------------------------------------------------------
   Werkzeugleiste / Filterzeile
   Alle Bedienelemente sitzen auf einer Grundlinie, unabhängig davon,
   ob darüber eine Beschriftung steht oder nicht.
   ---------------------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
}
.toolbar .field { margin-bottom: 0; }

/* Elemente ohne Beschriftung auf die Höhe der beschrifteten schieben */
.toolbar > .btn,
.toolbar > .toolbar-end {
  margin-top: auto;
}

/* Zwei Felder nebeneinander, z. B. Datum und Uhrzeit */
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}
@media (max-width: 420px) {
  .field-pair { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------------------------
   Umschalter mit zwei bis drei Möglichkeiten
   Ersetzt ein Ankreuzfeld dort, wo es um eine Entweder-oder-Wahl geht.
   Arbeitet mit Radiofeldern – funktioniert also ohne JavaScript.
   ---------------------------------------------------------------------- */
.segmented {
  display: inline-flex;
  align-items: center;
  height: var(--control-md);
  padding: 3px;
  gap: 2px;

  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  flex-shrink: 0;
}

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 14px;
  border-radius: 8px;

  font-size: 13px;
  font-weight: 540;
  color: var(--ink-3);
  white-space: nowrap;
  cursor: pointer;

  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.segmented label:hover { color: var(--ink); }

.segmented input:checked + label {
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.segmented input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.segmented label svg { flex-shrink: 0; opacity: .8; }

.segmented-sm { height: var(--control-sm); }
.segmented-sm label { padding: 0 11px; font-size: 12px; }

.field-error .input,
.field-error .select { border-color: var(--bad); }
.field-error .hint { color: var(--bad); }

/* Checkbox / Toggle-Zeile */
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  padding: 10px 0;
}
.check input[type="checkbox"] {
  width: 18px; height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.check .check-text { font-size: 14px; color: var(--ink-2); }
.check .check-text b { display: block; color: var(--ink); font-weight: 540; }
.check .check-text span { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ----------------------------------------------------------------------
   Karten & Flächen
   ---------------------------------------------------------------------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--pad-card);
}

/* Flächen richten sich nach ihrem Inhalt.
   Liegen sie in einem Raster, streckt dieses sie ohnehin auf die Höhe
   der Zeile (align-items: stretch) – eine feste Höhe ist dafür nicht
   nötig und würde die Fläche ausserhalb eines Rasters unnötig aufblähen. */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;

  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  min-height: 60px;
  padding: 14px var(--pad-card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.panel-h h3 { font-size: 16px; font-weight: 600; }

.panel-body { padding: var(--pad-card); flex: 1; min-width: 0; }

/* Fuß einer Fläche sitzt immer unten, auch wenn der Inhalt kurz ist */
.panel-foot {
  margin-top: auto;
  padding: 14px var(--pad-card);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

/* ----------------------------------------------------------------------
   Chips / Badges
   ---------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;

  font-size: 12px;
  font-weight: 540;
  white-space: nowrap;

  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
/* Text auf farbigen Flächen nutzt den dunkleren "-ink"-Ton,
   damit auch kleine Schrift 4.5:1 erreicht. */
.chip.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.chip.good   { background: var(--good-soft);   color: var(--good-ink);   border-color: transparent; }
.chip.warn   { background: var(--warn-soft);   color: var(--warn-ink);   border-color: transparent; }
.chip.bad    { background: var(--bad-soft);    color: var(--bad-ink);    border-color: transparent; }
[data-theme="dark"] .chip.accent { color: var(--accent); }

/* Pulsierender Punkt für „läuft gerade" */
.dot-live {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ink-4);
  display: inline-block;
  flex-shrink: 0;
}
.dot-live.on { background: var(--good); animation: tc-pulse 1.6s ease-in-out infinite; }
.dot-live.paused { background: var(--warn); }

@keyframes tc-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}

/* Farbpunkt einer Kategorie */
.swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  display: inline-block;
}

/* ----------------------------------------------------------------------
   Meldungen
   ---------------------------------------------------------------------- */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid transparent;
}
.alert-error   { background: var(--bad-soft);    color: var(--bad-ink); }
.alert-success { background: var(--good-soft);   color: var(--good-ink); }
.alert-warn    { background: var(--warn-soft);   color: var(--warn-ink); }
.alert-info    { background: var(--accent-soft); color: var(--accent-ink); }
[data-theme="dark"] .alert-info { color: var(--accent); }

/* Links innerhalb einer Meldung müssen sich vom Meldungstext abheben */
.alert a { color: inherit; text-decoration: underline; text-underline-offset: 2px; font-weight: 560; }
.alert svg { flex-shrink: 0; margin-top: 2px; }

/* ----------------------------------------------------------------------
   Tabellen
   ---------------------------------------------------------------------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; flex: 1; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  height: 42px;
  padding: 0 var(--pad-card);
  font-size: 12px;
  font-weight: 540;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-3);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td {
  height: 56px;
  padding: 10px var(--pad-card);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}

/* Schaltflächen in Tabellenzellen bleiben auf einer Linie */
.table td .row { justify-content: flex-end; gap: 6px; }
.table td form { display: inline-flex; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--bg-sunken); }
.table .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.table td.right, .table th.right { text-align: right; }

/* ----------------------------------------------------------------------
   Leerzustände
   ---------------------------------------------------------------------- */
/* Leerzustände füllen die Fläche und sitzen mittig – so bleibt eine
   leere Kachel genauso hoch wie eine gefüllte daneben. */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-3);
  min-height: 200px;
}
.empty .empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  border-radius: 12px;
  background: var(--bg-sunken);
  display: grid;
  place-items: center;
  color: var(--ink-4);
}
.empty h4 { font-size: 16px; color: var(--ink); margin-bottom: 6px; }
.empty p { font-size: 14px; color: var(--ink-3); max-width: 42ch; margin: 0 auto 18px; }

/* ----------------------------------------------------------------------
   Modal
   ---------------------------------------------------------------------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}
.modal-back[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: tc-modal-in .18s ease-out;
}
.modal-wide { max-width: 720px; }

@keyframes tc-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}
.modal-h h3 { font-size: 18px; font-weight: 600; }
.modal-body { padding: 24px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.modal-close {
  background: transparent;
  border: 0;
  color: var(--ink-3);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.modal-close:hover { color: var(--ink); background: var(--bg-sunken); }

/* ----------------------------------------------------------------------
   Fortschrittsbalken
   ---------------------------------------------------------------------- */
.progress {
  height: 6px;
  background: var(--bg-sunken);
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width var(--t-med);
}
.progress.over > span { background: var(--good); }
.progress.under > span { background: var(--warn); }

/* ----------------------------------------------------------------------
   Eyebrow (kleine Überschrift)
   ---------------------------------------------------------------------- */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 560;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.eyebrow .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ----------------------------------------------------------------------
   Markenzeichen
   ---------------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--ink);
}
/* Das Logo wird als Bild eingebunden (assets/icons/icon-192.png),
   damit Kopfzeile, Favicon und Startbildschirm-Symbol übereinstimmen. */
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
  display: block;
  object-fit: contain;
}
.brand-mark-lg { width: 36px; height: 36px; border-radius: 9px; }
