* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, "Noto Sans KR", sans-serif;
  background: #f3f5f8;
  color: #111827;
}

.app {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

header {
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: 26px;
}

header p {
  margin: 6px 0 0;
  color: #6b7280;
  font-size: 14px;
}

.search-card,
.result-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  margin-bottom: 16px;
}

label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.search-row {
  display: flex;
  gap: 8px;
}

input {
  flex: 1;
  height: 42px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
}

button {
  width: 90px;
  border: 0;
  border-radius: 12px;
  background: #2563eb;
  color: white;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

button:active {
  transform: scale(0.98);
}

.stock-name {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

.stock-code {
  color: #6b7280;
  font-size: 14px;
  margin-bottom: 18px;
}

.price {
  font-size: 42px;
  font-weight: 900;
  margin-bottom: 6px;
}

.rate {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 18px;
}

.up {
  color: #dc2626;
}

.down {
  color: #2563eb;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.info-box {
  background: #f9fafb;
  border-radius: 14px;
  padding: 12px;
}

.info-label {
  color: #6b7280;
  font-size: 13px;
  margin-bottom: 4px;
}

.info-value {
  font-size: 18px;
  font-weight: 800;
}

.empty,
.loading,
.error {
  text-align: center;
  color: #6b7280;
  padding: 24px 0;
}

.error {
  color: #dc2626;
  font-weight: 700;
}

.watch-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  margin-bottom: 16px;
}

.watch-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.watch-title-row h2 {
  margin: 0;
  font-size: 22px;
}

#loadWatchBtn {
  width: 100px;
  height: 42px;
  font-size: 15px;
}

.watch-list {
  display: grid;
  gap: 10px;
}

.watch-item {
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
}

.watch-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.watch-name {
  font-size: 18px;
  font-weight: 800;
}

.watch-code {
  color: #6b7280;
  font-size: 13px;
  margin-top: 3px;
}

.watch-price {
  font-size: 22px;
  font-weight: 900;
}

.watch-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: #6b7280;
  font-size: 13px;
}

.watch-actions {
  display: flex;
  gap: 8px;
}

#autoRefreshBtn {
  width: 100px;
  height: 42px;
  font-size: 15px;
  background: #6b7280;
}

#autoRefreshBtn.active {
  background: #16a34a;
}

.watch-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.watch-add-row input {
  height: 42px;
  font-size: 16px;
}

#addStockBtn {
  width: 80px;
  height: 42px;
  font-size: 15px;
  background: #111827;
}

.watch-remove {
  margin-top: 10px;
  width: 100%;
  height: 34px;
  border-radius: 10px;
  background: #fee2e2;
  color: #dc2626;
  font-size: 14px;
}

.watch-remove:active {
  transform: scale(0.99);
}

.suggest-list {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.suggest-item {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.suggest-item:hover {
  background: #eef2ff;
}

.suggest-name {
  font-weight: 800;
}

.suggest-code {
  color: #6b7280;
  font-size: 13px;
}

.flash-up {
  animation: flashUp 0.8s ease;
}

.flash-down {
  animation: flashDown 0.8s ease;
}

@keyframes flashUp {
  0% {
    background: #fee2e2;
  }
  100% {
    background: #f9fafb;
  }
}

@keyframes flashDown {
  0% {
    background: #dbeafe;
  }
  100% {
    background: #f9fafb;
  }
}

.hold-card {
  background: #ffffff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  margin-bottom: 16px;
}

.hold-card h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.hold-add-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 70px;
  gap: 8px;
  margin-bottom: 14px;
}

.hold-add-row input {
  height: 42px;
  font-size: 15px;
}

#addHoldBtn {
  width: 70px;
  height: 42px;
  background: #111827;
  font-size: 14px;
}

.hold-list {
  display: grid;
  gap: 10px;
}

.hold-item {
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px;
}

