:root {
  color-scheme: light dark;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  line-height: 1.4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #0b0b0f;
  color: #f5f5f5;
}

.persistent-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 32px;
  background: rgba(11, 11, 15, 0.95);
  border-bottom: 1px solid #2a2a3d;
  backdrop-filter: blur(8px);
}

body.has-files .persistent-header {
  display: flex;
}

.persistent-header__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 600;
}

.header-logo {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.persistent-header__controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.app {
  max-width: none;
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 24px 32px 48px;
  display: grid;
  gap: 20px;
}

.app__header h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

body.has-files .app__header {
  display: none;
}

body.has-files .upload-card {
  display: none;
}

.card {
  background: #151521;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.dropzone {
  position: relative;
  border: 2px dashed #3b3b5a;
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.dropzone.is-dragging {
  border-color: #8a5cff;
  background: rgba(138, 92, 255, 0.08);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone__inner {
  display: grid;
  gap: 12px;
  justify-items: center;
}

button {
  appearance: none;
  border: 1px solid #3b3b5a;
  background: #23233a;
  color: #f5f5f5;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}

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

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

body.has-files .card .controls {
  display: none;
}

.checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.status {
  font-size: 0.9rem;
  color: #c7c7d1;
}

.status--header {
  font-size: 0.85rem;
  color: #c7c7d1;
}

.file-list {
  display: grid;
  gap: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  align-items: center;
}

.tabs.is-hidden {
  display: none;
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: #1c1c2a;
  white-space: nowrap;
  line-height: 1;
  flex: 0 0 auto;
}

.is-hidden {
  display: none;
}

.tab.is-active {
  border-color: #8a5cff;
  color: #8a5cff;
}

.tab-panel.is-hidden {
  display: none;
}

.empty {
  padding: 16px;
  border: 1px dashed #2a2a3d;
  border-radius: 12px;
  color: #c7c7d1;
}

.file-card {
  background: #12121c;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.file-card__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.file-card__meta {
  font-size: 0.9rem;
  color: #c7c7d1;
}

.pill {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid #3b3b5a;
}

.pill.ok {
  border-color: #2ecc71;
  color: #2ecc71;
}

.pill.warn {
  border-color: #f39c12;
  color: #f39c12;
}

.pill.error {
  border-color: #e74c3c;
  color: #e74c3c;
}

.file-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.table-wrapper {
  overflow: auto;
  border: 1px solid #2a2a3d;
  border-radius: 10px;
  max-height: min(65vh, 720px);
}

.data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  background: #1c1c2a;
  z-index: 1;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a3d;
  text-align: left;
  vertical-align: top;
}

.data-table tbody tr:hover {
  background: rgba(138, 92, 255, 0.12);
}

.data-table td {
  min-width: 140px;
  max-width: 320px;
}

.data-table td.raw-text {
  max-width: 220px;
}

.cell {
  max-width: 320px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}

.data-table td.raw-text .cell {
  max-width: 220px;
}

body.is-wrap .table-wrapper {
  overflow-x: hidden;
}

body.is-wrap .data-table {
  width: 100%;
}

body.is-wrap .data-table td {
  max-width: none;
  min-width: 120px;
}

body.is-wrap .cell {
  max-width: none;
  overflow: visible;
  white-space: normal;
}

.raw-details {
  display: inline-block;
}

.raw-details summary {
  cursor: pointer;
  color: #8a5cff;
}

.raw-details pre {
  margin: 8px 0 0;
  padding: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  white-space: pre-wrap;
  max-width: 520px;
}

.analysis-filter {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
  margin-bottom: 16px;
}

.tag-filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chart {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.chart h3 {
  margin: 0;
  font-size: 1rem;
}

.chart svg {
  width: 100%;
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 240px) 1fr minmax(80px, max-content);
  gap: 12px;
  align-items: center;
}

.bar-label {
  font-size: 0.85rem;
  color: #c7c7d1;
  word-break: break-word;
}

.bar-track {
  position: relative;
  height: 16px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
}

.bar-value {
  font-size: 0.85rem;
  text-align: right;
  color: #f5f5f5;
}

.chart-scroll {
  overflow-x: auto;
}

.chart-scroll svg {
  display: block;
  min-width: 600px;
}

.pie-chart {
  display: grid;
  grid-template-columns: minmax(200px, 320px) 1fr;
  gap: 16px;
  align-items: center;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.85rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  display: inline-block;
}

.chart-label {
  fill: #c7c7d1;
  font-size: 12px;
}

.chart-value {
  fill: #f5f5f5;
  font-size: 12px;
}

.chart-axis {
  fill: #c7c7d1;
  font-size: 11px;
}

.tags-table {
  display: grid;
  gap: 12px;
}

.tags-row {
  padding: 12px;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
  display: grid;
  gap: 8px;
}

.tags-row__label {
  font-weight: 600;
}

.tags-row__meta {
  color: #c7c7d1;
  font-size: 0.85rem;
}

.tag-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  border-radius: 999px;
  border: 1px solid #3b3b5a;
  padding: 4px 10px;
  font-size: 0.8rem;
  background: transparent;
  color: inherit;
}

.tag-chip.auto {
  border-style: dashed;
}

.tag-chip.user {
  background: #26263a;
}

.tag-chip.empty {
  opacity: 0.7;
}

.tag-input {
  display: grid;
  gap: 8px;
}

.tag-input input {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #3b3b5a;
  background: #1a1a26;
  color: inherit;
}

.tag-suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tag-suggestion-label {
  font-size: 0.8rem;
  color: #c7c7d1;
}

.tag-builder {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.tag-builder-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
}

.tag-builder-form input {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #3b3b5a;
  background: #1a1a26;
  color: inherit;
}

.tag-error {
  color: #e74c3c;
  font-size: 0.85rem;
}

.tag-matches-info {
  font-size: 0.85rem;
  color: #c7c7d1;
}

.tag-match-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid #2a2a3d;
  border-radius: 10px;
  padding: 8px;
}

.tag-match-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: flex-start;
  padding: 6px;
  border-radius: 8px;
}

