:root {
  --bg: #070b18;
  --bg-soft: #0b1222;
  --topbar: #090e1d;
  --sidebar: #0a1021;
  --sidebar-2: #121837;
  --panel: rgba(17, 25, 46, 0.88);
  --panel-strong: rgba(22, 32, 59, 0.96);
  --field: #080d1c;
  --text: #eef4ff;
  --muted: #8ea0bc;
  --border: rgba(139, 159, 190, 0.18);
  --border-strong: rgba(155, 177, 215, 0.28);
  --primary: #8158ff;
  --primary-strong: #6b43ef;
  --primary-soft: rgba(129, 88, 255, 0.22);
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.14);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.13);
  --yellow: #fbbf24;
  --yellow-soft: rgba(251, 191, 36, 0.14);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.13);
  --hit: #fb7185;
  --hit-soft: rgba(251, 113, 133, 0.16);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 8%, rgba(129, 88, 255, 0.16), transparent 30%),
    radial-gradient(circle at 86% 12%, rgba(34, 211, 238, 0.1), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button,
a.button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
  min-height: 38px;
  font-weight: 600;
}

button:hover,
a.button:hover {
  background: var(--primary-strong);
}

button.secondary,
a.button.secondary {
  background: rgba(17, 25, 46, 0.78);
  color: var(--text);
  border-color: var(--border-strong);
}

button.secondary:hover,
a.button.secondary:hover {
  background: rgba(34, 44, 75, 0.95);
}

button.ghost {
  background: transparent;
  color: var(--cyan);
  border-color: transparent;
}

button.danger {
  background: rgba(251, 113, 133, 0.16);
  border-color: rgba(251, 113, 133, 0.32);
  color: #fecdd3;
}

button.small,
a.button.small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 13px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 10px 12px;
  outline-color: var(--primary);
}

input::placeholder,
textarea::placeholder {
  color: #61708b;
}

textarea {
  min-height: 116px;
  resize: vertical;
}

label,
.field-label {
  display: block;
  margin: 0 0 6px;
  color: #a7b8d2;
  font-size: 13px;
  font-weight: 600;
}

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

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.login-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel-strong);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.brand h1 {
  margin: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
  line-height: 1.15;
  white-space: nowrap;
}

.login-card p,
.brand p,
.muted {
  color: var(--muted);
}

.auth-switch {
  justify-self: start;
}

.stack {
  display: grid;
  gap: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(330px, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 0 20px;
  background: var(--topbar);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand > div {
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: #c4b5fd;
  background: rgba(129, 88, 255, 0.16);
}

.brand p {
  margin: 4px 0 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.flow-item {
  color: #b9c6da;
  font-size: 13px;
}

.flow-item::first-letter {
  color: #ffffff;
}

.flow-sep {
  color: #4b5871;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}

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

.sidebar {
  min-height: calc(100dvh - 58px);
  background: rgba(9, 14, 29, 0.92);
  border-right: 1px solid var(--border);
  padding: 18px 8px;
  position: sticky;
  top: 58px;
  align-self: start;
}

.sidebar-heading {
  padding: 0 12px 18px;
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
}

.sidebar-group {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
}

.sidebar-group-title {
  padding: 0 12px 4px;
  color: #a9b8d3;
  font-size: 12px;
  font-weight: 700;
}

.sidebar-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  color: #c7d3e8;
  padding: 9px 10px;
  font-weight: 600;
  text-align: left;
}

.sidebar-link:hover {
  background: rgba(129, 88, 255, 0.1);
}

.sidebar-link.is-active {
  background: var(--primary-soft);
  border-color: rgba(129, 88, 255, 0.28);
  color: #ffffff;
}

.sidebar-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.18);
  flex: 0 0 auto;
}

.sidebar-foot {
  margin: 26px 8px 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 25, 46, 0.62);
  color: var(--muted);
  display: grid;
  gap: 5px;
  font-size: 12px;
}

.sidebar-foot strong {
  color: #c7d3e8;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.content-shell {
  min-width: 0;
  padding: 22px 36px 44px;
}

.content-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.content-toolbar h2 {
  margin: 0;
  color: #ffffff;
  font-size: 22px;
}

.content-toolbar p {
  margin: 7px 0 0;
  color: #9db0ca;
}

.content-body {
  display: grid;
  gap: 14px;
}

.tabs {
  display: none;
}

.tab-button {
  min-height: 44px;
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}

.tab-button.is-active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented-control .is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.message,
.error {
  border-radius: 8px;
  padding: 11px 13px;
  margin: 0 0 12px;
}

.message {
  background: var(--green-soft);
  color: #86efac;
  border: 1px solid rgba(52, 211, 153, 0.24);
}

.error {
  background: var(--danger-soft);
  color: #fecdd3;
  border: 1px solid rgba(251, 113, 133, 0.24);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin: 6px 0 2px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
  color: #ffffff;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.tool-panel,
.record-item,
.stat-card,
.user-row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.tool-panel {
  padding: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-actions,
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.rank-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.record-filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 260px);
  gap: 12px;
  align-items: end;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  margin: 0;
}

