:root {
  color-scheme: light;
  --bg: #f5f6f2;
  --surface: #ffffff;
  --surface-2: #eef3f0;
  --ink: #14171f;
  --muted: #67707f;
  --line: #d8ded8;
  --accent: #0f766e;
  --accent-strong: #0a4f49;
  --blue: #2563eb;
  --danger: #c2410c;
  --danger-soft: #fff1eb;
  --warn: #b7791f;
  --warn-soft: #fff8e6;
  --ok: #16803a;
  --ok-soft: #eaf7ef;
  --shadow: 0 18px 45px rgba(23, 30, 42, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button,
label.file-button {
  user-select: none;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 84px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
  letter-spacing: 0;
}

.top-actions,
.form-actions,
.journal-toolbar,
.toolbar-fields,
.tabs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 15px;
  cursor: pointer;
  font-weight: 800;
  color: var(--ink);
  background: var(--surface);
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

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

.button:focus-visible,
.tab:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.secondary {
  background: #1f2937;
  color: #fff;
}

.button.ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  font-size: 1rem;
}

.button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #ffd7c5;
}

.settings-band {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 650;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.left-rail,
.main-panel,
.insight-block {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.left-rail {
  position: sticky;
  top: 14px;
  padding: 16px;
}

.main-panel {
  padding: 16px;
}

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

.section-heading span {
  min-width: 52px;
  border-radius: 999px;
  padding: 5px 10px;
  text-align: center;
  color: var(--accent-strong);
  background: var(--surface-2);
  font-size: 0.78rem;
  font-weight: 900;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.trade-form {
  display: grid;
  gap: 13px;
}

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

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

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

.risk-preview div {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-2);
}

.risk-preview span,
.metric-label,
.metric-note {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.risk-preview strong {
  display: block;
  margin-top: 6px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.form-actions {
  flex-wrap: wrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(135px, 1fr));
  gap: 10px;
}

.metric-card {
  min-height: 106px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfb;
}

.metric-value {
  display: block;
  margin: 10px 0 7px;
  font-size: clamp(1.2rem, 2.1vw, 1.8rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.metric-card.good {
  background: var(--ok-soft);
  border-color: #c8ead2;
}

.metric-card.warn {
  background: var(--warn-soft);
  border-color: #f3d792;
}

.metric-card.danger {
  background: var(--danger-soft);
  border-color: #ffd7c5;
}

.alerts-panel {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fbfcfb;
  color: var(--ink);
  font-weight: 760;
}

.alert::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--ok);
}

.alert.warn {
  background: var(--warn-soft);
  border-color: #f3d792;
}

.alert.warn::before {
  background: var(--warn);
}

.alert.danger {
  background: var(--danger-soft);
  border-color: #ffd7c5;
}

.alert.danger::before {
  background: var(--danger);
}

.journal-toolbar {
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 12px;
  flex-wrap: wrap;
}

.tabs {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--surface-2);
}

.tab {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.tab.active {
  background: #fff;
  color: var(--accent-strong);
  box-shadow: 0 5px 14px rgba(14, 26, 31, 0.08);
}

.toolbar-fields {
  flex-wrap: wrap;
}

.toolbar-fields label {
  width: min(220px, 100vw);
}

.insights-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.insight-block {
  padding: 12px;
  box-shadow: none;
}

.breakdown,
.recent-list {
  display: grid;
  gap: 8px;
}

.breakdown-item {
  display: grid;
  gap: 6px;
}

.breakdown-top,
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 830;
}

.bar-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.recent-item {
  min-height: 37px;
  border-bottom: 1px solid var(--line);
}

.recent-item:last-child {
  border-bottom: 0;
}

.table-shell {
  position: relative;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
  font-weight: 690;
}

tbody tr:hover {
  background: #fbfcfb;
}

.status-pill,
.side-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 900;
}

.status-pill.open {
  background: var(--warn-soft);
  color: #8a5d12;
}

.status-pill.closed {
  background: var(--ok-soft);
  color: var(--ok);
}

.side-pill.long {
  background: #e8f2ff;
  color: var(--blue);
}

.side-pill.short {
  background: var(--danger-soft);
  color: var(--danger);
}

.profit {
  color: var(--ok);
}

.loss {
  color: var(--danger);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.mini-button {
  min-width: 34px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.empty-state {
  display: none;
  place-items: center;
  gap: 6px;
  min-height: 160px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  color: var(--ink);
}

.table-shell.empty table {
  display: none;
}

.table-shell.empty .empty-state {
  display: grid;
}

@media (max-width: 1180px) {
  .settings-band {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

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

  .left-rail {
    position: static;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

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

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions .button,
  .top-actions .file-button {
    flex: 1 1 82px;
    text-align: center;
  }

  .settings-band,
  .form-grid,
  .risk-preview,
  .metric-grid,
  .insights-row {
    grid-template-columns: 1fr;
  }

  .journal-toolbar,
  .toolbar-fields,
  .tabs {
    width: 100%;
  }

  .tabs {
    justify-content: stretch;
  }

  .tab {
    flex: 1 1 0;
  }

  .toolbar-fields label {
    width: 100%;
  }
}
