:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --line: #d7ded8;
  --line-strong: #aeb9b1;
  --text: #17201b;
  --muted: #64706a;
  --accent: #176b5d;
  --accent-strong: #0f5147;
  --blue: #2f5f98;
  --amber: #9a6300;
  --red: #a83b3b;
  --green: #23734d;
  --shadow: 0 12px 34px rgba(30, 38, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button.primary,
.login-form button {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

input,
select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.shell {
  min-height: 100vh;
}

.is-hidden {
  display: none !important;
}

.login-panel {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

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

.brand-row.compact {
  gap: 10px;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #163b34;
  color: #ffffff;
  font-weight: 800;
}

.brand-row.compact .mark {
  width: 34px;
  height: 34px;
}

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

h1 {
  font-size: 18px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 14px;
}

.brand-row p,
.status-line,
.login-status,
.muted {
  color: var(--muted);
}

.login-status.error,
.status-line.error {
  color: var(--red);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.app-panel {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar-actions,
.filters,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 18px;
  background: #e8ece8;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  white-space: nowrap;
  background: transparent;
}

.tabs button.active {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.workspace {
  display: grid;
  gap: 14px;
  width: min(1480px, calc(100vw - 28px));
  margin: 16px auto 40px;
}

.status-line {
  min-height: 20px;
}

.status-line.error {
  color: var(--red);
}

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

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

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

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

.metrics {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.metric {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

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

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  line-height: 1.1;
}

.metric small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

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

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

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

th,
td {
  height: 38px;
  border-bottom: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f0f2ef;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  position: sticky;
  top: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
  background: #e9ece8;
  color: var(--muted);
}

.badge.ok,
.badge.sent,
.badge.open,
.badge.queued,
.badge.signal_created {
  background: #dff1e8;
  color: var(--green);
}

.badge.warn,
.badge.pending,
.badge.market_closed,
.badge.skipped,
.badge.tp1_hit {
  background: #fff1cf;
  color: var(--amber);
}

.badge.bad,
.badge.failed,
.badge.stop_loss,
.badge.unavailable {
  background: #f8dddd;
  color: var(--red);
}

.badge.info,
.badge.partial,
.badge.closed {
  background: #dfeafa;
  color: var(--blue);
}

.json-cell {
  max-width: 440px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail {
  display: grid;
  gap: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(95px, 1fr)) auto;
  gap: 8px;
  align-items: end;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .edit-grid {
    grid-template-columns: 1fr 1fr;
  }
}
