:root {
  color-scheme: light;
  --bg: #f8fafc;
  --sidebar-bg: #ffffff;
  --sidebar-text: #0f172a;
  --sidebar-active: #e2e8f0;
  --sidebar-active-text: #0f172a;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --focus: #3b82f6;
  --button: #2563eb;
  --button-hover: #1d4ed8;
  --disabled: #f1f5f9;
  --success: #10b981;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.3s ease, color 0.3s ease;
  font-family:
    "Inter",
    "Pretendard",
    "-apple-system",
    "Segoe UI",
    "Noto Sans KR",
    system-ui,
    sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  letter-spacing: -0.02em;
}

/* Layout Structure */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  width: 100%;
}

.app-sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* 모바일 헤더 및 드로어 스타일 */
.mobile-header {
  display: none;
  height: 56px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 0 16px;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--line);
}

.mobile-logo {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
}

.menu-btn {
  background: transparent;
  border: 0;
  color: var(--sidebar-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.sidebar-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px 24px;
}

.sidebar-header .sidebar-logo {
  padding: 0;
}

.mobile-only {
  display: none;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .mobile-header {
    display: flex;
  }

  .mobile-only {
    display: flex;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 999;
    transform: translateX(-100%);
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }
}

.sidebar-logo {
  padding: 0 24px 32px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--sidebar-text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.sidebar-link:hover {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text, white);
}

.sidebar-link.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text) !important;
  border-left: 4px solid var(--focus);
  padding-left: 20px;
  box-shadow: inset 4px 0 0 -4px var(--focus);
}

.app-sidebar a,
.app-sidebar button,
.app-sidebar .sidebar-link,
.app-sidebar .sidebar-link span,
.app-sidebar .sidebar-link i {
  color: var(--sidebar-text) !important;
}

.sidebar-link:hover,
.sidebar-link.is-active {
  color: var(--sidebar-active-text) !important;
}

.app-main {
  padding: 32px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
  overflow-x: hidden;
}

@media (max-width: 768px) {
  .app-main {
    padding: 16px;
    gap: 20px;
  }
}

/* Hero Section */
.hero-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 170px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.hero-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hero-card-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--line) 20%, var(--surface));
}

.hero-card-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.hero-card .label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hero-card .value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.hero-card .trend {
  font-size: 13px;
  font-weight: 600;
}

.hero-card-detail {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-top: 4px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

.text-buy { color: var(--button); font-weight: 700; }
.text-sell { color: var(--danger); font-weight: 700; }
.bg-buy { background: color-mix(in srgb, var(--button) 10%, var(--surface)); }
.bg-sell { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }

/* Grid Sections */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr));
  gap: 24px;
  width: 100%;
  align-items: start;
}

.settings-page-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 768px) {
  .settings-page-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.card-header span {
  font-size: 13px;
  color: var(--muted);
}

.sync-status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 13px;
  color: var(--muted);
}

.sync-status-badge.success {
  border-color: var(--success);
  color: var(--success);
}

.sync-status-badge.error,
.sync-status-badge.partial_failure {
  border-color: var(--danger);
  color: var(--danger);
}

.sync-status-badge .compact-action {
  padding: 2px;
  min-height: auto;
  width: auto;
  border: 0;
  background: transparent;
  color: inherit;
}

.syncing i[data-lucide="refresh-cw"] {
  animation: spin 1s linear infinite;
}

/* Activity Log */
.activity-log-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}

