:root {
  --bg: #0b0f14;
  --bg-elev: #121820;
  --bg-panel: #0e141c;
  --border: #1e2a38;
  --border-strong: #2a3a4d;
  --text: #f2f5f9;
  --text-dim: #b4c0d0;
  --text-mute: #8494a8;
  --accent: #3d9cf0;
  --accent-soft: rgba(61, 156, 240, 0.12);
  --success: #3ecf8e;
  --warn: #e6b84d;
  --danger: #f07178;
  --term-cyan: #79c0ff;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

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

code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--term-cyan);
}

a {
  color: var(--accent);
  text-decoration: none;
}

.muted {
  color: var(--text-dim);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #121a24 0%, var(--bg-panel) 100%);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
}

.tagline {
  margin: 0.1rem 0 0;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.top-actions,
.hero-actions,
.export-bar,
.filters,
.bulk,
.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #061018;
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 0.3rem 0.65rem;
  font-size: 0.82rem;
}

.file-btn {
  cursor: pointer;
}

.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.hero h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
}

.drop-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.1rem;
  text-align: center;
  background: rgba(61, 156, 240, 0.04);
  margin-bottom: 1.15rem;
  display: grid;
  gap: 0.25rem;
}

.drop-zone.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
  margin-bottom: 0.55rem;
}

.section-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.samples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.sample-card {
  text-align: left;
  display: grid;
  gap: 0.3rem;
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
  color: inherit;
}

.sample-card:hover,
.sample-card.active {
  border-color: var(--accent);
}

.sample-card.active {
  background: var(--accent-soft);
}

.sample-kind {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--warn);
  font-weight: 600;
}

.sample-meta {
  font-size: 0.78rem;
  color: var(--term-cyan);
  font-family: var(--mono);
}

.empty-state {
  padding: 0.5rem 0 1rem;
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.inline {
  display: grid;
  gap: 0.2rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.inline.grow {
  flex: 1;
  min-width: 200px;
}

.inline input,
.inline select,
.filters select,
.filters input,
.add-form input,
.add-form select,
.udt-name-row input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
}

.aoi-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.aoi-tab {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.aoi-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.instances-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.85rem;
  background: var(--bg-elev);
}

.instances-panel h3 {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
}

.instance-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.instance-chip {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--term-cyan);
}

.metrics {
  margin-bottom: 0.9rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.55rem;
}

.metric-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--success);
  font-family: var(--mono);
  line-height: 1.1;
}

.metric-label {
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.metric-hint {
  font-size: 0.72rem;
  color: var(--text-mute);
}

.metric-note {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.radio {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.udt-name-row {
  margin-bottom: 0.65rem;
}

.table-wrap {
  overflow: auto;
  max-height: min(52vh, 560px);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th,
.data-table td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #15202c;
  z-index: 1;
  text-align: left;
  color: var(--text-dim);
}

.mono {
  font-family: var(--mono);
  color: var(--term-cyan);
}

.row-off {
  opacity: 0.55;
}

.table-count {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
}

.add-row {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.add-row h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.rules {
  margin-top: 0.55rem;
}

.footer {
  padding: 0.85rem 1.25rem 1.25rem;
  text-align: center;
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #15202c;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.7rem 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  z-index: 50;
  max-width: min(420px, calc(100vw - 2rem));
}

.toast.ok {
  border-color: var(--success);
}

.toast.err {
  border-color: var(--danger);
}

@media (max-width: 720px) {
  .hero h2 {
    font-size: 1.05rem;
  }
  .export-bar {
    width: 100%;
  }
  .inline {
    flex: 1 1 140px;
  }
}
