:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #657080;
  --line: #dce2e8;
  --accent: #147d73;
  --accent-strong: #0e5f58;
  --danger: #c3423f;
  --warn: #b7791f;
  --good: #16803c;
  --blue: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", Arial, sans-serif;
}

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

.app {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  max-width: 1280px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.2;
}

.input-panel,
.decision-card,
.metric-card,
.robot-cockpit article,
.timing-grid article,
.chart-panel,
.table-panel,
.paper-panel article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

.input-panel {
  padding: 18px;
  margin-bottom: 16px;
}

.robot-cockpit {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.robot-cockpit article {
  padding: 14px;
}

.robot-cockpit strong {
  display: block;
  margin-bottom: 4px;
  font-size: 20px;
}

.robot-cockpit span {
  color: var(--muted);
  font-size: 12px;
}

.strategy-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.strategy-panel article {
  padding: 14px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.strategy-panel strong {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
}

.strategy-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.scanner-panel,
.telegram-panel,
.nextday-panel,
.kodex-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.scanner-panel {
  grid-template-columns: 1fr 160px;
  align-items: center;
}

.nextday-panel {
  grid-template-columns: 1fr 280px;
  align-items: center;
}

.kodex-panel {
  grid-template-columns: 1fr 160px;
  align-items: center;
}

.kodex-result-panel {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.kodex-result-panel article {
  padding: 14px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kodex-result-panel strong {
  display: block;
  margin-bottom: 4px;
  font-size: 22px;
}

.kodex-result-panel span {
  color: var(--muted);
  font-size: 13px;
}

.scanner-actions {
  display: grid;
  gap: 8px;
}

.nextday-actions {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  align-items: end;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.check-label input {
  width: 16px;
  height: 16px;
}

.scanner-panel h3 {
  margin-bottom: 4px;
  font-size: 18px;
}

.scanner-panel p,
.kodex-panel p,
.nextday-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.telegram-panel {
  grid-template-columns: 1fr 220px 240px;
  align-items: end;
}

.watchlist-panel {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.three-percent-panel {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 14px;
  margin-bottom: 14px;
}

.stock-row {
  grid-template-columns: 1fr 220px;
}

.holding-row {
  grid-template-columns: 1fr 1fr 160px;
  align-items: end;
  margin-top: 14px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 156px;
  padding: 12px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.file-label {
  margin-top: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 125, 115, 0.14);
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.primary-button {
  min-width: 118px;
  height: 42px;
  color: white;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  min-width: 166px;
  height: 42px;
  color: var(--ink);
  background: #edf1f4;
}

.secondary-button:hover {
  background: #dde5eb;
}

.ghost-button {
  height: 38px;
  padding: 0 14px;
  color: var(--accent-strong);
  background: #e6f2ef;
}

.stock-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--accent-strong);
  background: #e6f2ef;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.link-button:hover {
  background: #d6ebe6;
}

.status {
  color: var(--muted);
  font-size: 13px;
}

.results-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.holding-panel {
  display: grid;
  grid-template-columns: 2fr 1fr 1.5fr;
  gap: 14px;
  margin-bottom: 14px;
}

.paper-panel {
  display: grid;
  grid-template-columns: 1.5fr 1.2fr 1.3fr;
  gap: 14px;
  margin-bottom: 14px;
}

.decision-card,
.metric-card,
.holding-panel article,
.paper-panel article {
  padding: 18px;
}

.holding-panel article,
.paper-panel article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.05);
}

.holding-panel h3,
.paper-panel h3 {
  margin-bottom: 8px;
  font-size: 22px;
}

.holding-panel p:last-child,
.holding-panel span,
.paper-panel p:last-child {
  color: var(--muted);
  line-height: 1.55;
}

.holding-panel strong {
  display: block;
  margin-bottom: 8px;
  font-size: 24px;
}

.card-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.decision-card h2 {
  margin-bottom: 8px;
  font-size: 26px;
}

.decision-card p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.metric-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 24px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.timing-grid article {
  padding: 18px;
}

.timing-grid h3,
.chart-panel h3,
.table-panel h3 {
  margin-bottom: 12px;
  font-size: 17px;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

li {
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: var(--ink);
  line-height: 1.45;
}

li:first-child {
  border-top: 0;
  padding-top: 0;
}

.signal,
.badge {
  display: inline-block;
  min-width: 46px;
  margin-right: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  color: white;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.buy {
  background: var(--good);
}

.sell {
  background: var(--danger);
}

.wait {
  background: var(--warn);
}

.strong {
  background: #6f2dbd;
}

.decision-card h2.buy,
.decision-card h2.sell,
.decision-card h2.wait,
.holding-panel strong.buy,
.holding-panel strong.sell {
  display: block;
  padding: 0;
  color: inherit;
  background: transparent;
}

.decision-card h2.buy,
.holding-panel strong.buy {
  color: var(--good);
}

.decision-card h2.sell,
.holding-panel strong.sell {
  color: var(--danger);
}

.buy-text {
  color: var(--good);
  font-weight: 800;
}

.sell-text {
  color: var(--danger);
  font-weight: 800;
}

.decision-card h2.wait {
  color: var(--warn);
}

.helper-text {
  margin-top: -6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.paper-controls {
  display: grid;
  grid-template-columns: 1fr 82px 82px;
  gap: 8px;
}

.paper-controls .secondary-button,
.paper-controls .ghost-button {
  min-width: 0;
  height: 42px;
}

.paper-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.paper-stats strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.chart-panel,
.table-panel {
  padding: 18px;
  margin-bottom: 14px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 20px;
  height: 3px;
  border-radius: 999px;
}

.legend .price {
  background: var(--ink);
}

.legend .ma20 {
  background: var(--blue);
}

.legend .ma60 {
  background: var(--accent);
}

canvas {
  width: 100%;
  height: 360px;
  display: block;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 11px 10px;
  border-top: 1px solid var(--line);
  text-align: right;
  font-size: 13px;
  white-space: nowrap;
}

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

th {
  color: var(--muted);
  font-weight: 800;
}

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

  .topbar,
  .actions,
  .chart-header,
  .scanner-panel,
  .telegram-panel,
  .kodex-panel,
  .nextday-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .field-row,
  .robot-cockpit,
  .strategy-panel,
  .scanner-panel,
  .kodex-panel,
  .kodex-result-panel,
  .nextday-panel,
  .nextday-actions,
  .telegram-panel,
  .results-grid,
  .timing-grid,
  .holding-panel,
  .paper-panel {
    grid-template-columns: 1fr;
  }

  .stock-tools {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }
}

/* 다중 사용자 인증 & 관심종목 관리 CSS 추가 */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(22, 32, 42, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.auth-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.auth-box h2 {
  margin-bottom: 6px;
  font-size: 24px;
  color: var(--ink);
}

.auth-subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-box label {
  text-align: left;
  margin-bottom: 16px;
}

.auth-box input {
  margin-top: 4px;
}

.auth-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.auth-actions button {
  width: 100%;
  height: 44px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: bold;
  margin-top: 14px;
  min-height: 20px;
}

.workspace.hidden {
  display: none !important;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.user-meta strong {
  color: var(--ink);
  font-weight: 700;
}

/* 모달 오버레이 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(22, 32, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.close-btn {
  background: transparent;
  border: 0;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0;
}

.close-btn:hover {
  color: var(--ink);
}

.modal-body {
  padding: 20px;
}

.add-stock-form {
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.add-stock-form button {
  height: 42px;
}

.watchlist-list-wrap {
  max-height: 240px;
  overflow-y: auto;
}

.section-label {
  font-size: 12px;
  font-weight: bold;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.watchlist-items-list {
  padding: 0;
  margin: 0;
}

.watchlist-items-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.watchlist-items-list li:first-child {
  border-top: none;
}

.delete-stock-btn {
  background: #ffebeb;
  color: var(--danger);
  border: 0;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
}

.delete-stock-btn:hover {
  background: #ffd6d6;
}

