/* ============================================================
   Trade Journal — design system
   Palette is used ONLY through semantic tokens. No ad-hoc hex
   in components, no gradients, no purple, exactly two radii.
   ============================================================ */

:root {
  /* Raw brand palette (reference only — components use the tokens below) */
  --ink-black:       #001514;
  --espresso:        #5e3023;
  --teal:            #2d848a;
  --ash-grey:        #c6d8d3;
  --bubblegum-pink:  #f9627d;

  /* Surfaces — solid colours derived from ink-black, stepped by lightness */
  --bg:          #001514;
  --surface-1:   #062320;   /* cards / panels */
  --surface-2:   #0a302b;   /* inputs, raised rows */
  --surface-3:   #0e3a34;   /* hover / active rows */

  /* Text — ash-grey family */
  --text:        #c6d8d3;
  --text-bright: #eef4f1;
  --text-dim:    rgba(198, 216, 211, 0.58);
  --text-faint:  rgba(198, 216, 211, 0.36);

  /* Borders — ash-grey at low opacity, two strengths only */
  --border:        rgba(198, 216, 211, 0.13);
  --border-strong: rgba(198, 216, 211, 0.26);

  /* Accents */
  --teal:          #2d848a;
  --teal-bright:   #43a7ae;
  --teal-soft:     rgba(45, 132, 138, 0.16);
  --espresso:      #5e3023;
  --espresso-soft: rgba(94, 48, 35, 0.42);

  /* Semantic: profit = teal, loss = pink */
  --profit:        #43a7ae;
  --profit-soft:   rgba(45, 132, 138, 0.16);
  --loss:          #f9627d;
  --loss-soft:     rgba(249, 98, 125, 0.15);
  --danger:        #f9627d;

  /* Radii — the ONLY radii used anywhere */
  --r-control: 8px;
  --r-card:    12px;
  --r-pill:    999px;

  /* Spacing scale (4 / 8 rhythm) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  /* Typography */
  --font-ui:  system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --shadow-card:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop:   0 12px 40px rgba(0, 0, 0, 0.55);
  --ease:         180ms cubic-bezier(0.2, 0, 0, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Tabular figures everywhere numbers live */
.num, td.num, .stat-value, input[type="number"] {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

h1, h2, h3 { margin: 0; color: var(--text-bright); font-weight: 600; letter-spacing: -0.01em; }

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

:focus-visible {
  outline: 2px solid var(--teal-bright);
  outline-offset: 2px;
  border-radius: var(--r-control);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s4);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s6);
  box-shadow: var(--shadow-card);
}
.login-card .brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s5); }
.login-card h1 { font-size: 20px; }
.login-card p.sub { color: var(--text-dim); font-size: 13px; margin: 0 0 var(--s5); }

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100dvh;
}

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: var(--s5) var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  position: sticky;
  top: 0;
  height: 100dvh;
}

.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: var(--r-control);
  background: var(--teal-soft);
  border: 1px solid var(--border-strong);
  display: grid; place-items: center;
  color: var(--teal-bright);
  flex: none;
}
.brand-name { font-weight: 600; color: var(--text-bright); font-size: 15px; }
.brand-sub  { font-size: 11px; color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }

.nav-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: var(--s2);
}

.profile-list { display: flex; flex-direction: column; gap: var(--s1); flex: 1; overflow-y: auto; }

