* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0a1220;
  --card-bg: #0d1729;
  --text: #f0f2f5;
  --text-muted: #555c65;
  --border: #78DCE8;
  --brand: #F25E86;
  --brand-light: #3d1421;
  --brand-glow: rgba(242, 94, 134, 0.15);
  --input-bg: #050911;
  --shadow: none;
  --radius: 0px;
  --hover-bg: #162438;
  --negative: #F28B66;
  --negative-bg: rgba(242, 139, 102, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1220;
    --card-bg: #0d1729;
    --text: #f0f2f5;
    --text-muted: #555c65;
    --border: #78DCE8;
    --brand: #F25E86;
    --brand-light: #3d1421;
    --brand-glow: rgba(242, 94, 134, 0.15);
    --input-bg: #050911;
    --shadow: none;
    --hover-bg: #162438;
    --negative: #F28B66;
    --negative-bg: rgba(242, 139, 102, 0.1);
    color-scheme: dark;
  }
}

body {
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Monaco, 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  text-shadow: 0 0 2px rgba(240, 242, 245, 0.1);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
}

header {
  margin-bottom: 24px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.prompt {
  color: var(--brand);
  animation: blink 1s step-end infinite;
}

@keyframes blink {

  from,
  to {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Filter panel */
.field-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field-filters label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.field-filters input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--input-bg);
  color: var(--text);
  min-width: 140px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field-filters input:focus {
  border-color: var(--brand);
  background: #111;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  margin-top: 4px;
}

.filter-search-btn {
  padding: 9px 28px;
  background: var(--brand);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  text-transform: uppercase;
}

.filter-search-btn:hover {
  background: #78DCE8;
  color: #000;
}

.filter-search-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.filter-clear-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.filter-clear-btn:hover {
  border-color: var(--brand);
  color: var(--text);
}

/* Status bar */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 4px 12px;
  margin-bottom: 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
  min-height: 32px;
}

.status-bar .count {
  font-weight: 600;
  color: var(--text);
}

.status-bar .sum {
  font-weight: 600;
}

.filter-summary {
  width: 100%;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.filter-summary .filter-tag {
  display: inline-block;
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 7px;
  margin: 1px 2px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.filter-summary .filter-tag .filter-label {
  color: var(--text-muted);
}

.filter-summary .filter-tag .filter-value {
  color: var(--text);
  font-weight: 500;
}

/* Interactive result cells */
.cell-filter {
  cursor: pointer;
  border-bottom: 1px dashed var(--brand);
  transition: color .1s;
}

.cell-filter:hover {
  color: var(--brand);
}

.cell-add-filter {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  margin-left: 4px;
  vertical-align: middle;
  transition: all .1s;
  opacity: 0;
}

tr:hover .cell-add-filter {
  opacity: 1;
}

.cell-add-filter:hover {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

/* Spinner & progress */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 12px;
  overflow: hidden;
  display: none;
}

.progress-bar.active {
  display: block;
}

.progress-bar .fill {
  height: 100%;
  background: var(--brand);
  border-radius: 2px;
  transition: width .3s;
  width: 0%;
}

/* Results table */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 10px 12px;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

thead th:hover {
  color: var(--brand);
}

thead th.sorted {
  color: var(--brand);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

tbody tr:hover {
  background: var(--hover-bg);
}

td {
  padding: 8px 12px;
  vertical-align: top;
}

td.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.amount.negative {
  color: var(--negative);
}

.load-more {
  display: block;
  margin: 20px auto;
  padding: 10px 28px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s;
}

.load-more:hover {
  border-color: var(--brand);
}

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  gap: 6px;
}

.tool-btn {
  padding: 5px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s;
}

.tool-btn:hover {
  border-color: var(--brand);
  color: var(--text);
}

/* Row detail */
.row-detail {
  display: none;
  background: var(--hover-bg);
  font-size: 0.8rem;
}

.row-detail td {
  padding: 8px 12px 12px;
}

.row-detail .detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px 16px;
}

.row-detail .detail-grid .label {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.row-detail .detail-grid .value {
  font-weight: 500;
}

/* Period picker */
.period-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.period-row .period-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 2px;
}

.period-btn {
  padding: 4px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}

.period-btn:hover {
  border-color: var(--brand);
  color: var(--text);
}

.period-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
}

.period-nav button {
  padding: 3px 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  line-height: 1;
}

.period-nav button:hover {
  border-color: var(--brand);
  color: var(--text);
}

.period-nav .period-current {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  min-width: 90px;
  text-align: center;
}

/* Catalog panels (konto, leverantör) */
.catalog-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.catalog-toggle:hover {
  border-color: var(--brand);
  color: var(--text);
}

.catalog-panel {
  display: none;
  width: 100%;
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.catalog-panel.open {
  display: block;
}

.catalog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.catalog-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
}

.catalog-header .catalog-status {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.catalog-search {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.catalog-search input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.catalog-search input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-glow);
}

.catalog-grid {
  max-height: 350px;
  overflow-y: auto;
}

.catalog-row {
  display: grid;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
  font-size: 0.84rem;
}

.catalog-row:last-child {
  border-bottom: none;
}

.catalog-row:hover {
  background: var(--hover-bg);
}

.catalog-row.active {
  background: var(--brand-glow);
  border-left: 3px solid var(--brand);
  padding-left: 13px;
}

.catalog-row .cat-id {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--brand);
}

.catalog-row .cat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-row .cat-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--hover-bg);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.catalog-row.konto-row {
  grid-template-columns: 60px 1fr auto;
}

.catalog-row.lev-row {
  grid-template-columns: 1fr auto;
}

/* Autocomplete */
.ac-wrap {
  position: relative;
}

.ac-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
  list-style: none;
}

.ac-list.open {
  display: block;
}

.ac-list li {
  padding: 7px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}

.ac-list li:last-child {
  border-bottom: none;
}

.ac-list li:hover,
.ac-list li.active {
  background: var(--brand-light);
  color: var(--brand);
}

.ac-list .ac-hint {
  padding: 7px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.ac-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin-right: 5px;
  vertical-align: middle;
}

/* Dark mode: native controls, scrollbars, date pickers */
@media (prefers-color-scheme: dark) {
  input[type="date"] {
    color-scheme: dark;
  }

  input[type="text"],
  input[type="date"] {
    background: var(--input-bg);
    color: var(--text);
    border-color: var(--border);
  }

  input[type="text"]:focus,
  input[type="date"]:focus {
    border-color: var(--brand);
    outline: none;
    background: #111;
  }

  * {
    scrollbar-color: var(--border) var(--card-bg);
  }

  *::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  *::-webkit-scrollbar-track {
    background: var(--card-bg);
  }

  *::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
  }

  *::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
  }

  button {
    color-scheme: dark;
  }
}

@media (max-width: 700px) {
  table {
    font-size: 0.78rem;
  }

  td,
  thead th {
    padding: 6px 8px;
  }

  .hide-mobile {
    display: none;
  }
}

/* CRT Scanline Effect */
.scanline {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(10, 18, 32, 0) 50%,
      rgba(0, 0, 0, 0.2) 50%),
    linear-gradient(90deg,
      rgba(242, 94, 134, 0.02),
      rgba(120, 220, 232, 0.01),
      rgba(178, 217, 119, 0.02));
  background-size: 100% 3px, 3px 100%;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.1;
}

tbody tr:hover {
  background: var(--hover-bg);
  box-shadow: inset 0 0 10px rgba(120, 220, 232, 0.1);
  color: #B2D977;
}