.hold-top,
.hold-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.hold-name {
  font-size: 18px;
  font-weight: 800;
}

.hold-code {
  color: #6b7280;
  font-size: 13px;
  margin-top: 3px;
}

.hold-profit {
  font-size: 20px;
  font-weight: 900;
  text-align: right;
}

.hold-row {
  margin-top: 8px;
  color: #374151;
  font-size: 14px;
}

.hold-remove {
  margin-top: 10px;
  width: 100%;
  height: 34px;
  border-radius: 10px;
  background: #fee2e2;
  color: #dc2626;
  font-size: 14px;
}

@media (max-width: 480px) {
  .hold-add-row {
    grid-template-columns: 1fr 1fr;
  }

  #addHoldBtn {
    width: 100%;
  }
}

.sort-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 14px;
}

.sort-btn {
  min-width: 90px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: white;
  color: #111827;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.sort-btn.active {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

.summary-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.summary-box div {
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px;
}

.summary-box span {
  display: block;
  color: #6b7280;
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-box strong {
  font-size: 20px;
  font-weight: 900;
}

.alert-setting-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.alert-setting-row input {
  height: 42px;
  font-size: 15px;
}

#saveAlertRateBtn {
  width: 120px;
  height: 42px;
  font-size: 14px;
  background: #7c3aed;
}

.alert-box {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.alert-title {
  font-weight: 900;
  margin-bottom: 8px;
  color: #c2410c;
}

.alert-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid #fed7aa;
}

.alert-item:first-of-type {
  border-top: 0;
}

.hold-sort-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 14px;
}

.hold-sort-btn {
  min-width: 90px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: white;
  color: #111827;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.hold-sort-btn.active {
  background: #111827;
  color: white;
  border-color: #111827;
}

.hold-action-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.hold-edit,
.hold-remove {
  flex: 1;
  width: 100%;
  height: 36px;
  border-radius: 10px;
  font-size: 14px;
}

.hold-edit {
  background: #dbeafe;
  color: #1d4ed8;
}

.hold-remove {
  background: #fee2e2;
  color: #dc2626;
}

.hold-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.hold-action-row .hold-edit,
.hold-action-row .hold-remove {
  margin-top: 0;
  width: 100%;
  height: 36px;
}

.hold-rank-box {
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.hold-rank-title {
  font-weight: 900;
  margin-bottom: 8px;
}

.hold-rank-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 15px;
}

.hold-rank-row strong {
  font-weight: 900;
}

.target-hit {
  animation: targetBlink 1s infinite;
  border: 2px solid #ef4444;
}

@keyframes targetBlink {
  0% {
    box-shadow: 0 0 0 rgba(239,68,68,0);
  }

  50% {
    box-shadow: 0 0 18px rgba(239,68,68,0.7);
  }

  100% {
    box-shadow: 0 0 0 rgba(239,68,68,0);
  }
}

.trade-log-box {
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
}

.trade-log-title {
  font-weight: 900;
  margin-bottom: 10px;
}

.trade-log-item {
  background: white;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  font-size: 14px;
}

.trade-log-item strong {
  font-weight: 900;
}

.trade-log-time {
  color: #6b7280;
  font-size: 12px;
  margin-top: 4px;
}

.stop-loss-hit {
  animation: stopLossBlink 1s infinite;
  border: 2px solid #2563eb;
}

@keyframes stopLossBlink {
  0% {
    box-shadow: 0 0 0 rgba(37, 99, 235, 0);
  }

  50% {
    box-shadow: 0 0 18px rgba(37, 99, 235, 0.7);
  }

  100% {
    box-shadow: 0 0 0 rgba(37, 99, 235, 0);
  }
}

.hold-action-row {
  grid-template-columns: 1fr 1fr 1fr;
}

.hold-auto {
  width: 100%;
  height: 36px;
  border-radius: 10px;
  font-size: 14px;
  background: #e5e7eb;
  color: #374151;
}

