:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --green: #059669;
  --green-soft: #d1fae5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px 16px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 10px;
}

.header-main {
  flex: 1 1 220px;
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.header .subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.upload-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-bar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
}

.upload-bar label:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-bar input[type="file"] {
  display: none;
}

.upload-bar .status {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.upload-bar .status.ready {
  color: var(--green);
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 8px;
  flex-wrap: wrap;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.tab:hover {
  border-color: #cbd5e1;
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab .badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab:not(.active) .badge {
  background: var(--bg);
  color: var(--text-muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.metric:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.metric.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.metric:active {
  transform: scale(0.98);
}

.metric .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-bottom: 4px;
}

.metric .dot.blue { background: var(--accent); }
.metric .dot.amber { background: var(--amber); }
.metric .dot.green { background: var(--green); }
.metric .dot.red { background: var(--red); }

.metric .label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
  line-height: 1.2;
}

.metric .value {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.toolbar-filters {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.search-wrap {
  flex: 1 1 200px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 7px 10px 7px 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.toolbar select {
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-export:hover {
  background: var(--surface-2);
}

.btn-export-pdf {
  color: var(--accent);
  border-color: #bfdbfe;
  background: var(--accent-soft);
}

.btn-export-pdf:hover {
  background: #bfdbfe;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 210px);
  min-height: 280px;
}

.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table col.col-code { width: 8%; }
.data-table col.col-link { width: 42px; }
.data-table col.col-desc { width: auto; }
.data-table col.col-num { width: 11%; }
.data-table col.col-pct { width: 7%; }

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
}

th {
  padding: 8px 14px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  vertical-align: bottom;
}

th.col-left {
  text-align: left;
}

th.col-num {
  text-align: right;
  padding-left: 8px;
  padding-right: 14px;
}

th.col-link-h {
  text-align: center;
  padding-left: 6px;
  padding-right: 6px;
  cursor: default;
}

td.link-cell {
  text-align: center;
  padding-left: 6px;
  padding-right: 6px;
  vertical-align: middle;
}

.ecat-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.ecat-link:hover {
  background: var(--accent);
  color: #fff;
}

th .th-text {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
}

th.col-left .th-text {
  justify-content: flex-start;
}

th.col-num .th-text {
  justify-content: flex-end;
  width: 100%;
}

th:hover {
  color: var(--text);
}

th .sort-icon {
  opacity: 0.45;
  font-size: 0.62rem;
  flex-shrink: 0;
}

th.sorted .sort-icon {
  opacity: 1;
  color: var(--accent);
}

td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow: hidden;
}

tbody tr.data-row:hover {
  background: #f8fafc;
}

tr.virtual-pad td {
  padding: 0;
  border: none;
  line-height: 0;
  font-size: 0;
}

tr.virtual-pad .pad-cell {
  padding: 0;
  border: none;
  overflow: hidden;
}

td.code {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: left;
}

td.desc {
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.desc-de {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.desc-en {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.desc.desc-both .desc-de,
td.desc.desc-both .desc-en {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 14px;
}

td.num .positive,
td.num .negative,
td.num .neutral {
  display: inline-block;
  min-width: 100%;
  text-align: right;
}

.pill-staffel {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.positive {
  color: var(--red);
  font-weight: 600;
}

.negative {
  color: var(--green);
  font-weight: 600;
}

.neutral {
  color: var(--text-muted);
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 0.95rem;
}

.footer-note {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .metrics {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .app {
    padding: 10px 12px;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .table-wrap {
    max-height: calc(100vh - 280px);
  }
}
