@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg: #0b0f14;
  --bg-elev: #11161d;
  --bg-elev-2: #171d26;
  --text: #e7edf6;
  --muted: #98a5b8;
  --line: #273242;
  --brand: #f0b90b;
  --brand-2: #ffcb3d;
  --danger: #ff5a6f;
  --success: #28c48f;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(240, 185, 11, 0.2), transparent 35%),
    radial-gradient(circle at 88% 0%, rgba(26, 138, 255, 0.18), transparent 40%),
    linear-gradient(165deg, #090d12 0%, #0d131b 55%, #0b0f14 100%);
  line-height: 1.45;
}

.page-wrap {
  width: min(1200px, 92vw);
  margin: 32px auto 56px;
  animation: reveal 0.45s ease;
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-title {
  margin: 0;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #39485c;
  border-radius: 999px;
  background: rgba(18, 25, 35, 0.7);
  color: #c5d0de;
  font-size: 0.82rem;
}

.grid {
  display: grid;
  gap: 16px;
}

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

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

.card {
  background: linear-gradient(180deg, rgba(22, 29, 39, 0.95) 0%, rgba(17, 23, 31, 0.96) 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.card h2,
.card h3 {
  margin-top: 0;
}

.metric-label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 6px;
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.metric-value {
  margin: 0;
  font-size: clamp(1rem, 2.5vw, 1.7rem);
  font-weight: 700;
  color: #f8fbff;
}

.metric-time {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.83rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 14, 20, 0.85);
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid #1f2a38;
  text-align: left;
  white-space: nowrap;
}

th {
  font-size: 0.78rem;
  color: #9fb0c6;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: #121923;
}

tr:hover td {
  background: rgba(240, 185, 11, 0.05);
}

form {
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

label {
  color: #b8c5d8;
  font-size: 0.9rem;
}

input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #314154;
  background: #0d141d;
  color: #eaf0f8;
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  user-select: none;
  cursor: pointer;
  color: #d5deea;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid #3a4a5f;
  border-radius: 5px;
  accent-color: var(--brand);
  cursor: pointer;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(240, 185, 11, 0.15);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(95deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #11151b;
  box-shadow: 0 10px 25px rgba(240, 185, 11, 0.25);
}

.btn-muted {
  background: #1a2432;
  color: #d2dbe8;
  border: 1px solid #334356;
}

.btn-danger {
  background: #31161d;
  color: #ffb8c3;
  border: 1px solid #7a2a3e;
}

.btn-sm {
  padding: 7px 10px;
  font-size: 0.83rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.05rem;
  line-height: 1;
}

.status {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status.running {
  background: rgba(40, 196, 143, 0.14);
  color: #84ebc7;
  border: 1px solid rgba(40, 196, 143, 0.45);
}

.status.stopped {
  background: rgba(152, 165, 184, 0.1);
  color: #b3becc;
  border: 1px solid rgba(152, 165, 184, 0.34);
}

.status.idle {
  background: rgba(152, 165, 184, 0.1);
  color: #b3becc;
  border: 1px solid rgba(152, 165, 184, 0.34);
}

.status.starting,
.status.stopping {
  background: rgba(240, 185, 11, 0.14);
  color: #ffd86f;
  border: 1px solid rgba(240, 185, 11, 0.45);
}

.status.error {
  background: rgba(255, 90, 111, 0.14);
  color: #ffc3cd;
  border: 1px solid rgba(255, 90, 111, 0.45);
}

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

.pnl-plus {
  color: #ff6b6b;
  font-weight: 600;
}

.pnl-minus {
  color: #4f8cff;
  font-weight: 600;
}

.error {
  margin: 0 0 14px;
  background: rgba(255, 90, 111, 0.14);
  border: 1px solid rgba(255, 90, 111, 0.45);
  color: #ffc3cd;
  border-radius: 10px;
  padding: 10px 12px;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 12, 0.7);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.modal-backdrop.open {
  display: flex;
  animation: reveal 0.2s ease;
}

.modal-panel {
  width: min(520px, 96vw);
  max-height: 88vh;
  background: linear-gradient(180deg, rgba(20, 28, 39, 0.98), rgba(14, 20, 29, 0.98));
  border: 1px solid #36485f;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-panel-wide {
  width: min(860px, 96vw);
}

.agent-detail-modal {
  width: min(1280px, 98vw);
  max-height: 94vh;
}

[data-modal="agent-settings-modal"] .modal-panel {
  width: min(620px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
}

[data-modal="agent-create-modal"] .modal-panel {
  max-height: 90vh;
  overflow-y: auto;
}

.agent-assets-wrap {
  max-height: 32vh;
  overflow-y: auto;
}

.agent-trades-wrap {
  max-height: 34vh;
  overflow-y: auto;
}

.agent-detail-tabs {
  display: flex;
  gap: 8px;
  margin: 8px 0 10px;
}

.agent-journals-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 12px;
  min-height: 56vh;
}

.agent-journals-list,
.agent-journals-detail {
  border: 1px solid #2a394c;
  border-radius: 12px;
  background: rgba(11, 16, 23, 0.8);
  padding: 10px;
}

.agent-journal-list-items {
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-journal-item {
  width: 100%;
  text-align: left;
  border: 1px solid #2a394c;
  border-radius: 10px;
  background: rgba(15, 21, 30, 0.95);
  color: inherit;
  padding: 10px;
  cursor: pointer;
}

.agent-journal-item:hover {
  border-color: #516a88;
}

.agent-journal-item.active {
  border-color: #d7a92f;
  box-shadow: inset 0 0 0 1px rgba(215, 169, 47, 0.25);
}

.agent-journal-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.agent-journal-item-line {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.agent-journal-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.agent-journal-metric-card {
  border: 1px solid #2a394c;
  border-radius: 10px;
  background: rgba(15, 21, 30, 0.95);
  padding: 10px;
}

.agent-journal-metric-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.agent-journal-metric-value {
  font-weight: 700;
}

.agent-journal-summary {
  margin: 0;
  padding: 12px;
  border: 1px solid #2a394c;
  border-radius: 10px;
  background: rgba(15, 21, 30, 0.95);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 64vh;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  line-height: 1.45;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, rgba(20, 28, 39, 0.98), rgba(14, 20, 29, 0.98));
  z-index: 2;
}

.modal-head h3 {
  margin: 0;
}

.kv-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid #2a394c;
  border-radius: 10px;
  background: rgba(11, 16, 23, 0.9);
  margin-top: 8px;
}

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

.kv-line strong {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  letter-spacing: 0.02em;
}

.vault-table {
  min-width: 700px;
}

.trades-table-wrap {
  max-height: 46vh;
  overflow-y: auto;
}

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

.auth-card {
  width: min(460px, 94vw);
  background: linear-gradient(180deg, rgba(20, 27, 38, 0.95), rgba(15, 21, 30, 0.98));
  border: 1px solid #2b3747;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-title {
  margin: 0;
  font-size: 1.5rem;
}

.auth-sub {
  margin: 8px 0 22px;
  color: var(--muted);
}

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

a:hover {
  color: #ffd35a;
}

@media (max-width: 980px) {
  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
  }

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

  .page-wrap {
    margin-top: 20px;
  }

  .agent-detail-modal {
    width: 98vw;
    max-height: 92vh;
  }

  .agent-assets-wrap {
    max-height: 30vh;
  }

  .agent-trades-wrap {
    max-height: 28vh;
  }

  .agent-journals-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .agent-journal-list-items,
  .agent-journal-summary {
    max-height: 28vh;
  }
}
