:root {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #141b33;
  --panel-2: #1a2342;
  --text: #e8ecff;
  --muted: #a8b1d9;
  --accent: #58a6ff;
  --danger: #ff7b72;
  --border: #2a3561;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: linear-gradient(180deg, #0b1020, #121a33);
  color: var(--text);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 1rem;
  align-items: start;
}

.app-column .card {
  margin-bottom: 1rem;
}

.app-topbar {
  margin-bottom: 1.1rem;
}

.app-title {
  margin-bottom: 0.2rem;
}

.warning {
  border-color: #8e6b16;
  background: #2c230f;
}

h1,
h2,
h3 {
  margin-top: 0;
}

.muted {
  color: var(--muted);
  margin: 0.5rem 0;
}

.helper {
  color: #95a1d2;
  font-size: 0.82rem;
  margin: 0.5rem 0 0;
}

.message {
  margin-top: 0.75rem;
  min-height: 1.15rem;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  transition: background-color 150ms ease, color 150ms ease;
}

.message-success {
  background: rgba(88, 166, 255, 0.13);
  border: 1px solid rgba(88, 166, 255, 0.28);
}

.message-error {
  background: rgba(248, 81, 73, 0.18);
  border: 1px solid rgba(248, 81, 73, 0.4);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
}

.spread {
  justify-content: space-between;
}

.actions-row {
  margin-top: 1rem;
  gap: 0.65rem;
}

.targets-heading-row {
  margin-top: 0;
  justify-content: space-between;
  align-items: center;
}

.targets-heading-row h3 {
  margin: 0;
}

.targets-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.target-pair-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
  align-items: center;
}

.target-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.target-field > input {
  width: 100%;
}

.tooltip-wrap {
  position: relative;
}

.info-icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 0.82rem;
  font-weight: 700;
  background: #2b3868;
  color: #dbe5ff;
  border: 1px solid var(--border);
}

.info-icon-btn:hover {
  filter: brightness(1.1);
}

.tooltip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(280px, 75vw);
  background: #0f1630;
  border: 1px solid #3b4a80;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  color: #d9e2ff;
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  z-index: 10;
}

.tooltip::before {
  content: "";
  position: absolute;
  top: -6px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: #0f1630;
  border-left: 1px solid #3b4a80;
  border-top: 1px solid #3b4a80;
  transform: rotate(45deg);
}

.grid,
.auth-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.form-block {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 0.75rem;
  margin-top: 0.75rem;
}

.form-block h3 {
  margin: 0 0 0.55rem;
  font-size: 0.98rem;
}

input,
select,
button {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
}

input,
select {
  background: var(--panel-2);
  color: var(--text);
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(88, 166, 255, 0.7);
  outline-offset: 1px;
}

button {
  background: var(--accent);
  color: #081225;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  filter: brightness(1.07);
}

button.secondary {
  background: #2b3868;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: var(--danger);
  color: #1f0806;
}

#positions-body tr.pending-delete > td {
  background: rgba(248, 81, 73, 0.18) !important;
}

button.delete-confirm {
  background: #ff4d4f;
  color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.35);
}

.confirm-x {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  font-weight: 800;
}

.delete-icon {
  width: 16px;
  height: 16px;
  display: block;
  filter: brightness(0) invert(1);
}

.edit-icon {
  width: 16px;
  height: 16px;
  display: block;
  filter: brightness(0) invert(1);
}

.summary-grid {
  display: grid;
  gap: 0.5rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
}

.summary-item.summary-item--entry {
  background: rgba(46, 160, 67, 0.38) !important;
  border-color: rgba(46, 160, 67, 0.95) !important;
}

.summary-item.summary-item--stop {
  background: rgba(248, 81, 73, 0.38) !important;
  border-color: rgba(248, 81, 73, 0.95) !important;
}

.summary-item .label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-item .value {
  font-weight: 700;
  margin-top: 0.2rem;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
}

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

.projection-table {
  min-width: 100%;
  table-layout: fixed;
}

.projection-table th,
.projection-table td {
  padding: 0.5rem 0.4rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.projection-table th:nth-child(1),
.projection-table td:nth-child(1) {
  width: 11%;
}

.projection-table th:nth-child(2),
.projection-table td:nth-child(2) {
  width: 17%;
}

.projection-table th:nth-child(3),
.projection-table td:nth-child(3) {
  width: 19%;
}

.projection-table th:nth-child(4),
.projection-table td:nth-child(4),
.projection-table th:nth-child(5),
.projection-table td:nth-child(5) {
  width: 14%;
  text-align: center;
}

.projection-table th:nth-child(6),
.projection-table td:nth-child(6) {
  width: 25%;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 0.55rem;
  font-size: 0.88rem;
}

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

.positions-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1d284c;
}

#positions-body tr {
  transition: background-color 120ms ease;
}

#positions-body tr:nth-child(odd) > td {
  background: rgba(255, 255, 255, 0.01);
}

#positions-body tr:nth-child(even) > td {
  background: rgba(255, 255, 255, 0.04);
}

#positions-body tr:hover > td {
  background: rgba(88, 166, 255, 0.12);
}

#positions-body tr.selected > td {
  background: rgba(88, 166, 255, 0.2);
}

.hidden {
  display: none;
}

@media (max-width: 1080px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .target-pair-row {
    grid-template-columns: 1fr;
  }

  .actions-row button {
    width: 100%;
  }
}