.checkline input {
  width: 18px;
  height: 18px;
}

.option-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-check {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 10px;
}

.collect-flags {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.drama-status-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.drama-status-inline .field-label {
  margin: 0;
  white-space: nowrap;
}

.collect-flags .option-check {
  min-height: 40px;
  padding: 8px 12px;
}

.suggestion {
  border-left: 4px solid var(--green);
  padding: 12px 0 12px 13px;
  background: var(--green-soft);
}

.suggestion strong {
  display: block;
  margin-bottom: 4px;
}

.suggestion ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: #b9c6da;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 14px;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: #ffffff;
}

.stat-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.records-list,
.users-list {
  display: grid;
  gap: 10px;
}

.record-item,
.user-row {
  padding: 14px;
}

.record-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title h3 {
  margin: 0;
  font-size: 17px;
  color: #ffffff;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.meta-box {
  min-width: 0;
}

.meta-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.meta-box strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 14px;
  color: #dbe7fb;
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge-row.compact {
  margin-top: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: #b8c5da;
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.badge.hit {
  color: #fecdd3;
  background: var(--hit-soft);
  border-color: rgba(251, 113, 133, 0.26);
}

.badge.green {
  color: #86efac;
  background: var(--green-soft);
  border-color: rgba(52, 211, 153, 0.28);
}

.badge.blue {
  color: #67e8f9;
  background: var(--cyan-soft);
  border-color: rgba(34, 211, 238, 0.3);
}

.badge.warn {
  color: #fde68a;
  background: var(--yellow-soft);
  border-color: rgba(251, 191, 36, 0.28);
}

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

.platform-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #d8e4f8;
  padding: 5px 8px;
  font-size: 13px;
}

.platform-chip button {
  min-height: 26px;
  padding: 3px 6px;
  font-size: 12px;
}

.option-sort-list {
  display: grid;
  gap: 8px;
}

.option-sort-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #d8e4f8;
  padding: 6px 8px;
}

.option-sort-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.option-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drag-handle {
  display: inline-grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.option-sort-item.is-dragging {
  opacity: 0.72;
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.1);
}

.option-sort-item.is-dragging .drag-handle {
  cursor: grabbing;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.page-status {
  color: var(--muted);
  font-size: 13px;
}

.page-jump {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.page-jump input {
  width: 74px;
  min-height: 34px;
  padding: 7px 9px;
}

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: rgba(17, 25, 46, 0.5);
}

.chart-panel {
  margin-top: 4px;
}

.bars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18px, 1fr));
  gap: 5px;
  align-items: end;
  min-height: 150px;
  padding-top: 10px;
}

.bar {
  display: grid;
  gap: 4px;
  align-content: end;
  min-width: 0;
}

.bar-fill {
  min-height: 4px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--cyan), var(--primary));
}

.bar-label {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.rank-metrics {
  display: grid;
  gap: 6px;
}

.rank-metric {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
}

.rank-metric span {
  color: var(--muted);
  font-size: 12px;
}

.rank-metric strong {
  color: #eef4ff;
}

.progress {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: var(--progress);
  background: linear-gradient(90deg, var(--green), var(--cyan));
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: #aebbd1;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.03);
}

td {
  font-size: 14px;
  color: #d8e4f8;
}

a {
  color: #67e8f9;
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: minmax(280px, 1fr) auto;
  }

  .top-flow {
    display: none;
  }

  .content-shell {
    padding: 20px 24px 38px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    position: static;
  }

  .user-pill {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .sidebar {
    top: 0;
    min-height: calc(100dvh - 0px);
    padding: 12px 7px;
  }

  .sidebar-heading,
  .sidebar-group-title,
  .sidebar-foot {
    display: none;
  }

  .sidebar-link {
    justify-content: center;
    min-height: 56px;
    padding: 8px 4px;
  }

  .sidebar-link span:last-child {
    display: none;
  }

  .sidebar-icon {
    width: 34px;
    height: 34px;
  }

  .content-shell {
    padding: 14px 12px 28px;
  }

  .content-toolbar {
    display: grid;
  }

  .summary-grid,
  .meta-grid,
  .grid-3,
  .record-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 8px;
    padding: 10px;
  }

  .brand p {
    display: none;
  }

  .brand h1 {
    font-size: 15px;
  }

  .user-pill {
    gap: 6px;
    font-size: 12px;
  }

  .user-pill button {
    width: auto;
  }

  .workspace {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .content-shell {
    padding: 12px 10px 24px;
  }

  .grid-2,
  .grid-3,
  .summary-grid,
  .meta-grid,
  .record-filters {
    grid-template-columns: 1fr;
  }

  .section-head,
  .record-title {
    display: grid;
  }

  button,
  a.button {
    width: 100%;
  }

  .sidebar-link,
  .form-actions button,
  .row-actions button,
  .row-actions a.button,
  .pagination button {
    width: auto;
  }

  .pagination {
    justify-content: flex-start;
  }

  .page-status {
    flex: 1 1 100%;
  }
}
