:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --card: #222b36;
  --border: #2f3b4a;
  --text: #e8eef5;
  --muted: #9aa7b5;
  --accent: #3d8bfd;
  --danger: #e35d6a;
  --ok: #3ecf8e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 0.25rem;
}

.auth-brand-logo {
  display: block;
  margin: 0 auto 0.65rem;
  height: 3rem;
  width: auto;
  max-width: 11rem;
  object-fit: contain;
}

.auth-brand-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.auth-card--wide {
  width: min(480px, 100%);
  max-width: 100%;
}

.auth-h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.muted.small {
  font-size: 0.82rem;
  line-height: 1.4;
}

.checkbox-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.85rem;
  color: var(--muted);
}

.checkbox-row input[type='checkbox'] {
  width: auto;
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.totp-qr-wrap {
  margin: 0.5rem 0;
  text-align: center;
  min-height: 4rem;
}

.totp-qr-wrap img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

code.totp-secret {
  display: block;
  margin-top: 0.25rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border-radius: 6px;
  font-size: 0.72rem;
  word-break: break-all;
  color: var(--text);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stack label span {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="time"],
input:not([type]) {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.secondary {
  background: #2a3441;
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  background: #3a2228;
  border-color: #6b2f3a;
  color: #ffb4bc;
}

.muted {
  color: var(--muted);
}

.app-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #141b24;
  position: sticky;
  top: 0;
  z-index: 5;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: min(100%, 16rem);
}

.header-logo {
  flex-shrink: 0;
  height: 2.75rem;
  width: auto;
  max-width: 9.5rem;
  object-fit: contain;
  display: block;
}

.header-brand-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.header-brand-heading {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
}

.header-brand-dashboard {
  font-weight: 600;
  color: var(--muted);
}

.header-brand-name {
  font-weight: 700;
  color: var(--text);
}

.header-brand-date {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.3;
}

.title {
  margin: 0;
  font-size: 1.15rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-pill {
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.main-view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.main-view-tab {
  font-weight: 600;
}

.main-panel--tkst {
  padding: 0.75rem 1rem 1.5rem;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tkst-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  align-items: flex-start;
  min-width: min-content;
}

.tkst-item {
  flex: 0 0 auto;
}

.tkst-iframe-wrap {
  width: 530px;
  height: 170px;
  overflow: hidden;
  line-height: 0;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0e12;
}

.tkst-iframe {
  display: block;
  width: 530px;
  height: 170px;
  border: 0;
  overflow: hidden;
  vertical-align: top;
}

.date-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  border-color: var(--accent);
  background: #1e2a3d;
}

.date-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.date-label span {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.live-bar {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.live-bar.ok {
  color: var(--ok);
}

.filter-toolbar {
  margin-top: 0.65rem;
}

.filter-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.filter-quick-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.filter-quick-btn {
  padding: 0.32rem 0.55rem;
  font-size: 0.82rem;
  min-height: 0;
}

.filter-quick-btn.is-active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.filter-toolbar label {
  font-size: 0.88rem;
  color: #fff;
  font-weight: 500;
}

.filter-inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.filter-inline-check input {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}

.filter-toolbar select {
  min-width: 14rem;
  max-width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
}

.filter-toolbar .filter-sort-select {
  min-width: 12.5rem;
}

.filter-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.app-main {
  padding: 0.75rem;
  max-width: min(100%, calc(580px * 3 + 4rem));
  margin: 0 auto;
}

@media (max-width: 600px) {
  .app-main {
    padding: 0.5rem;
  }
}

.grid-blocks {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  justify-items: stretch;
}

@media (min-width: 620px) {
  .grid-blocks {
    grid-template-columns: repeat(auto-fill, 580px);
    justify-content: center;
  }
}

.block-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  max-width: 580px;
  margin: 0 auto;
}

@media (min-width: 620px) {
  .block-card {
    width: 580px;
    max-width: 580px;
    margin: 0;
  }
}

.block-head {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.block-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
}

.block-head-titles {
  flex: 1 1 auto;
  min-width: 7rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.block-note-wrap {
  flex: 1 1 12rem;
  max-width: 22rem;
  min-width: 8rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

textarea.block-note-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 3.2rem;
  font-size: 0.85rem;
  line-height: 1.35;
  padding: 0.4rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: #ff9a9a;
  resize: vertical;
  touch-action: manipulation;
}

textarea.block-note-input::placeholder {
  color: rgba(255, 154, 154, 0.45);
}

textarea.block-note-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

textarea.block-note-input:read-only {
  cursor: not-allowed;
  background: #1e2630;
  color: rgba(255, 154, 154, 0.55);
  border-color: #3a4656;
}

.block-note-meta {
  font-size: 0.65rem;
  color: var(--muted);
}

.block-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.block-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.c-green {
  border-left: 4px solid #3ecf8e;
}
.c-pink {
  border-left: 4px solid #ff7eb3;
}
.c-yellow {
  border-left: 4px solid #ffd56a;
}
.c-blue {
  border-left: 4px solid #6ab0ff;
}
.c-orange {
  border-left: 4px solid #ffb86b;
}
.c-teal {
  border-left: 4px solid #5ee0d0;
}
.c-purple {
  border-left: 4px solid #c79bff;
}
.c-gray {
  border-left: 4px solid #9aa7b5;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.mini-table th,
.mini-table td {
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.4rem;
  vertical-align: top;
}

.mini-table td.slot-cell {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mini-table thead th {
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
}

.mini-table tbody th {
  text-align: left;
  color: #fff;
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.35;
  width: auto;
  min-width: 4.5rem;
}

.mini-table tbody th.product-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  vertical-align: top;
}

.mini-table tbody th .product-name {
  line-height: 1.3;
}

.mini-table tbody th .product-history-btn {
  flex-shrink: 0;
  margin: 0;
  padding: 0.12rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  color: var(--accent);
  background: rgba(30, 42, 61, 0.85);
  border: 1px solid rgba(106, 176, 255, 0.45);
  border-radius: 6px;
  cursor: help;
  font-family: inherit;
}

.mini-table tbody th .product-history-btn:hover {
  background: rgba(40, 56, 82, 0.95);
  border-color: rgba(106, 176, 255, 0.75);
  color: #8ec8ff;
}

/* Produkt-Hover: Preisvergleich letzte Werktage */
.product-popover {
  z-index: 200;
  max-width: min(96vw, 52rem);
  padding: 0.55rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  font-size: 0.78rem;
  color: var(--text);
  pointer-events: auto;
}

.product-popover[hidden] {
  display: none !important;
}

.product-popover-title {
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 0.45rem;
  color: #fff;
}

.product-popover-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.product-popover-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 280px;
}

.product-popover-table th,
.product-popover-table td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.45rem;
  text-align: right;
  white-space: nowrap;
}

.product-popover-table thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-align: center;
}

.product-popover-table tbody th {
  text-align: left;
  color: #fff;
  font-weight: 500;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-popover-loading,
.product-popover-empty,
.product-popover-error {
  margin: 0;
  padding: 0.35rem 0.15rem;
  font-size: 0.82rem;
}

.product-popover-error {
  color: #e35d6a;
}

.product-popover-table td.ph-rank-cheapest {
  background: rgba(62, 207, 142, 0.22);
  color: #b8f0d0;
  font-weight: 600;
}

.product-popover-table td.ph-rank-second {
  background: rgba(255, 213, 106, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 213, 106, 0.35);
}

.product-popover-table td.ph-rank-worst {
  background: rgba(227, 93, 106, 0.2);
  color: #ffb3bc;
  font-weight: 600;
}

@media (min-width: 700px) {
  .mini-table tbody th {
    width: 22%;
  }
}

.slot-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  width: 100%;
}

@media (min-width: 480px) {
  .slot-grid {
    grid-template-columns: repeat(2, minmax(6.25rem, auto));
    width: 100%;
    min-width: min(100%, 14rem);
  }
}

@media (min-width: 900px) {
  .slot-grid {
    grid-template-columns: repeat(4, minmax(5.75rem, auto));
    width: max-content;
    max-width: 100%;
    min-width: min(100%, 26rem);
  }
}

@media (min-width: 1200px) {
  .slot-grid {
    grid-template-columns: repeat(4, minmax(5.75rem, auto));
    min-width: min(100%, 26rem);
  }
}

.slot {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 5.75rem;
  max-width: 6rem;
}

.slot label {
  font-size: 0.72rem;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.slot input.cell-input-time,
.slot input.cell-input--price {
  box-sizing: border-box;
  width: 5.5rem;
  min-width: 5.5rem;
  max-width: 5.5rem;
  min-height: 2.5rem;
  font-size: 0.95rem;
  line-height: 1.3;
  padding: 0.4rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  touch-action: manipulation;
}

.slot input.cell-input-time {
  cursor: default;
  background: #1e2630;
  color: var(--muted);
  border-color: #3a4656;
  pointer-events: none;
  user-select: none;
}

.slot input.cell-input--price:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.slot input.cell-input--price:read-only {
  cursor: not-allowed;
  background: #1e2630;
  color: var(--muted);
  border-color: #3a4656;
}

.modal-msg-pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
  max-height: 14rem;
  overflow: auto;
}

.meta {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.meta-user {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 500;
}

.slot.slot--rank-cheapest {
  padding: 3px;
  margin: -3px;
  border-radius: 10px;
  animation: slot-rank-green-pulse 1.4s ease-in-out infinite;
}

.slot.slot--rank-second {
  padding: 3px;
  margin: -3px;
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(255, 213, 106, 0.65);
}

.slot.slot--rank-worst {
  padding: 3px;
  margin: -3px;
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(227, 93, 106, 0.75);
}

@keyframes slot-rank-green-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(140, 220, 170, 0.45);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.75), 0 0 14px rgba(62, 207, 142, 0.25);
  }
}

@media (prefers-reduced-motion: reduce) {
  .slot.slot--rank-cheapest {
    animation: none;
    box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.55);
  }
}

/* Modal */
.modal-root[hidden] {
  display: none !important;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 2rem));
  max-height: min(80vh, 640px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal-panel--wide {
  width: min(560px, calc(100% - 2rem));
}

.modal-msg {
  margin: 0 0 1rem;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.admin-user-row {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.admin-user-main {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
}

.admin-user-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.admin-form {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