.activity-item {
  display: flex;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.activity-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.activity-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.activity-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-message {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.activity-time {
  font-size: 12px;
  color: var(--muted);
}

/* Shortcut Guide */
.shortcut-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shortcut-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

kbd {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
  min-width: 32px;
  text-align: center;
}

/* Dark Mode Variables */
body.dark-theme {
  --bg: #0f172a;
  --sidebar-bg: #020617;
  --sidebar-text: #e2e8f0;
  --sidebar-active: #1e293b;
  --sidebar-active-text: #f8fafc;
  --surface: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  --focus: #3b82f6;
  --button: #3b82f6;
  --button-hover: #60a5fa;
  --disabled: #1e293b;
}

body.dark-theme .csv-drop-zone {
  background: #0f172a;
}

body.dark-theme .result-table th {
  background: #1e293b;
  color: #f8fafc;
}

body.dark-theme .result-table tbody tr:nth-child(even) {
  background: #0f172a;
}

body.dark-theme input,
body.dark-theme select,
body.dark-theme textarea {
  background: #0f172a;
  color: #f8fafc;
  border-color: #334155;
}

body.dark-theme .strategy-link {
  background: #1e293b;
  border-color: #334155;
}

body.dark-theme .strategy-link.primary-link {
  background: #1e293b;
  border-color: var(--focus);
}

.backtest-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.is-hidden {
  display: none;
}

.csv-drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  margin-bottom: 18px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  cursor: pointer;
  padding: 12px 16px;
  text-align: center;
}

.csv-drop-zone strong {
  color: var(--text);
  font-size: 14px;
}

.csv-drop-zone span {
  font-size: 13px;
}

.csv-drop-zone:hover,
.csv-drop-zone:focus,
.csv-drop-zone.is-dragging {
  border-color: var(--focus);
  outline: 2px solid color-mix(in srgb, var(--focus) 18%, transparent);
}

.csv-drop-zone.is-dragging {
  background: color-mix(in srgb, var(--focus) 5%, var(--surface));
  border-style: solid;
  transform: scale(1.01);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 1s linear infinite;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--focus);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

body.dark-theme .spinner {
  border-color: rgba(255, 255, 255, 0.1);
  border-top-color: var(--focus);
}

.two-track-drop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.home-section {
  margin-top: 18px;
}

.home-section + .home-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.home-section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.home-section-header h2 {
  margin: 0;
  font-size: 18px;
}

.home-section-header span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.strategy-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 0;
  align-items: stretch;
}

.execution-nav {
  grid-template-columns: minmax(0, 1fr);
}