.profile-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-control);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  transition: background var(--ease), border-color var(--ease);
}
.profile-item:hover { background: var(--surface-2); }
.profile-item.active {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.profile-item.active .profile-name { color: var(--text-bright); }
.profile-dot { width: 8px; height: 8px; border-radius: var(--r-pill); flex: none; background: var(--text-faint); }
.profile-item.active .profile-dot { background: var(--teal-bright); }
.profile-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.profile-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-tags { font-size: 11px; color: var(--text-faint); font-family: var(--font-num); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-item.active .profile-tags { color: var(--text-dim); }
.profile-del {
  opacity: 0; border: none; background: none; color: var(--text-dim);
  cursor: pointer; padding: 2px; border-radius: var(--r-control); flex: none;
  display: grid; place-items: center;
}
.profile-item:hover .profile-del { opacity: 1; }
.profile-del:hover { color: var(--loss); background: var(--loss-soft); }

.type-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 1px 7px; border-radius: var(--r-pill);
  border: 1px solid var(--border-strong); color: var(--text-dim);
  font-family: var(--font-num);
}
.type-badge.live  { color: var(--loss);  border-color: var(--loss); background: var(--loss-soft); }
.type-badge.paper { color: var(--teal-bright); border-color: var(--teal); background: var(--teal-soft); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: var(--s4); }

/* ---------- Main ---------- */

.main { padding: var(--s5) var(--s6); max-width: 1200px; width: 100%; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap;
}
.page-title h2 { font-size: 22px; }
.page-title .meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; gap: var(--s2); align-items: center; }
.meta-faint { color: var(--text-faint); font-size: 12px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 9px 14px;
  min-height: 40px;
  border-radius: var(--r-control);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-bright);
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), opacity var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #022; }
.btn.primary:hover { background: var(--teal-bright); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--loss); border-color: var(--loss); background: var(--loss-soft); }
.btn.danger:hover { background: rgba(249, 98, 125, 0.24); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.icon { padding: 9px; min-width: 40px; justify-content: center; }

/* ---------- Stat cards ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s3);
  margin-bottom: var(--s5);
}
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s4);
}
.stat-label {
  font-size: 12px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; align-items: center; gap: 6px;
}
.stat-value { font-size: 26px; font-weight: 600; color: var(--text-bright); margin-top: 6px; }
.stat-value.profit { color: var(--profit); }
.stat-value.loss   { color: var(--loss); }
.stat-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ---------- Panels & charts ---------- */

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  margin-bottom: var(--s5);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4) var(--s4) var(--s3);
  border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 15px; }
.panel-body { padding: var(--s4); }

.chart-grid { display: grid; grid-template-columns: 1fr; gap: var(--s5); }
@media (min-width: 1000px) { .chart-grid { grid-template-columns: 3fr 2fr; } }

svg.chart { width: 100%; height: auto; display: block; }

/* ---------- Table ---------- */