.tag-match-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tag-select-all {
  margin-top: 4px;
}

.tag-match-text {
  display: grid;
  gap: 4px;
}

.tag-match-meta {
  font-size: 0.8rem;
  color: #c7c7d1;
}

.tag-builder-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.tag-empty {
  font-size: 0.85rem;
  color: #c7c7d1;
}

.tag-untagged {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.tag-untagged-list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  border: 1px solid #2a2a3d;
  border-radius: 10px;
  padding: 8px;
}

.tag-untagged-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: flex-start;
  padding: 6px;
  border-radius: 8px;
}

.tag-untagged-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.tag-untagged-footer {
  display: grid;
  grid-template-columns: max-content minmax(200px, 1fr) max-content;
  gap: 12px;
  align-items: center;
}

.tag-untagged-footer input {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #3b3b5a;
  background: #1a1a26;
  color: inherit;
}

.group-list {
  display: grid;
  gap: 12px;
}

.group-card {
  padding: 12px;
  border: 1px solid #2a2a3d;
  border-radius: 12px;
  display: grid;
  gap: 8px;
}

.group-card__header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.group-card__title {
  font-weight: 600;
}

.group-card__meta {
  color: #c7c7d1;
  font-size: 0.85rem;
}

.group-card__pattern {
  font-size: 0.8rem;
  color: #c7c7d1;
}

.meta-details {
  display: inline-block;
}

.meta-details summary {
  cursor: pointer;
  color: #8a5cff;
}

.meta-list {
  margin: 8px 0 0;
  display: grid;
  gap: 6px;
}

.meta-item {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px;
}

.meta-item dt {
  font-weight: 600;
}

.toggle[aria-pressed="true"] {
  border-color: #8a5cff;
  box-shadow: 0 0 0 1px rgba(138, 92, 255, 0.4);
}

@media (prefers-color-scheme: light) {
  body {
    background: #f7f7fb;
    color: #1c1c28;
  }

  .persistent-header {
    background: rgba(247, 247, 251, 0.95);
    border-bottom-color: #e3e3ef;
  }

  .card,
  .file-card {
    background: #ffffff;
    border-color: #e3e3ef;
  }

  .dropzone {
    border-color: #b4b4cc;
  }

  .dropzone.is-dragging {
    background: rgba(66, 133, 244, 0.08);
  }

  button {
    background: #f0f0f7;
    border-color: #d6d6e8;
    color: #1c1c28;
  }

  .status,
  .file-card__meta {
    color: #51516b;
  }

  .status--header {
    color: #51516b;
  }

  .table-wrapper {
    border-color: #e3e3ef;
  }

  .data-table thead {
    background: #f4f4fb;
  }

  .data-table th,
  .data-table td {
    border-bottom-color: #e3e3ef;
  }

  .data-table tbody tr:hover {
    background: rgba(66, 133, 244, 0.12);
  }

  .raw-details summary {
    color: #3367d6;
  }

  .meta-details summary {
    color: #3367d6;
  }

  .raw-details pre {
    background: rgba(0, 0, 0, 0.04);
  }

  .analysis-filter,
  .tags-row,
  .tag-input input {
    border-color: #e3e3ef;
  }

  .tag-builder-form,
  .tag-match-list,
  .group-card {
    border-color: #e3e3ef;
  }

  .tag-builder-form input {
    border-color: #e3e3ef;
    background: #ffffff;
  }

  .tag-untagged-list {
    border-color: #e3e3ef;
  }

  .tag-untagged-footer input {
    border-color: #e3e3ef;
    background: #ffffff;
  }

  .tag-match-item:hover {
    background: rgba(0, 0, 0, 0.04);
  }

  .tag-untagged-item:hover {
    background: rgba(0, 0, 0, 0.04);
  }

  .tab {
    background: #f4f4fb;
  }

  .tab.is-active {
    border-color: #3367d6;
    color: #3367d6;
  }

  .bar-track {
    background: rgba(0, 0, 0, 0.06);
  }

  .toggle[aria-pressed="true"] {
    border-color: #3367d6;
    box-shadow: 0 0 0 1px rgba(51, 103, 214, 0.3);
  }
}