.hold-auto.active {
  background: #16a34a;
  color: white;
}

.emergency-row {
  margin-bottom: 12px;
}

#emergencyStopBtn {
  width: 100%;
  height: 42px;
  border-radius: 12px;
  background: #dc2626;
  color: white;
  font-size: 16px;
  font-weight: 900;
}

.value-flash-up {
  animation: valueFlashUp 0.7s ease;
}

.value-flash-down {
  animation: valueFlashDown 0.7s ease;
}

@keyframes valueFlashUp {
  0% {
    background: rgba(220, 38, 38, 0.18);
    transform: scale(1.04);
  }
  100% {
    background: transparent;
    transform: scale(1);
  }
}

@keyframes valueFlashDown {
  0% {
    background: rgba(37, 99, 235, 0.18);
    transform: scale(1.04);
  }
  100% {
    background: transparent;
    transform: scale(1);
  }
}

.watch-price,
.hold-current-price,
.hold-profit-value,
.hold-profit-rate {
  display: inline-block;
  border-radius: 6px;
  padding: 1px 4px;
}

.test-mode-banner {
  display: none;
  background: #dc2626;
  color: #fff;
  font-weight: 800;
  text-align: center;
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);
}

.entry-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #dcfce7;
  color: #15803d;
  font-size: 11px;
  font-weight: 800;
}

.volume-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 3px 6px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 800;
}

@media (min-width: 1024px) {

  body {
    background: #eef2f7;
  }

  .app {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 18px;
    align-items: start;
  }

  .left-panel,
  .right-panel {
    display: grid;
    gap: 16px;
  }

  .watch-list {
    grid-template-columns: 1fr 1fr;
  }

  .hold-list {
    grid-template-columns: 1fr 1fr;
  }

  .trade-log-list {
    max-height: 500px;
    overflow-y: auto;
  }
}

@media (min-width: 1024px) {
  .app {
    max-width: 1400px;
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 18px;
    align-items: start;
  }

  .left-panel,
  .right-panel {
    display: grid;
    gap: 16px;
  }

  .watch-list {
    grid-template-columns: 1fr;
  }

  .hold-list {
    grid-template-columns: 1fr 1fr;
  }

  .trade-log-list {
    max-height: 520px;
    overflow-y: auto;
  }
}

/* 모바일 화면 압축 보정 */
@media (max-width: 768px) {
  body {
    background: #f3f5f8;
  }

  .app {
    width: 100%;
    max-width: none;
    padding: 8px;
  }

  header {
    margin-bottom: 10px;
  }

  h1 {
    font-size: 22px;
  }

  header p {
    font-size: 12px;
  }

  .search-card,
  .result-card,
  .watch-card,
  .hold-card {
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
  }

  input {
    min-width: 0;
    height: 38px;
    padding: 0 9px;
    font-size: 14px;
  }

  button {
    height: 38px;
    border-radius: 10px;
    font-size: 13px;
  }

  .search-row {
    gap: 6px;
  }

  #searchBtn {
    width: 66px;
    flex-shrink: 0;
  }

  .price {
    font-size: 34px;
  }

  .rate {
    font-size: 17px;
    margin-bottom: 10px;
  }

  .info-grid {
    gap: 6px;
  }

  .info-box {
    padding: 8px;
    border-radius: 10px;
  }

  .info-value {
    font-size: 15px;
  }

  .watch-title-row {
    display: block;
    margin-bottom: 10px;
  }

  .watch-title-row h2,
  .hold-card h2 {
    font-size: 19px;
    margin-bottom: 8px;
  }

  .watch-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }

  #loadWatchBtn,
  #autoRefreshBtn,
  #testModeBtn {
    width: 100%;
    height: 36px;
    font-size: 12px;
  }

  .sort-row,
  .hold-sort-row {
    gap: 6px;
    margin-bottom: 10px;
  }

  .sort-btn,
