:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181c20;
  --panel-2: #20262b;
  --line: #303941;
  --text: #eef2f1;
  --muted: #9ba8a5;
  --accent: #6ee7b7;
  --accent-2: #f59e0b;
  --danger: #fb7185;
  --blue: #7dd3fc;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  overflow-x: hidden;
}

.sidebar {
  min-height: 100vh;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #121619;
  position: sticky;
  top: 0;
  min-width: 0;
  overflow: hidden;
}

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

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

.mark {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(110, 231, 183, 0.45);
  background: #17211f;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 800;
  border-radius: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  font-size: 16px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.brand p,
.eyebrow,
.controls span,
.status-panel p,
.status-message {
  color: var(--muted);
}

.brand p,
.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.user-line {
  margin-top: 3px;
  color: var(--blue) !important;
  overflow-wrap: anywhere;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  padding: 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid #3a454d;
  background: #0f1316;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 9px;
  font: inherit;
  font-size: 13px;
}

input:focus {
  outline: 2px solid rgba(110, 231, 183, 0.24);
  border-color: var(--accent);
}

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

.check {
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 10px;
}

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

button,
.ghost {
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #06110d;
  font-weight: 700;
  padding: 8px 10px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  font: inherit;
}

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-width: 0;
}

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

.ghost {
  background: transparent;
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.5);
}

.hidden {
  display: none !important;
}

.status-panel {
  margin-top: 10px;
  padding: 12px;
  overflow: hidden;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 6px;
}

.status-message {
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
  font-size: 13px;
}

.status-lines {
  display: grid;
  gap: 7px;
}