.backtest-nav {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.strategy-link {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  min-height: 150px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.strategy-link.primary-link {
  min-height: 150px;
  border-color: color-mix(in srgb, var(--focus) 36%, var(--line));
  background: color-mix(in srgb, var(--focus) 10%, var(--surface));
}

.strategy-link:hover {
  transform: translateY(-2px);
  border-color: var(--focus);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
}

.strategy-link strong {
  font-size: 18px;
  line-height: 1.2;
}

.strategy-link span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  white-space: normal;
}

.db-run-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.db-run-panel h3,
.section-subheader h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.db-run-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.db-run-panel span {
  color: var(--muted);
  font-size: 13px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.settings-row h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.settings-row span {
  color: var(--muted);
  font-size: 13px;
}

.settings-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(100%, 460px);
}

.settings-controls input {
  min-width: 0;
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

.paste-panel {
  margin-top: 18px;
}

.paste-textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: 13px/1.5 Consolas, "Courier New", monospace;
}

.paste-textarea:focus {
  border-color: var(--focus);
  outline: 2px solid color-mix(in srgb, var(--focus) 18%, transparent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.38);
}

.modal-backdrop.is-hidden {
  display: none;
}

.modal-panel {
  width: min(100%, 760px);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
  padding: 16px;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  margin-bottom: 12px;
}

.modal-description {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

.modal-footer {
  margin-top: 10px;
}

.modal-footer .form-status {
  min-height: 0;
  margin: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: 16px;
}

.compact-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.two-track-settings {
  display: grid;
  gap: 14px;
}

.settings-group {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.settings-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.settings-group h2 {
  margin-bottom: 12px;
  color: var(--text);
  font-size: 15px;
}

.settings-page-stack {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.settings-panel-group {
  min-width: 0;
}

.settings-shortcut-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.settings-shortcut-grid .field {
  min-width: 0;
}

.settings-action-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.settings-action-column .run-button,
.settings-danger-button {
  width: 100%;
}

.settings-backup-list {
  margin-top: 8px;
  width: 100%;
  overflow: hidden;
}

.settings-backup-table {
  width: 100%;
  overflow: visible;
  border: 1px solid var(--line);
}

.backup-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.85rem;
}

.backup-file-cell {
  min-width: 0;
  overflow: hidden;
  padding: 8px 6px;
}

.backup-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.backup-download-cell {
  width: 36px;
  padding: 8px 6px 8px 0;
  text-align: right;
  vertical-align: middle;
}

.backup-download-cell .compact-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
}

.settings-danger-button {
  box-sizing: border-box;
  color: var(--danger);
  border-color: var(--danger);
  margin-top: 12px;
}

.live-create-panel {
  padding-top: 0;
}

.live-create-panel h2 {
  margin-bottom: 8px;
}

.live-create-grid {
  grid-template-columns: 1.4fr 0.75fr repeat(3, minmax(86px, 0.9fr)) 1.15fr repeat(4, minmax(92px, 0.9fr)) auto;
  gap: 8px;
  align-items: end;
}

.live-create-grid .field {
  gap: 4px;
}

.live-create-grid .field span {
  font-size: 12px;
}

.live-create-modal {
  width: min(100%, 920px);
}

.live-create-modal .live-create-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.live-create-modal .live-create-panel {
  border-top: 0;
  padding-top: 0;
}

.live-create-grid input,
.live-create-grid select {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

.live-create-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  min-width: 96px;
}

.live-create-panel .run-button {
  min-height: 34px;
  min-width: 88px;
  padding: 7px 14px;
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.round-input-detail {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
}

.manual-order-guide {
  margin: 10px 0 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
}

.auto-trade-panel {
  display: grid;
  gap: 8px;
  margin: 10px 0 16px;
}

.auto-trade-payload {
  min-height: 130px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
}

.broker-panel {
  display: grid;
  gap: 10px;
  margin: 16px 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.broker-panel-main {
  display: grid;
  grid-template-columns: minmax(180px, 240px) max-content minmax(220px, 1fr);
  gap: 12px;
  align-items: end;
}

.broker-provider-field select {
  min-height: 36px;
}

.broker-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.switch-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.switch-field input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e5e7eb;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
  transition: transform 0.16s ease;
}

.switch-field input:checked + .switch-track {
  border-color: var(--focus);
  background: var(--focus);
}

.switch-field input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch-field input:disabled + .switch-track {
  opacity: 0.55;
}

.switch-field input:focus-visible + .switch-track {
  outline: 2px solid color-mix(in srgb, var(--focus) 35%, transparent);
  outline-offset: 2px;
}

.switch-label {
  color: var(--text);
}

.broker-status-line {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.broker-payload-details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.broker-payload-details summary {
  width: fit-content;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.broker-payload-details .auto-trade-payload {
  width: 100%;
  min-height: 110px;
  margin-top: 8px;
}

.guide-empty,
.guide-muted {
  color: var(--muted);
  font-size: 13px;
}

.guide-head {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.guide-chip {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 7px 9px;
}

.guide-head span,
.guide-block h4 {
  display: block;
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.guide-head strong {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
}

.guide-alert {
  margin-bottom: 8px;
  border: 1px solid #d14b4b;
  border-radius: 6px;
  background: #fff1f1;
  color: #9f1d1d;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 9px;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.guide-block {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.guide-block h4 {
  margin: 0;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
}

.guide-muted {
  margin: 0;
  padding: 10px;
}

.guide-order-head,
.guide-order-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.9fr) minmax(92px, 1.1fr) minmax(70px, 0.8fr) minmax(64px, 0.8fr);
  gap: 6px;
  align-items: center;
}

.guide-order-head {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.guide-order-list {
  display: grid;
}

.guide-order-row {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.guide-order-row:last-child {
  border-bottom: 0;
}

.guide-order-row strong {
  color: var(--text);
  font-size: 12px;
}

.guide-stage {
  color: var(--button);
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

input:focus,
select:focus {
  outline: 2px solid color-mix(in srgb, var(--focus) 25%, transparent);
  border-color: var(--focus);
}

.run-button {
  min-width: 104px;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--button);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 18px;
}

.run-button:hover {
  background: var(--button-hover);
}

.crypto-field.is-hidden {
  display: none;
}

.form-status {
  min-height: 20px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.result-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.result-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.profit-summary {
  color: var(--button);
  font-size: 13px;
  font-weight: 700;
}

.state-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.state-summary-item {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  padding: 10px 12px;
}

.state-summary-item span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.state-summary-item strong {
  display: block;
  color: var(--text);
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.summary-value-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.state-summary-item.is-completed {
  border-color: #c94a4a;
  background: #fff4f4;
}

.section-subheader {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 8px;
}

.section-subheader span {
  color: var(--muted);
  font-size: 13px;
}

.task-subheader {
  margin-top: 8px;
}

.task-guide {
  border-color: color-mix(in srgb, var(--focus) 35%, var(--line));
  background: #f8fbff;
}

.trade-input-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.trade-input-panel .db-run-panel {
  margin: 0;
  border: 0;
  background: transparent;
  padding: 0;
}

.trade-input-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.input-subheader {
  margin: 4px 0 0;
}

.history-details {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.history-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  padding: 10px 12px;
}

.history-details:not([open]) summary {
  border-bottom: 0;
}

.history-details summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.history-details .result-table-wrap {
  border: 0;
  border-radius: 0;
}

.danger-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  border: 1px solid #f0caca;
  border-radius: 8px;
  background: #fff8f8;
  padding: 12px;
}

.danger-actions h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.danger-actions span {
  color: #9f1d1d;
  font-size: 13px;
}

.inline-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.inline-filter select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 6px 28px 6px 8px;
}

.ghost-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 7px 12px;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.ghost-button:hover {
  border-color: var(--focus);
  color: var(--focus);
  background: color-mix(in srgb, var(--surface) 90%, var(--focus) 10%);
}

.run-button:disabled,
.ghost-button:disabled {
  border-color: var(--line);
  background: var(--disabled);
  color: #9aa4af;
  cursor: not-allowed;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.result-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  position: relative;
}

.result-table th:first-child,
.result-table td:first-child,
.strategy-table th:first-child,
.strategy-table td:first-child,
.round-summary-table th:first-child,
.round-summary-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 10;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
}

.result-table th:first-child {
  background: #eef4f8;
  z-index: 20;
}

body.dark-theme .result-table th:first-child {
  background: #1e293b;
}

body.dark-theme .result-table td:first-child {
  background: #1e293b;
}

.strategy-card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.strategy-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 10px 12px;
  text-align: left;
}

.strategy-card:hover {
  border-color: color-mix(in srgb, var(--focus) 45%, var(--line));
  background: #f8fbff;
}

.strategy-card.is-selected {
  border-color: var(--focus);
  background: #e8f2ff;
}

.strategy-card-main,
.strategy-card-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.strategy-card-main strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-card-main span,
.strategy-card-meta span {
  color: var(--muted);
  font-size: 12px;
}

.strategy-card-meta {
  justify-items: end;
}

.strategy-card-meta strong {
  color: var(--button);
  font-size: 13px;
}

.strategy-card-empty {
  min-height: 88px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.round-result-scroll {
  max-height: min(560px, 62vh);
  overflow: auto;
}

.strategy-result-scroll {
  max-height: min(440px, 50vh);
  overflow: auto;
}

.task-table-wrap {
  margin-bottom: 18px;
}

.round-summary-wrap {
  margin-bottom: 14px;
}

.round-summary-table {
  min-width: 860px;
}

.compact-action {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.compact-action:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.task-input {
  width: 110px;
  min-height: 32px;
  padding: 4px 6px;
  font-size: 12px;
}

.task-status-select {
  width: 82px;
  min-height: 32px;
  padding: 4px 6px;
  font-size: 12px;
}

.result-table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}

.result-table th,
.result-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  text-align: right;
  white-space: nowrap;
}

.result-table th {
  position: sticky;
  top: 0;
  background: #eef4f8;
  color: var(--muted);
  font-weight: 700;
}

.result-table th:nth-child(1),
.result-table th:nth-child(2),
.result-table th:nth-child(3),
.result-table td:nth-child(1),
.result-table td:nth-child(2),
.result-table td:nth-child(3) {
  text-align: left;
}

.result-table tbody tr:last-child td {
  border-bottom: 0;
}

.result-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.result-table tbody tr.is-selected {
  background: #e8f2ff;
}

.result-table tbody tr.is-preview {
  background: #fff8df;
  color: #6c4b00;
}

.strategy-table tbody tr[data-strategy-number] {
  cursor: pointer;
}

.strategy-table tbody tr[data-strategy-number]:hover,
.strategy-table tbody tr[data-strategy-number]:focus-visible {
  background: #e8f2ff;
  outline: 2px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: -2px;
}

.empty-row td {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.strategy-table {
  width: 100%;
  min-width: 0;
}

.strategy-table th,
.strategy-table td {
  text-align: right;
}

.strategy-table th:first-child,
.strategy-table td:first-child {
  text-align: center;
  width: 64px;
}

.yearly-results-table {
  width: 100%;
  min-width: 0;
}

.yearly-results-table th,
.yearly-results-table td {
  padding: 6px 4px;
  white-space: nowrap;
}

.yearly-results-table th:first-child,
.yearly-results-table td:first-child {
  text-align: center;
  width: auto;
}

/* ─── 위험도 배지 ─────────────────────────────────────── */
.risk-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
  line-height: 1.6;
}

.risk-none {
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 12px;
}

.risk-low {
  background: #dcfce7;
  color: #166534;
}

.risk-mid {
  background: #fef9c3;
  color: #854d0e;
}

.risk-high {
  background: #fee2e2;
  color: #991b1b;
}

.risk-cell {
  white-space: nowrap;
}

.mdd-cell {
  color: #991b1b;
}

body.dark-theme .risk-low {
  background: color-mix(in srgb, #166534 25%, #1a2a1e);
  color: #86efac;
}

body.dark-theme .risk-mid {
  background: color-mix(in srgb, #854d0e 25%, #2a221a);
  color: #fde68a;
}

body.dark-theme .risk-high {
  background: color-mix(in srgb, #991b1b 25%, #2a1a1a);
  color: #fca5a5;
}

body.dark-theme .mdd-cell {
  color: #fca5a5;
}

@media (max-width: 900px) {
  .state-summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .guide-head,
  .guide-grid {
    grid-template-columns: 1fr;
  }

  .guide-order-head {
    display: none;
  }

  .guide-order-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .broker-panel-main {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .broker-actions {
    justify-content: flex-start;
  }

  .strategy-nav,
  .strategy-card-list {
    grid-template-columns: 1fr;
  }

  .home-section-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .home-section-header span {
    text-align: left;
  }
}

@media (max-width: 560px) {
  .backtest-form {
    padding: 16px;
  }

  .form-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .csv-drop-zone {
    align-items: center;
    flex-direction: column;
    gap: 4px;
  }

  .db-run-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-row,
  .settings-controls,
  .settings-shortcut-grid {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-controls {
    min-width: 0;
  }

  .settings-shortcut-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .db-run-panel span {
    text-align: left;
  }

  .two-track-drop-grid {
    grid-template-columns: 1fr;
  }

  .state-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-subheader {
    align-items: flex-start;
    flex-direction: column;
  }

  .run-button {
    width: 100%;
  }

  .result-panel {
    padding: 16px;
  }

  .round-result-scroll {
    max-height: 420px;
  }

  .result-header {
    align-items: stretch;
    flex-direction: column;
  }

  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

/* ==========================================================================
   반자동 주문 후보 패널 (Trade Candidates Panel) V2
   ========================================================================== */
.trade-candidates-panel {
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
  transition: all 0.2s ease;
}

.trade-candidates-panel.is-disabled {
  opacity: 0.65;
  pointer-events: none;
  background-color: var(--disabled);
}

.candidates-unsupported-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}

.candidates-unsupported-message i {
  color: var(--danger);
  margin-bottom: 12px;
}

.candidates-unsupported-message h4 {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 8px 0;
  color: var(--text);
}

.candidates-unsupported-message p {
  font-size: 13px;
  margin: 0;
  line-height: 1.5;
}

/* 로딩 애니메이션 및 에러 표시 */
.candidates-loading-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--muted);
}

.candidates-loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.candidates-error-wrapper {
  background-color: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  color: #991b1b;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.candidates-error-wrapper i {
  margin-top: 2px;
  flex-shrink: 0;
}

.candidates-error-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.candidates-error-desc {
  line-height: 1.5;
}

/* 반자동 후보 목록 레이아웃 */
.candidates-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

.candidates-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.candidates-header-right {
  text-align: right;
}

.candidates-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.candidate-item-card {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 16px;
  background-color: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  position: relative;
  transition: all 0.2s ease;
}

.candidate-item-card:hover {
  border-color: var(--focus);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.08);
}

.candidate-item-card.is-expired {
  opacity: 0.55;
  background-color: var(--disabled);
  border-color: var(--line);
  box-shadow: none !important;
}

/* 체크박스 커스텀 */
.candidate-checkbox-label {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.candidate-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--muted);
  cursor: pointer;
}

/* 방향 뱃지 */
.candidate-side-badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 6px;
  text-align: center;
  min-width: 60px;
}

.candidate-side-badge.buy {
  background-color: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.candidate-side-badge.sell {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* 후보 상세 정보 */
.candidate-info-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.candidate-reason-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.candidate-price-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.candidate-price-details span strong {
  color: var(--text);
}

.candidate-qty-block {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.candidate-qty-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.candidate-qty-sub {
  font-size: 11px;
  color: var(--muted);
}

.candidate-action-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

/* 카운트다운 타이머 */
.candidate-timer-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.candidate-timer-badge.warning {
  background-color: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
  animation: pulse 1s infinite alternate;
}

.candidate-timer-badge.expired {
  background-color: var(--disabled);
  color: var(--muted);
  border: 1px solid var(--line);
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.7; }
}

/* 경고 & 하단 컨트롤 */
.candidates-footer-control {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}

.candidates-warning-banner {
  background-color: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 10px 14px;
  color: #b45309;
  font-size: 12px;
  line-height: 1.5;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 대기 조건(Pending Conditions) 스타일 */
.pending-conditions-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 20px 0 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pending-conditions-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.pending-condition-card {
  background-color: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0.8;
  font-size: 12px;
}

.pending-condition-card:hover {
  opacity: 1;
  border-color: var(--muted);
}

.pending-condition-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}

.pending-side-tag {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
}

.pending-side-tag.buy {
  background-color: #f0f9ff;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.pending-side-tag.sell {
  background-color: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
}

.pending-price-block {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
}

.pending-diff-value {
  font-weight: 600;
  font-size: 11px;
}

.pending-diff-value.buy {
  color: #2563eb;
}

.pending-diff-value.sell {
  color: #dc2626;
}

/* 현대적인 토글 스위치 스타일 */
.switch-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch-control {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch-control input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--line, #e2e8f0);
  transition: .3s;
  border-radius: 24px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.switch-control input:checked + .switch-slider {
  background-color: var(--focus, #3b82f6);
}

.switch-control input:focus + .switch-slider {
  box-shadow: 0 0 1px var(--focus, #3b82f6);
}

.switch-control input:checked + .switch-slider:before {
  transform: translateX(20px);
}

.bg-seed-add {
  background-color: rgba(59, 130, 246, 0.06) !important;
}
.text-seed-add {
  color: var(--focus, #3b82f6) !important;
  font-weight: bold;
}
