:root {
  --bg: #f9fafc;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --ink: #1f203b;
  --muted: #7c8194;
  --line: #edf0f5;
  --line-strong: #d8deea;
  --nav: #ffffff;
  --nav-muted: #7c8194;
  --navy: #3d405f;
  --accent: #2585d9;
  --accent-soft: #e7f0ff;
  --danger: #d96363;
  --danger-soft: #fff0ee;
  --warn: #a15c00;
  --warn-soft: #fff5df;
  --success: #247b4b;
  --success-soft: #e9f8ef;
  --shadow: 0 12px 28px rgba(38, 43, 70, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--nav);
  border-right: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 18px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  padding: 0;
}

.brand-mark {
  align-items: center;
  background: var(--navy);
  border-radius: 12px;
  color: #ffffff;
  display: flex;
  font-weight: 800;
  height: 40px;
  justify-content: center;
  width: 40px;
}

.brand-name {
  color: var(--navy);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.brand-subtitle {
  color: var(--nav-muted);
  font-size: 12px;
  font-weight: 500;
  margin-top: 4px;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-link {
  border-radius: 10px;
  color: var(--nav-muted);
  font-size: 13px;
  font-weight: 600;
  min-height: 42px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.side-link:hover,
.side-link.active {
  background: var(--navy);
  color: #ffffff;
}

.main-panel {
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  padding: 24px;
}

.topbar {
  align-items: flex-start;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 18px;
  min-width: 0;
}

.topbar > div:first-child,
.panel-header > div:first-child {
  min-width: 0;
}

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

.connection-panel {
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(280px, 1fr) auto;
  margin-bottom: 18px;
  padding: 16px;
}

.topbar p,
.panel-header p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  margin: 6px 0 0;
  overflow-wrap: anywhere;
}

.topbar-actions,
.panel-header {
  align-items: center;
  display: flex;
  gap: 12px;
}

.topbar-actions {
  flex-shrink: 0;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

.panel-header h2,
.modal-content h2 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0;
}

.primary-link,
.secondary-btn,
.danger-btn,
.mini-btn,
.unban-btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  text-decoration: none;
  white-space: nowrap;
}

.primary-link {
  background: var(--accent);
  color: #fff;
}

.secondary-btn {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.danger-btn {
  background: var(--danger);
  color: #fff;
  width: fit-content;
}

.mini-btn {
  background: var(--accent-soft);
  color: var(--accent);
  min-height: 34px;
}

.unban-btn {
  background: var(--accent-soft);
  color: var(--accent);
}

.primary-link:hover,
.danger-btn:hover {
  filter: brightness(0.94);
}

.secondary-btn:hover,
.unban-btn:hover,
.mini-btn:hover {
  background: #eef3f8;
}

.metrics-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.metric-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: 27px;
  line-height: 1;
  margin-top: 10px;
}

.workspace-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.75fr);
  margin-bottom: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 18px;
}

