:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --panel-alt: #eef3f4;
  --ink: #192126;
  --muted: #667078;
  --line: #cfd9de;
  --accent: #147d73;
  --accent-strong: #0b5f58;
  --danger: #b43434;
  --warn: #8b6200;
  --numeric: #e7f3ff;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}

button {
  min-width: 24px;
  padding: 0 6px;
  cursor: pointer;
  font-weight: 650;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

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

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100vh;
  padding: 4px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.top-actions,
.import-controls,
.panel-heading,
.row-actions,
.filter-actions,
.corner-tools,
.cell-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

.top-actions button,
#load-paste,
#add-filter,
#download-view {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.import-panel,
.filters-panel,
.table-panel,
.status-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.import-panel {
  overflow: hidden;
}

.import-panel summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  min-height: 30px;
  padding: 0 6px;
  cursor: pointer;
  font-weight: 800;
}

.import-panel summary::marker {
  color: var(--accent);
}

#import-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-body {
  display: grid;
  gap: 4px;
  padding: 0 6px 6px;
  border-top: 1px solid var(--line);
}

.import-body.dragging {
  background: #e7f5f2;
}

.import-controls {
  padding-top: 4px;
  flex-wrap: nowrap;
}

.import-controls label,
.filter-row label {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.separator-control {
  display: block;
}

.separator-control select {
  min-width: 96px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 4px;
  color: var(--ink);
}

.import-body > textarea {
  resize: vertical;
}

.status-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
}

.status-card {
  min-height: 26px;
  padding: 4px 6px;
  box-shadow: none;
  font-size: 13px;
}

.status-card.ok {
  color: var(--accent-strong);
}

.status-card.warn {
  color: var(--warn);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 4px;
  min-height: 0;
}

.filters-panel {
  align-self: start;
  padding: 4px;
}

.panel-heading {
  justify-content: space-between;
}

.panel-heading h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.filters-list {
  display: grid;
  gap: 2px;
  margin-top: 4px;
}

.empty-note {
  color: var(--muted);
  font-size: 14px;
}

.filter-row {
  display: grid;
  grid-template-columns: 20px minmax(70px, 1fr) 60px minmax(52px, 0.8fr) 26px;
  gap: 2px;
  align-items: center;
  min-height: 26px;
}

.filter-row select,
.filter-row input,
.import-controls select {
  width: 100%;
  padding: 0 4px;
  font-size: 12px;
}

.filter-row select,
.filter-row input {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}

.filter-row label {
  display: block;
  font-size: 0;
}

.filter-toggle {
  display: grid;
  place-items: center;
}

.filter-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.table-panel {
  min-width: 0;
  overflow: hidden;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 126px);
  min-height: 160px;
  resize: both;
}

table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  vertical-align: top;
  position: relative;
  overflow: hidden;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef3f4;
  text-align: left;
}

th.numeric {
  background: var(--numeric);
}

.th-content {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 2px 26px 2px 6px;
}

.col-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.numeric-pill {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 0;
  background: #d5ebff;
  color: #115d91;
  font-size: 10px;
  font-weight: 800;
}

.row-number {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 44px;
  background: #f8fafb;
  color: var(--muted);
  text-align: left;
}

th.row-number {
  z-index: 3;
  background: #e7ecef;
}

td textarea {
  display: block;
  position: absolute;
  inset: 0;
  min-height: 0;
  height: auto;
  width: 100%;
  border: 0;
  border-radius: 0;
  resize: none;
  overflow: hidden;
  box-shadow: none;
  background: transparent;
  line-height: 18px;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  word-break: normal;
  padding: 4px 8px;
}

.cell-error {
  background: #fff5f4;
}

.small-button {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  min-height: 18px;
  padding: 0;
  font-size: 11px;
}

.sort-button.active {
  background: #dff4ef;
  border-color: var(--accent);
}

.danger {
  color: var(--danger);
}

#file-input {
  display: none;
}

.corner-tools {
  justify-content: center;
  gap: 1px;
  padding: 1px;
}

.cell-actions {
  gap: 2px;
  flex-wrap: nowrap;
  opacity: 0.28;
  transition: opacity 120ms ease;
}

tr:hover .cell-actions,
th:hover .cell-actions,
.cell-actions:focus-within {
  opacity: 1;
}

.th-content .cell-actions {
  position: absolute;
  right: 8px;
  top: 5px;
}

.row-actions {
  position: relative;
  justify-content: center;
  gap: 1px;
  height: 100%;
  padding: 1px;
}

.row-label {
  flex: 1;
  min-width: 0;
  padding-left: 2px;
  font-weight: 750;
}

.row-cell-actions {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translateY(-50%);
}

.col-resizer {
  position: absolute;
  z-index: 4;
  background: transparent;
}

.col-resizer {
  top: 0;
  right: -5px;
  width: 12px;
  height: 100%;
  cursor: col-resize;
}

.col-resizer:hover {
  background: rgba(20, 125, 115, 0.2);
}

.icon-button {
  border-radius: 0;
  font-size: 11px;
  line-height: 1;
}

.icon-button svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: currentColor;
  pointer-events: none;
}

.small-button.icon-button svg {
  width: 13px;
  height: 13px;
}

.sort-button {
  color: var(--muted);
}

.sort-button.active {
  color: var(--accent-strong);
  font-weight: 900;
}

@media (max-width: 920px) {
  .workspace,
  .status-row {
    grid-template-columns: 1fr;
  }

  .filter-row {
    grid-template-columns: 20px minmax(80px, 1fr) 56px minmax(60px, 1fr) 26px;
  }

  .table-wrap {
    max-height: 62vh;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 4px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions button {
    flex: 1;
  }
}
