:root {
  color-scheme: light;
  --ink: #191f28;
  --muted: #8b95a1;
  --line: #edf0f3;
  --panel: #ffffff;
  --bg: #f7f8fa;
  --green: #00a661;
  --blue: #3182f6;
  --red: #f04452;
  --amber: #f59f00;
  --soft-green: #eafaf2;
  --soft-blue: #eef6ff;
  --soft-red: #fff0f1;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.topbar,
.panel-heading,
.summary-grid,
.workbench,
.rule-grid,
.top-actions,
.view-tabs,
.legend {
  display: flex;
}

.topbar {
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
  padding: 2px 2px 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.14;
  letter-spacing: 0;
  font-weight: 800;
}

.dashboard-title-input {
  display: block;
  width: min(620px, 100%);
  margin: 0;
  padding: 0 2px 3px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 32px;
  line-height: 1.14;
  letter-spacing: 0;
  font-weight: 800;
  outline: none;
}

.dashboard-title-input:focus {
  border-bottom-color: #d8dee5;
}

.today-label {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.title-meta-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 7px;
}

.top-close-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 19px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.top-close-control strong {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 850;
}

.fetch-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.fetch-close-btn:hover {
  background: var(--accent-soft, rgba(59, 130, 246, 0.12));
  color: var(--accent, #2563eb);
  border-color: var(--accent, #2563eb);
}

.fetch-close-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.visually-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.top-close-status {
  min-height: 18px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  font-weight: 650;
}

.quote-up {
  color: var(--red) !important;
}

.quote-down {
  color: var(--blue) !important;
}

.quote-flat {
  color: var(--muted) !important;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: 0;
  font-weight: 800;
}

.top-actions {
  align-items: center;
  gap: 5px;
  padding-top: 61px;
}

.view-tabs {
  align-items: center;
  gap: 4px;
  min-width: max-content;
  margin-top: 61px;
  padding: 2px;
  border-radius: 9px;
  background: #eef0f3;
}

.view-tab {
  min-height: 30px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.view-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0 0 1px #d8dee5;
}

.view-sheet[hidden] {
  display: none !important;
}

.is-backtest-view .rules-panel {
  display: none;
}

.currency-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 30px);
  height: 30px;
  padding: 2px;
  border-radius: 9px;
  background: #eef0f3;
}

.currency-option {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.currency-option.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0 0 1px #d8dee5;
}

.icon-button,
.text-button,
.wide-button {
  border: 0;
  background: #f2f4f6;
  color: var(--ink);
  min-height: 30px;
}

.icon-button {
  min-width: 58px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.icon-button:hover,
.text-button:hover,
.wide-button:hover {
  background: #e5e8eb;
}

.icon-button.danger:hover {
  background: var(--soft-red);
  color: var(--red);
}

.text-button {
  border-radius: 8px;
  padding: 0 13px;
  font-weight: 700;
}

.wide-button {
  width: 100%;
  min-height: 42px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-weight: 800;
}

.wide-button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.wide-button.primary:hover {
  background: #1b64da;
  border-color: #1b64da;
}

.summary-grid,
.summary-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.metric,
.panel {
  background: var(--panel);
  border: 0;
  box-shadow: var(--shadow);
}

.metric {
  display: grid;
  grid-template-rows: 24px minmax(34px, auto) minmax(34px, auto);
  align-items: center;
  min-height: 150px;
  padding: 20px;
  border-radius: 8px;
  text-align: center;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  text-align: center;
  min-width: 0;
}

.metric strong {
  display: block;
  min-width: 0;
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
  line-height: 1.12;
  font-weight: 800;
  text-align: center;
  overflow-wrap: anywhere;
}

.metric strong.buy {
  color: var(--red);
}

.metric strong.sell {
  color: var(--blue);
}

.metric strong.wait {
  color: var(--amber);
}

.metric small {
  align-self: start;
  line-height: 1.35;
}

/* 손익(수익금·수익률): 국내 증시 관행대로 이익은 빨강, 손실은 파랑.
   전일대비(.quote-up/.quote-down)와 같은 규칙이다. */
.value-positive {
  color: var(--red);
}

.value-negative {
  color: var(--blue);
}

/* 입출금·배당은 손익이 아니라 현금 증감이라 기존 색을 유지한다(들어오면 파랑, 나가면 빨강). */
.flow-positive {
  color: var(--blue);
}

.flow-negative {
  color: var(--red);
}

.workbench {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: flex-start;
  gap: 10px;
}

.panel {
  border-radius: 8px;
}

.controls-panel {
  position: sticky;
  top: 18px;
  width: 100%;
  min-width: 0;
  padding: 20px;
}

.sidebar-group {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.sidebar-group:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.sidebar-group h3 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.sidebar-group h3 span {
  display: block;
  color: #8b95a1;
  font-size: 12px;
  line-height: 1.25;
}

.cycle-setting-hint {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}

label {
  line-height: 1.35;
  word-break: keep-all;
}

.main-column {
  display: grid;
  grid-column: span 5;
  gap: 10px;
  min-width: 0;
}

.panel-heading {
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
  position: relative;
  text-align: center;
}

.panel-heading > :not(h2) {
  position: absolute;
  right: 0;
}

.panel-heading h2 {
  width: 100%;
  text-align: center;
}

.controls-panel .panel-heading {
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.controls-panel .panel-heading > :not(h2) {
  position: static;
}

.controls-panel .panel-heading h2 {
  width: auto;
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.pill.buy {
  background: var(--soft-red);
  color: var(--red);
}

.pill.sell {
  background: var(--soft-blue);
  color: var(--blue);
}

.pill.wait {
  background: #f5ecdd;
  color: var(--amber);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field-note {
  min-height: 34px;
  margin: -2px 0 13px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.field-note.is-warning {
  color: var(--red);
  font-weight: 700;
}

.cycle-setting-hint.is-warning {
  color: var(--red);
  font-weight: 700;
}

/* 주문표 안 G 추천 칸 — 판정 버튼은 카드 우측 상단에 두어
   다른 카드와 높이를 맞춘다(버튼 줄이 아래로 붙으면 카드가 통째로 길어진다). */
.g-suggest-cell {
  position: relative;
}

.g-suggest-row {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
  display: flex;
  gap: 6px;
  align-items: center;
}

.g-suggest-row .mini-button {
  padding: 2px 8px;
  font-size: 11px;
}

.g-suggest-cell strong {
  font-size: 15px;
}

.g-suggest-cell .g-zone-oversold {
  color: #d12636;
}

.g-suggest-cell .g-zone-overbought {
  color: #1f66d6;
}

input,
select {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #f2f4f6;
}

input[readonly] {
  color: var(--muted);
  cursor: default;
}

.controls-panel .sidebar-group label input,
.controls-panel .sidebar-group label select {
  width: 66.6667%;
  justify-self: start;
}

.controls-panel .sidebar-group label input[type="date"] {
  width: 100%;
}

input:focus,
select:focus {
  outline: 3px solid rgba(49, 130, 246, 0.14);
  background: #fff;
}

button:focus-visible {
  outline: 3px solid rgba(49, 130, 246, 0.22);
  outline-offset: 2px;
}

.chart-panel,
.rules-panel,
.ticket-panel,
.cycle-panel {
  min-width: 0;
  padding: 18px;
}

.operation-panel {
  min-width: 0;
}

canvas {
  display: block;
  width: 100%;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.allocation-metric {
  display: grid;
  grid-template-rows: 22px 1fr;
  grid-column: 5 / span 2;
  grid-row: 1 / span 2;
  align-items: stretch;
  min-height: 300px;
  padding: 12px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.allocation-metric canvas {
  height: 270px;
  max-height: none;
  margin-top: -2px;
  border: 0;
  contain: size layout paint;
}

.legend {
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
}

.chart-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

.chart-range {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border-radius: 8px;
  background: #f2f4f6;
}

.range-option {
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
  cursor: pointer;
}

.range-option.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 2px rgba(25, 31, 40, 0.1);
}

.chart-canvas-wrap {
  position: relative;
}

#valueChart {
  height: 300px;
  touch-action: none;
}

.chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  transform: translate(-50%, 8px);
  pointer-events: none;
  padding: 8px 11px;
  border-radius: 8px;
  background: rgba(25, 31, 40, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.55;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(25, 31, 40, 0.22);
}

.chart-tooltip strong {
  font-weight: 800;
}

.chart-tooltip .tip-title {
  display: block;
  margin-bottom: 3px;
  font-weight: 800;
}

.chart-tooltip .tip-projected {
  color: #cdd5df;
}

.chart-tooltip .tip-sub {
  color: #cdd5df;
  font-size: 11px;
}

.target-dot {
  background: var(--blue);
}

.current-dot {
  background: var(--green);
}

.band-dot {
  background: var(--amber);
}

.v-dot {
  background: var(--ink);
}

.principal-dot {
  background: var(--muted);
}

.trade-dot {
  background: var(--red);
}

.chart-subheading {
  display: flex;
  justify-content: flex-end;
  margin: 2px 0 10px;
}

.limit-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.order-heading-tools {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.operation-heading-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--card);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mini-button.primary {
  background: var(--soft-blue);
  color: var(--blue);
}

.inline-control {
  display: inline-grid;
  grid-template-columns: auto 72px;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.inline-control input {
  width: 72px;
  height: 34px;
  padding: 0 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 750;
}

.ticket-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

/* 카드 스타일은 직계 자식에만 준다(카드 안에 중첩된 div가 또 카드처럼 커지지 않게) */
.ticket-grid > div {
  min-height: 112px;
  border: 0;
  border-radius: 8px;
  padding: 16px;
  background: #f7f8fa;
}

.ticket-grid span,
.ticket-grid small {
  display: block;
  color: var(--muted);
  text-align: center;
}

.ticket-grid strong {
  display: block;
  margin: 11px 0 8px;
  font-size: 24px;
  line-height: 1.08;
  font-weight: 800;
  text-align: center;
}

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

.order-plan-card {
  min-width: 0;
  border-radius: 8px;
  padding: 8px;
}

.order-plan-panel {
  padding: 12px;
}

.order-plan-panel .panel-heading {
  min-height: 34px;
  margin-bottom: 10px;
}

.order-plan-panel .panel-heading h2 {
  font-size: 18px;
}

.buy-plan {
  background: #fff0f1;
}

.sell-plan {
  background: #eef6ff;
}

.order-plan-title {
  display: grid;
  gap: 3px;
  margin-bottom: 7px;
  text-align: center;
}

/* 매수·매도 계획: 주문 단위를 각 상자 우측 상단에 배치한다. */
.order-plan-card {
  position: relative;
}

.order-plan-title .plan-lot {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  grid-template-columns: auto 48px;
  gap: 5px;
  font-size: 11px;
}

.order-plan-title .plan-lot input {
  width: 48px;
  height: 24px;
  min-width: 0;
  padding: 0 6px;
  font-size: 12px;
}

.order-plan-title strong {
  font-size: 16px;
  line-height: 1.1;
}

.order-plan-title span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.order-plan-card .table-wrap {
  max-height: 180px;
  overflow: auto;
  border-radius: 7px;
  background: #fff;
}

.order-plan-card table {
  min-width: 0;
  background: #fff;
  table-layout: fixed;
}

.order-plan-card thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.order-plan-card th,
.order-plan-card td {
  padding: 6px 5px;
  font-size: 11px;
  line-height: 1.15;
}

.order-plan-card td:first-child {
  font-weight: 800;
}

.order-plan-card td.order-plan-empty {
  height: 72px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
  white-space: normal;
}

/* 보유량(예정 수량)은 분홍·파랑 바탕에서도 또렷하게 읽히도록 진하게 (매수·매도 동일) */
.order-plan-card td.plan-shares {
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.buy-plan .order.buy,
.sell-plan .order.sell {
  font-size: 12px;
  font-weight: 800;
}

/* 주문표 전용 진한 빨강·파랑: 분홍(#fff4f5)·하늘(#f3f8ff) 바탕에서 WCAG AA(4.5:1)를 넘긴다.
   전역 --red/--blue는 그대로 두고 여기서만 어둡게 한다. */
.buy-plan .order.buy {
  color: #d12636; /* 분홍 4.83:1 · 흰색 5.2:1 */
}

.sell-plan .order.sell {
  color: #1f66d6; /* 하늘 5.01:1 · 흰색 5.34:1 */
}

.buy-plan tr.order-planned td {
  background: #fff4f5;
}

.sell-plan tr.order-planned td {
  background: #f3f8ff;
}

.order-plan-card tr.order-planned td:first-child {
  border-radius: 6px 0 0 6px;
}

.order-plan-card tr.order-planned td:last-child {
  border-radius: 0 6px 6px 0;
}

.plan-action-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 22px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  gap: 3px;
}

.execution-hint {
  font-size: 8px;
  font-weight: 800;
  opacity: 0.68;
}

.plan-action-label.buy {
  background: #fff0f1;
  color: #d12636;
}

.plan-action-label.sell {
  background: #eef6ff;
  color: #1f66d6;
}

/* '즉시' 보조 라벨은 opacity로 흐려져 대비가 떨어지므로 흐림을 줄인다 */
.execution-hint {
  opacity: 0.85;
}

.backtest-controls {
  display: grid;
  grid-template-columns: 1fr 0.85fr 1.15fr repeat(7, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.journal-entry-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.9fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.journal-entry-grid label {
  grid-template-rows: 20px 42px;
  margin-bottom: 0;
  text-align: center;
}

.journal-entry-grid input,
.journal-entry-grid select {
  height: 42px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.journal-save {
  width: auto;
  min-width: 128px;
  height: 42px;
  min-height: 42px;
  margin-bottom: 0;
  padding: 0 16px;
  white-space: nowrap;
}

/* 운용내역: 내용 크기대로 두고 가로 스크롤로 본다(글자 확대) */
.operation-panel table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.operation-panel th,
.operation-panel td {
  padding: 8px 10px;
  font-size: 12px;
  white-space: nowrap;
}

/* 배당 입력: 회색 칸 없이 다른 셀처럼 보이게, 클릭·포커스 때만 편집 표시 */
.cycle-dividend {
  width: 52px;
  min-width: 0;
  height: 24px;
  padding: 0 2px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.cycle-dividend::placeholder {
  color: #c3cad4;
  font-weight: 600;
}

.cycle-dividend:focus {
  background: #fff;
  outline: 2px solid rgba(49, 130, 246, 0.18);
}

/* 배당 표시: 입출금 셀과 같은 폰트·색(부호별 tone), 클릭하면 편집 */
.dividend-value {
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.cycle-actions {
  white-space: nowrap;
}

.cycle-edit,
.cycle-delete {
  border: 0;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.cycle-edit {
  margin-right: 4px;
}

.cycle-edit {
  background: var(--soft-blue);
  color: var(--blue);
}

.cycle-delete {
  background: var(--soft-red);
  color: var(--red);
}

.cycle-delete:disabled {
  cursor: default;
  opacity: 0.35;
}

.journal-panel table {
  min-width: 1040px;
}

.journal-table-wrap {
  max-height: 620px;
  overflow: auto;
}

.sheet-link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}

.sheet-link-row label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sheet-link-row input {
  flex: 1;
  min-width: 180px;
  height: 34px;
  font-size: 12px;
  font-weight: 600;
}

.sheet-link-row #sheetSaveBtn {
  flex-shrink: 0;
  height: 34px;
}

.sheet-link-row #sheetLinkStatus {
  min-height: 0;
  margin: 0;
  white-space: nowrap;
}

.journal-cell {
  width: 100%;
  min-width: 0;
  height: 22px;
  border-radius: 6px;
  padding: 0 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

/* 매매일지 기록 행 높이를 절반으로(다른 표는 그대로) */
.journal-table-wrap th,
.journal-table-wrap td {
  padding: 4px 12px;
  text-align: center; /* 입력값·표시값 모두 열 가운데 정렬 */
  vertical-align: middle;
}

/* 날짜가 잘리지 않도록 첫 열에 충분한 폭을 준다(2026. 07. 21. 전체 표시) */
.journal-table-wrap th:first-child,
.journal-table-wrap td:first-child {
  min-width: 132px;
}

.journal-cell[type="date"] {
  width: 100%;
  min-width: 118px;
  text-overflow: clip;
}

#recordRows .pill {
  min-height: 22px;
  min-width: 46px;
}

.journal-cell[type="date"] {
  cursor: pointer;
  padding-right: 8px;
  color-scheme: light;
}

.journal-cell[type="date"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator {
  width: 18px;
  height: 18px;
  opacity: 1;
  cursor: pointer;
}

/* 저장된 매매일지 행: 회색 입력 상자 배경을 없애고 글자만 표시(클릭해 편집하면 다시 상자 표시) */
#recordRows tr[data-journal-row]:not([data-journal-row="__new__"]) .journal-cell {
  background: transparent;
}

#recordRows tr[data-journal-row]:not([data-journal-row="__new__"]) .journal-cell[type="date"]::-webkit-calendar-picker-indicator {
  display: none;
}

/* 관리 열: 편집(저장)과 삭제를 나란히 둔다 */
.row-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
}

.row-save,
.row-edit,
.row-remove {
  border: 0;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.row-save,
.row-edit {
  background: var(--soft-blue);
  color: var(--blue);
}

.row-remove {
  background: var(--soft-red);
  color: var(--red);
}

/* 편집 중인 행만 입력 상자를 다시 보여준다(읽기 전용 행은 글자만) */
#recordRows tr[data-journal-row].journal-row-editing .journal-cell {
  background: #f2f4f6;
}

#recordRows tr[data-journal-row].journal-row-editing .journal-cell[type="date"]::-webkit-calendar-picker-indicator {
  display: inline-block;
}

.backtest-controls label {
  display: grid;
  grid-template-rows: 22px 50px;
  gap: 6px;
  min-width: 0;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.backtest-controls input,
.backtest-controls select {
  width: 100%;
  min-width: 0;
  height: 50px;
  padding: 0 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.backtest-controls select {
  padding-right: 28px;
}

.backtest-controls input[type="date"] {
  font-size: 15px;
}

.backtest-sheet {
  margin-top: 8px;
}

.backtest-panel {
  padding: 20px;
}

.backtest-panel > .panel-heading {
  min-height: 36px;
  margin-bottom: 18px;
}

.backtest-panel > .panel-heading h2 {
  font-size: 22px;
}

.backtest-grid {
  gap: 12px;
  margin-bottom: 16px;
}

.backtest-grid div {
  min-height: 126px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.backtest-grid span {
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

.backtest-grid strong {
  margin: 10px 0 7px;
  font-size: 26px;
}

.backtest-grid small {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1.35;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.backtest-table-wrap {
  max-height: 420px;
  overflow: auto;
}

.backtest-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

table {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 0;
}

.journal-table-wrap table,
.backtest-table-wrap table {
  min-width: 760px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 14px 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fff;
  text-align: center;
}

td {
  font-size: 14px;
}

td:nth-child(n + 2) {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
  text-align: center;
}

td input {
  height: 36px;
  min-width: 92px;
}

td:first-child input {
  min-width: 150px;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.order {
  font-weight: 800;
}

.order.buy {
  color: var(--red);
}

.order.sell {
  color: var(--blue);
}

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

.row-remove {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}

.row-remove:hover {
  color: var(--red);
  border-color: var(--red);
}

.rules-panel {
  margin-top: 10px;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.rule-grid div {
  border-left: 0;
  border-top: 1px solid var(--line);
  padding: 14px 0 0;
}

.rule-grid strong {
  display: block;
  margin-bottom: 7px;
}

.rule-grid p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

@media (max-width: 900px) {
  .dashboard-title-input {
    font-size: 28px;
  }

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

  .allocation-metric {
    grid-column: auto;
    grid-row: auto;
    aspect-ratio: auto;
    min-height: 220px;
  }

  .allocation-metric canvas {
    height: 180px;
  }

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

  .controls-panel {
    position: static;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 12px;
  }

  .main-column {
    grid-column: auto;
  }

  .controls-panel .panel-heading {
    grid-column: 1 / -1;
  }

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

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

  .order-plan-board {
    grid-template-columns: 1fr;
  }

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

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

  .journal-save {
    width: 100%;
  }

  .backtest-grid {
    gap: 12px;
  }

  .backtest-grid div {
    min-height: 126px;
  }

  .backtest-grid span {
    font-size: 15px;
  }

  .backtest-grid strong {
    font-size: 26px;
  }

  .backtest-grid small {
    font-size: 14px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 18px 12px;
  }

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

  .view-tabs {
    width: 100%;
    margin-top: 0;
  }

  .view-tab {
    flex: 1;
  }

  .top-actions {
    width: 100%;
    padding-top: 0;
    justify-content: flex-end;
  }

  .summary-grid,
  .summary-board,
  .controls-panel,
  .rule-grid,
  .ticket-grid,
  .order-plan-board,
  .backtest-controls,
  .journal-entry-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 110px;
  }

  .backtest-controls label {
    grid-template-rows: auto 50px;
    white-space: normal;
  }

  .backtest-controls input,
  .backtest-controls select {
    height: 50px;
    font-size: 16px;
  }

  .backtest-grid div {
    min-height: 160px;
  }

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

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading > :not(h2) {
    position: static;
    align-self: center;
  }
}

@media (max-width: 1180px) and (min-width: 1061px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.journal-row-error td {
  background: #fff1f2;
}

.journal-row-error .journal-cell {
  outline: 2px solid rgba(240, 68, 82, 0.28);
  outline-offset: -2px;
}

.cloud-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: #191f28;
  box-shadow: 0 18px 60px rgba(25, 31, 40, 0.2);
}

.cloud-dialog::backdrop {
  background: rgba(25, 31, 40, 0.38);
}

.cloud-dialog-inner {
  display: grid;
  gap: 14px;
  padding: 24px;
}

.cloud-dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.cloud-dialog-heading h2,
.cloud-dialog-heading p {
  margin: 0;
}

.cloud-dialog-heading p {
  margin-top: 6px;
  color: #8b95a1;
  font-size: 14px;
}

.cloud-dialog label {
  display: grid;
  gap: 7px;
  color: #6b7684;
  font-size: 14px;
  font-weight: 700;
}

.cloud-dialog input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid #e5e8eb;
  border-radius: 6px;
  background: #f7f8fa;
  color: #191f28;
  font: inherit;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #6b7684;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

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