.table-scroll { overflow-x: auto; }
table.trades { width: 100%; border-collapse: collapse; font-size: 14px; }
table.trades th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.trades th.num, table.trades td.num { text-align: right; }
table.trades td {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.trades tbody tr { transition: background var(--ease); }
table.trades tbody tr:hover { background: var(--surface-2); }
table.trades tbody tr:last-child td { border-bottom: none; }

.sym { font-weight: 600; color: var(--text-bright); }
.side-tag { font-size: 11px; font-family: var(--font-num); text-transform: uppercase; letter-spacing: 0.04em; }
.side-tag.long  { color: var(--teal-bright); }
.side-tag.short { color: var(--bubblegum-pink); }
.cell-profit { color: var(--profit); }
.cell-loss   { color: var(--loss); }

.status-pill {
  font-size: 11px; font-family: var(--font-num);
  padding: 2px 9px; border-radius: var(--r-pill);
  border: 1px solid var(--border-strong); color: var(--text-dim);
}
.status-pill.open   { color: var(--text-bright); border-color: var(--border-strong); }
.status-pill.closed { color: var(--text-dim); }

.row-actions { display: flex; gap: var(--s1); justify-content: flex-end; }
.row-btn {
  border: none; background: none; color: var(--text-dim);
  cursor: pointer; padding: 5px; border-radius: var(--r-control);
  display: grid; place-items: center;
}
.row-btn:hover { background: var(--surface-3); color: var(--text-bright); }
.row-btn.del:hover { color: var(--loss); background: var(--loss-soft); }

/* ---------- Empty state ---------- */

.empty {
  text-align: center; padding: var(--s7) var(--s4); color: var(--text-dim);
}
.empty .icon { color: var(--text-faint); margin-bottom: var(--s3); }
.empty h3 { color: var(--text); margin-bottom: var(--s2); }
.empty p { margin: 0 0 var(--s4); font-size: 14px; }

/* ---------- Forms ---------- */

label.field, .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
label.field .req { color: var(--loss); }
label.field .opt { color: var(--text-faint); }

/* ---------- Segmented control (asset class) ---------- */

.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s1);
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-control); padding: 3px;
}
@media (max-width: 460px) { .segmented { grid-template-columns: repeat(2, 1fr); } }
.seg-item { position: relative; }
.seg-item input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-item span {
  display: block; text-align: center; padding: 8px 6px;
  border-radius: 6px; font-size: 13px; color: var(--text-dim);
  cursor: pointer; transition: background var(--ease), color var(--ease);
}
.seg-item:hover span { color: var(--text-bright); }
.seg-item input:checked + span { background: var(--teal); color: #022; font-weight: 600; }
.seg-item input:focus-visible + span { outline: 2px solid var(--teal-bright); outline-offset: 2px; }

/* ---------- Risk calculator (trade modal) ---------- */

.head-chip {
  font-size: 11px; font-family: var(--font-num); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--teal-bright); background: var(--teal-soft); border: 1px solid var(--teal);
  padding: 2px 8px; border-radius: var(--r-pill); margin-left: var(--s2); vertical-align: middle;
}
.calc {
  margin-top: var(--s4); border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface-2); overflow: hidden;
}
.calc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border);
}
.calc-title { font-size: 13px; font-weight: 600; color: var(--text-bright); }
.calc-equity { font-size: 12px; color: var(--text-dim); font-family: var(--font-num); }
.calc-body { padding: var(--s4); }
.calc-hint { font-size: 13px; color: var(--text-dim); line-height: 1.55; }
.calc-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); }
@media (max-width: 460px) { .calc-row { grid-template-columns: 1fr; gap: var(--s2); } }
.calc-stat { display: flex; flex-direction: column; gap: 2px; }
.calc-k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.calc-v { font-size: 18px; font-weight: 600; color: var(--text-bright); }
.calc-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-dim); flex-wrap: wrap;
}
.calc-apply { min-height: 34px; padding: 6px 12px; font-size: 13px; }

input, select, textarea {
  font: inherit;
  background: var(--surface-2);
  color: var(--text-bright);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-control);
  padding: 9px 11px;
  min-height: 40px;
  width: 100%;
  transition: border-color var(--ease), background var(--ease);
}
textarea { min-height: 72px; resize: vertical; line-height: 1.5; }
input:hover, select:hover, textarea:hover { border-color: rgba(198, 216, 211, 0.4); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--teal-bright); background: var(--surface-3);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23c6d8d3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 34px;
}

.form-error {
  color: var(--loss); font-size: 13px; min-height: 18px;
  display: flex; align-items: center; gap: 6px;
}

/* ---------- Modal ---------- */

.scrim {
  position: fixed; inset: 0; background: rgba(0, 8, 7, 0.62);
  display: grid; place-items: center; padding: var(--s4); z-index: 100;
  animation: fade var(--ease);
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  max-height: 92dvh; overflow-y: auto;
  animation: pop var(--ease);
}
.modal.small { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface-1);
}
.modal-head h3 { font-size: 17px; }
.modal-body { padding: var(--s5); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--s3);
  padding: var(--s4) var(--s5); border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--surface-1);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop  { from { opacity: 0; transform: scale(0.98) translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */

.toast-wrap { position: fixed; bottom: var(--s5); right: var(--s5); display: flex; flex-direction: column; gap: var(--s2); z-index: 200; }
.toast {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--teal-bright);
  border-radius: var(--r-control); padding: var(--s3) var(--s4);
  color: var(--text-bright); font-size: 14px; box-shadow: var(--shadow-pop);
  animation: pop var(--ease);
}
.toast.error { border-left-color: var(--loss); }

/* ---------- Responsive shell ---------- */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    align-items: center; gap: var(--s3);
  }
  .profile-list { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .profile-item { width: auto; }
  .main { padding: var(--s4); }
}