.status-line {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.status-line span {
  color: var(--muted);
}

.status-line strong {
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.status-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.status-action {
  display: block;
  border: 1px solid rgba(110, 231, 183, 0.45);
  border-radius: 6px;
  color: var(--accent);
  text-align: center;
  text-decoration: none;
  padding: 8px 9px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(110, 231, 183, 0.06);
}

.status-action.primary {
  background: var(--accent);
  color: #06110d;
}

.login-body {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-shell {
  width: min(100%, 380px);
}

.login-card {
  padding: 18px;
}

.login-brand {
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form span {
  color: var(--muted);
}

.login-message {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.running {
  background: var(--accent-2);
  box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.12);
}

.dot.done {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(110, 231, 183, 0.12);
}

.dot.failed {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(251, 113, 133, 0.12);
}

.main {
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.hero {
  min-height: 54px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.hero h2 {
  font-size: 22px;
  line-height: 1.15;
}

.hero p:last-child {
  margin-top: 4px;
  color: var(--muted);
  max-width: 760px;
  font-size: 13px;
}

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

.metrics article {
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.metrics strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
}

.top-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.45fr) minmax(0, 1fr);
  gap: 10px;
}

.graph-panel,
.summary-panel,
.tabs {
  padding: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-head h3,
.tabs h3 {
  margin-top: 0;
  font-size: 14px;
}

#graph {
  min-height: 230px;
  position: relative;
  border: 1px solid #283139;
  background: #11171a;
  border-radius: 8px;
  overflow: hidden;
}

.graph-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 96px;
  max-width: 150px;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #1e252a;
  text-align: center;
  font-size: 11px;
  line-height: 1.25;
}

.node.self {
  background: #17362d;
  border-color: rgba(110, 231, 183, 0.55);
  color: var(--accent);
  font-weight: 800;
}

.node.friend {
  border-color: rgba(125, 211, 252, 0.55);
  color: var(--blue);
}

.node.enemy {
  border-color: rgba(251, 113, 133, 0.58);
  color: #fecdd3;
}

.edge {
  position: absolute;
  height: 1px;
  background: #44515b;
  transform-origin: 0 0;
}

.summary {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px 10px;
  align-items: start;
}

.summary dt {
  color: var(--muted);
  font-size: 12px;
}

.summary dd {
  margin: 0;
  font-weight: 700;
  font-size: 13px;
}

.tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin: -4px -4px 10px;
  padding: 4px 4px 8px;
}

.tab {
  background: #20262b;
  color: var(--muted);
  border-color: var(--line);
}

.tab.active {
  background: var(--accent);
  color: #06110d;
}

.tabpage {
  display: none;
}

.tabpage.active {
  display: block;
}

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

.wide {
  grid-column: span 2;
}

.full {
  grid-column: 1 / -1;
}

.doctrine-summary {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.doctrine-summary article {
  padding: 10px 12px;
  background: #20262b;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.doctrine-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}

.relation-card {
  border-left: 2px solid transparent;
  padding-left: 8px;
}

.friendly-card {
  border-left-color: rgba(125, 211, 252, 0.65);
}

.friendly-card h3,
.friendly-card tbody td:first-child {
  color: #a5ddff;
}

.enemy-card {
  border-left-color: rgba(251, 113, 133, 0.68);
}

.enemy-card h3,
.enemy-card tbody td:first-child {
  color: #fda4af;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 6px;
  font-size: 12px;
}

small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

th,
td {
  padding: 6px 6px;
  border-bottom: 1px solid #283139;
  text-align: left;
  vertical-align: top;
}

th:last-child,
td:last-child {
  text-align: right;
  width: 58px;
}

table:has(th:nth-child(4)) th:last-child,
table:has(th:nth-child(4)) td:last-child {
  width: 64px;
}

#doctrineFleets th:last-child,
#doctrineFleets td:last-child {
  width: 92px;
}

td:first-child,
th:first-child {
  overflow-wrap: anywhere;
}

th {
  padding: 6px;
  color: var(--muted);
  font-weight: 600;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.36fr) minmax(0, 1fr);
  gap: 12px;
}

.admin-card {
  min-width: 0;
  padding: 10px;
  background: #151a1e;
  border: 1px solid #283139;
  border-radius: 8px;
}

.admin-form {
  display: grid;
  gap: 10px;
}

.rule-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.rules-editor {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid #3a454d;
  background: #0f1316;
  color: var(--text);
  border-radius: 6px;
  padding: 10px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  overflow-wrap: normal;
  white-space: pre;
  overflow: auto;
}

.rules-hint {
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.rules-editor:focus {
  outline: 2px solid rgba(110, 231, 183, 0.24);
  border-color: var(--accent);
}

.admin-message {
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.admin-message.ok {
  color: var(--accent);
}

.admin-message.error {
  color: var(--danger);
}

.inline-input {
  padding: 5px 6px;
  font-size: 12px;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.mini-button {
  width: auto;
  padding: 5px 7px;
  font-size: 12px;
  border-color: rgba(110, 231, 183, 0.35);
  background: rgba(110, 231, 183, 0.08);
  color: var(--accent);
}

.danger-button {
  border-color: rgba(251, 113, 133, 0.45);
  background: rgba(251, 113, 133, 0.08);
  color: #fda4af;
}

.role-badge,
.status-badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 6px;
  color: var(--muted);
  background: #101519;
  font-size: 11px;
  white-space: nowrap;
}

.admin-role {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.45);
}

.owner-role {
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.5);
}

.status-badge.done {
  color: var(--accent);
  border-color: rgba(110, 231, 183, 0.45);
}

.status-badge.failed {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.45);
}

.status-badge.running,
.status-badge.queued {
  color: var(--accent-2);
  border-color: rgba(245, 158, 11, 0.45);
}

.muted-row {
  opacity: 0.58;
}

#usersTable th:nth-child(5),
#usersTable td:nth-child(5) {
  width: 150px;
}

#usersTable th:last-child,
#usersTable td:last-child {
  width: 116px;
}

#recordsTable th:nth-child(1),
#recordsTable td:nth-child(1) {
  width: 86px;
}

#recordsTable th:nth-child(2),
#recordsTable td:nth-child(2) {
  width: 128px;
}

#recordsTable th:nth-child(4),
#recordsTable td:nth-child(4) {
  width: 110px;
}

#recordsTable th:last-child,
#recordsTable td:last-child {
  width: 74px;
}

@media (max-width: 1050px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .top-grid,
  .table-grid,
  .metrics,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .sidebar {
    padding: 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .grid-2,
  .action-row {
    grid-template-columns: 1fr;
  }

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