.hold-sort-btn {
  min-width: 58px;
  padding: 0 6px;
  height: 32px;
  font-size: 11px;
  border-radius: 8px;
}

.sort-row,
.hold-sort-row {
  overflow-x: auto;
  scrollbar-width: none;
}

.sort-row::-webkit-scrollbar,
.hold-sort-row::-webkit-scrollbar {
  display: none;
}

  .alert-setting-row,
  .entry-setting-row,
  .volume-setting-row,
  .watch-add-row {
    gap: 6px;
    margin-bottom: 8px;
  }

  #saveAlertRateBtn,
  #saveEntryRateBtn,
  #saveVolumeThresholdBtn {
    width: 92px;
    height: 38px;
    font-size: 12px;
    flex-shrink: 0;
  }

  #addStockBtn {
    width: 58px;
    height: 38px;
    font-size: 12px;
    flex-shrink: 0;
  }

  .watch-item,
  .hold-item,
  .hold-rank-box,
  .trade-log-box,
  .alert-box,
  .entry-box {
    padding: 9px;
    border-radius: 12px;
  }

  .watch-name,
  .hold-name {
    font-size: 16px;
  }

  .watch-price,
  .hold-profit {
    font-size: 18px;
  }

  .watch-bottom,
  .hold-row {
    font-size: 12px;
    gap: 6px;
  }

  .watch-remove {
    height: 30px;
    font-size: 12px;
  }

  .summary-box {
    gap: 6px;
    margin-bottom: 10px;
  }

  .summary-box div {
    padding: 9px;
    border-radius: 10px;
  }

  .summary-box strong {
    font-size: 16px;
  }

  .emergency-row {
    display: grid;
    grid-template-columns: 1fr 92px;
    gap: 6px;
  }

  #emergencyStopBtn,
  #resetHoldingsBtn {
    width: 100%;
    height: 38px;
    font-size: 12px;
  }

  .trade-time-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr 82px;
    gap: 5px;
    align-items: center;
    margin-bottom: 10px;
  }

  .trade-time-row input {
    width: 100%;
    padding: 0 4px;
    font-size: 12px;
  }

  #saveTradeTimeBtn {
    width: 82px;
    height: 38px;
    font-size: 11px;
  }

  .hold-add-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  #addHoldBtn {
    width: 100%;
    height: 38px;
    grid-column: span 2;
  }

  .hold-action-row {
    gap: 6px;
  }

  .hold-auto,
  .hold-edit,
  .hold-remove {
    height: 32px;
    font-size: 12px;
  }

  .empty,
  .loading,
  .error {
    padding: 14px 0;
    font-size: 13px;
  }
}

/* 자동매매 상태판 정리 */
.hold-strategy-panel {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.hold-strategy-title {
  font-size: 13px;
  font-weight: 900;
  color: #111827;
  margin-bottom: 8px;
}

.hold-strategy-panel .hold-row {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e5e7eb;
}

.hold-strategy-panel .hold-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.hold-auto-status.up {
  background: #dcfce7;
  color: #15803d;
  padding: 2px 8px;
  border-radius: 999px;
}

.hold-auto-status:not(.up) {
  background: #e5e7eb;
  color: #374151;
  padding: 2px 8px;
  border-radius: 999px;
}

.hold-strategy-status,
.hold-target-status,
.hold-second-target-status,
.hold-stoploss-status,
.hold-last-action-value {
  padding: 2px 8px;
  border-radius: 999px;
  background: #f3f4f6;
}

.hold-target-status.up,
.hold-second-target-status.up {
  background: #fee2e2;
  color: #dc2626;
}

.hold-stoploss-status.down {
  background: #dbeafe;
  color: #2563eb;
}

.hold-strategy-title {
  display: block !important;
  font-size: 14px !important;
  font-weight: 900 !important;
  color: #111827 !important;
  margin-bottom: 8px !important;
}