.panel-wide {
  min-width: 0;
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.compact-list {
  gap: 8px;
}

.empty-list,
.empty {
  color: var(--muted);
  font-size: 14px;
  padding: 18px 0;
  text-align: center;
}

.record-item,
.banned-item,
.violation-item {
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.record-item {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.record-main {
  min-width: 0;
}

.record-actions {
  align-items: center;
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.banned-item {
  align-items: center;
  border-left-color: var(--danger);
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.violation-item {
  border-left-color: var(--warn);
}

.violation-item.reviewed,
.record-item.reviewed {
  border-left-color: var(--accent);
  opacity: 0.78;
}

.report-item.open {
  border-left-color: var(--danger);
}

.report-item.reviewed {
  border-left-color: var(--accent);
}

.banned-username,
.record-title {
  color: var(--ink);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.link-button {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  color: var(--accent);
}

.record-kicker,
.record-meta,
.violation-time,
.time {
  color: var(--muted);
  font-size: 12px;
}

.record-message,
.violation-message,
.message {
  color: var(--ink);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.record-meta,
.violation-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

.pill,
.violation-category,
.violation-state {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
}

.pill-danger {
  background: var(--danger-soft);
  border-color: #f4c6c0;
  color: var(--danger);
}

.pill-success {
  background: var(--success-soft);
  border-color: #bfe9ce;
  color: var(--success);
}

.pill-warn {
  background: var(--warn-soft);
  border-color: #f2d28e;
  color: var(--warn);
}

.violation-content {
  min-width: 0;
  width: 100%;
}

.violation-matches {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 10px;
  overflow: hidden;
}

.violation-matches.empty-match {
  color: var(--muted);
  font-size: 13px;
  padding: 10px;
}

.match-heading {
  background: #eef3f8;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 8px 10px;
  text-transform: uppercase;
}

.violation-matches ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.violation-matches li {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(96px, 140px) minmax(0, 1fr) 54px;
  padding: 10px;
}

.violation-matches li + li {
  border-top: 1px solid var(--line);
}

.match-label,
.match-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.match-label {
  color: var(--ink);
  font-weight: 800;
}

.match-label small,
.match-key,
.match-targets {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.match-snippet {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.match-score {
  color: var(--accent);
  font-weight: 800;
  text-align: right;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-stack label,
.section-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-stack span,
.section-block label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.form-stack input,
.section-block input,
.section-block textarea,
.section-block select,
.flag-word,
.flag-cat,
.cat-add-row select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.section-block textarea {
  min-height: 92px;
  resize: vertical;
}

.form-stack input:focus,
.section-block input:focus,
.section-block textarea:focus,
.section-block select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.status-message {
  border-radius: 8px;
  display: none;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px 14px;
}

.status-message.success {
  background: var(--success-soft);
  color: var(--success);
}

.status-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.modal {
  align-items: center;
  background: rgba(23, 32, 44, 0.58);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(23, 32, 44, 0.28);
  max-height: 88vh;
  max-width: 720px;
  overflow-y: auto;
  padding: 22px;
  position: relative;
  width: min(100%, 720px);
}

.modal-large {
  max-width: 880px;
  width: min(100%, 880px);
}

.modal-body {
  margin-top: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.close-btn {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
  position: absolute;
  right: 18px;
  top: 18px;
}

.msg {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.msg:last-child {
  border-bottom: 0;
}

.msg.reviewed {
  opacity: 0.72;
}

.cat-container,
.cat-add-row,
.flagged-item {
  display: flex;
  gap: 8px;
}

.cat-container {
  flex-wrap: wrap;
}

.cat-tag,
.chip {
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid #c6d8f8;
  border-radius: 999px;
  color: var(--accent);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  gap: 6px;
  padding: 6px 9px;
}

.cat-tag.locked {
  opacity: 0.68;
}

.cat-tag button,
.remove-flag {
  border: 0;
  cursor: pointer;
}

.cat-tag button {
  background: transparent;
  color: var(--accent);
  font-weight: 900;
  line-height: 1;
  padding: 0;
}

.flagged-item {
  align-items: center;
  margin-top: 6px;
}

.remove-flag {
  background: var(--danger-soft);
  border-radius: 6px;
  color: var(--danger);
  flex-shrink: 0;
  min-height: 34px;
  padding: 6px 9px;
}

.section-block {
  margin-top: 12px;
}

.section-block.immutable input,
.section-block.immutable textarea {
  background: var(--surface-muted);
  color: var(--muted);
}

.loading-spinner {
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  border-top-color: #fff;
  display: inline-block;
  height: 16px;
  margin-left: 7px;
  vertical-align: middle;
  width: 16px;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 1100px) {
  .app-shell {
    display: block;
    width: 100%;
    overflow-x: hidden;
  }

  .sidebar {
    height: auto;
    position: static;
    max-width: 100%;
  }

  .side-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .side-link {
    flex: 0 0 auto;
  }

  .workspace-grid,
  .metrics-grid,
  .connection-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .app-shell,
  .sidebar,
  .main-panel {
    width: 100%;
  }

  .panel,
  .metric,
  .status-message,
  .topbar-actions,
  .connection-panel {
    max-width: min(100%, 354px);
  }

  .workspace-grid,
  .metrics-grid,
  .connection-panel {
    max-width: min(100%, 354px);
  }

  .main-panel,
  .sidebar {
    padding: 18px;
  }

  .side-nav {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .side-link {
    flex: 1 1 calc(50% - 4px);
    text-align: center;
  }

  .topbar,
  .panel-header,
  .record-item,
  .banned-item {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar p,
  .panel-header p {
    max-width: 32ch;
  }

  .topbar-actions,
  .record-actions {
    flex-wrap: wrap;
  }

  .topbar-actions,
  .topbar-actions .secondary-btn,
  .topbar-actions .primary-link {
    width: 100%;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace-grid,
  .metrics-grid,
  .connection-panel {
    grid-template-columns: 1fr;
  }

  .violation-matches li {
    grid-template-columns: 1fr;
  }

  .match-score {
    text-align: left;
  }
}
