:root {
  color-scheme: light dark;
  --bg: #fbfcfb;
  --sidebar: #f7faf9;
  --surface: #ffffff;
  --surface-soft: #f6faf8;
  --surface-tint: #e9f6f2;
  --text: #0f1720;
  --muted: #6d7672;
  --soft-text: #8c9692;
  --line: #dde5e1;
  --line-soft: #edf2ef;
  --accent: #00856f;
  --accent-dark: #006f5e;
  --accent-soft: #dff3ee;
  --blue-soft: #e8f0ff;
  --blue: #3867d6;
  --danger: #f23b55;
  --shadow: 0 18px 38px rgba(15, 23, 32, 0.04);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101514;
  --sidebar: #121a18;
  --surface: #17201d;
  --surface-soft: #1d2925;
  --surface-tint: #17332e;
  --text: #edf4f1;
  --muted: #a4b0ab;
  --soft-text: #83918b;
  --line: #2b3935;
  --line-soft: #22302c;
  --accent: #48d7bf;
  --accent-dark: #72ead6;
  --accent-soft: #123b35;
  --blue-soft: #17243f;
  --blue: #92afff;
  --danger: #ff8394;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans KR", Arial, sans-serif;
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 28px 12px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 0 14px 26px;
  color: var(--accent-dark);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.2;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--accent);
  border-radius: 3px;
  position: relative;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  border-top: 2px solid var(--accent);
  transform: skew(-32deg) translateY(0);
}

.brand-mark::before {
  top: 19px;
}

.brand-mark::after {
  top: 11px;
}

.tabs {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  text-align: left;
}

.tab.is-active {
  background: linear-gradient(90deg, var(--accent-soft), rgba(223, 243, 238, 0.42));
  color: var(--accent-dark);
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  color: inherit;
  font-size: 20px;
}

.sidebar-note {
  margin-top: auto;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent-soft), rgba(255, 255, 255, 0.6));
  padding: 18px 14px;
  color: var(--text);
}

.sidebar-note strong,
.sidebar-note span,
.sidebar-note small {
  display: block;
}

.sidebar-note span {
  margin-top: 14px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.7;
}

.sidebar-note small {
  margin-top: 28px;
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  border-bottom: 1px solid var(--line);
  padding: 18px 24px 18px 32px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.topbar-meta {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 3px 18px;
  text-align: right;
}

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

.topbar-meta strong {
  color: var(--accent);
  font-size: 16px;
}

.refresh-button {
  grid-row: 1 / span 2;
  grid-column: 2;
  height: 44px;
  border: 1px solid rgba(0, 133, 111, 0.48);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-dark);
  padding: 0 18px;
  font-weight: 800;
}

.market-switch {
  display: inline-flex;
  gap: 4px;
  margin: 18px 24px 0 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 4px;
}

.market-tab {
  min-width: 72px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.market-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

main {
  padding: 22px 24px 36px 32px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 28px;
  margin-bottom: 22px;
}

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

.metric-card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  min-height: 116px;
  padding: 18px 20px;
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card span {
  color: var(--text);
  font-weight: 800;
}

.metric-card strong {
  display: inline-block;
  margin-top: 8px;
  font-size: 32px;
  line-height: 1;
}

.metric-card small {
  margin-top: 10px;
}

.metric-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--surface-tint);
  position: relative;
}

.trend-icon::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 29px;
  width: 27px;
  height: 18px;
  border-top: 3px solid var(--accent);
  border-right: 3px solid var(--accent);
  transform: skew(-36deg) rotate(-12deg);
}

.sync-icon::before {
  content: "";
  position: absolute;
  inset: 13px;
  border: 3px solid var(--accent);
  border-left-color: transparent;
  border-right-color: transparent;
  border-radius: 50%;
}

.home-stack {
  display: grid;
  gap: 16px;
}

.home-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  min-width: 0;
}

.home-lower-grid > * {
  min-width: 0;
}

.panel {
  padding: 16px;
}

.full-panel {
  max-width: 1240px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.section-head h2 span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.text-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.head-meta,
.head-meta-inline {
  color: var(--muted);
  font-size: 12px;
}

.head-meta {
  display: grid;
  gap: 2px;
  text-align: right;
}

.head-meta strong {
  color: var(--text);
}

.top-signal-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(210px, 1fr));
  gap: 12px;
}

.top-signal-card,
.journal-item,
.detail-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.top-signal-card {
  min-height: 178px;
  padding: 16px;
}

.status-badge,
.event-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  border-radius: 5px;
  padding: 0 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
}

.badge-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.elite-badge,
.elite20-badge,
.champion-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  border-radius: 5px;
  padding: 0 8px;
  margin-left: 6px;
  background: #fff1cc;
  color: #936100;
  font-size: 11px;
  font-weight: 900;
}

.elite20-badge {
  background: #e7efff;
  color: #2557b8;
}

.champion-badge {
  background: #d9f1e9;
  color: #00735f;
}

.badge-row .elite-badge,
.badge-row .elite20-badge,
.badge-row .champion-badge,
.closed-row .elite-badge,
.closed-row .elite20-badge,
.closed-row .champion-badge {
  margin-left: 0;
}

.status-up {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-strong {
  background: #d9f1e9;
  color: #00735f;
}

.status-early {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-watch {
  background: var(--surface-soft);
  color: var(--muted);
}

.status-down {
  background: #ffe8ec;
  color: var(--danger);
}

.top-signal-card .stock-name {
  margin-top: 16px;
  font-size: 20px;
}

.stock-name {
  color: var(--text);
  font-weight: 900;
  letter-spacing: 0;
}

.stock-code,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.stock-code,
.stock-meta {
  display: block;
  margin-top: 3px;
  line-height: 1.35;
  text-decoration: none;
  box-shadow: none;
  background: transparent;
  transform: none;
}

.stock-cell {
  line-height: 1.35;
}

.stock-cell strong {
  display: block;
  line-height: 1.35;
}

.stock-stack {
  display: inline-grid;
  gap: 4px;
  align-items: start;
  min-width: 64px;
  padding: 2px 6px 2px 0;
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--surface);
  isolation: isolate;
  position: relative;
  z-index: 1;
}

.mini-metrics {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  font-size: 12px;
}

.mini-line,
.detail-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.price,
.score {
  color: var(--accent-dark);
  font-weight: 900;
}

.return-pos {
  color: var(--accent-dark);
}

.return-neg {
  color: var(--danger);
}

.toolbar,
.segmented {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.segmented.mini {
  gap: 18px;
}

.chip {
  height: 30px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
}

.chip.is-active {
  border: 1px solid rgba(0, 133, 111, 0.42);
  background: rgba(223, 243, 238, 0.62);
  color: var(--accent-dark);
}

.search-box {
  display: flex;
  align-items: center;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.search-box span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 0 12px;
}

.scan-search,
.detail-search {
  width: min(360px, 100%);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

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

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.row-index {
  color: var(--muted);
  text-align: right;
  width: 34px;
}

.detail-column {
  min-height: 0;
}

.journal-list {
  display: grid;
  gap: 12px;
}

.journal-item {
  position: relative;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  padding: 12px;
}

.journal-time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}

.journal-body {
  min-width: 0;
}

.journal-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.journal-body .stock-name {
  margin-top: 10px;
}

.journal-body .detail-line {
  margin-top: 8px;
}

.event-closed {
  background: #ffe8ec;
  color: var(--danger);
}

.guide-panel {
  padding: 24px;
}

.guide-intro {
  max-width: 760px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
}

.guide-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  margin-top: 22px;
}

.guide-list div {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 12px;
  min-height: 46px;
  border-top: 1px solid var(--line-soft);
  padding-top: 12px;
}

.guide-list strong {
  color: var(--accent-dark);
}

.guide-list span {
  color: var(--muted);
  line-height: 1.55;
}

.guide-disclaimer {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  color: var(--muted);
  font-weight: 800;
}

.journal-date-group {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.journal-date-title {
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 900;
}

.journal-event-section {
  display: grid;
  gap: 10px;
}

.journal-event-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
}

.journal-table-wrap {
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

.journal-table {
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
}

.journal-table th,
.journal-table td {
  border-bottom: 0;
}

.journal-table tbody tr + tr td {
  border-top: 6px solid var(--surface);
}

.journal-table td.stock-cell {
  display: table-cell;
  padding-top: 12px;
  padding-bottom: 12px;
  vertical-align: middle;
  white-space: normal;
}

.journal-table td.stock-cell .stock-code {
  margin-top: 0;
  color: #4f5b56;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
  background: var(--surface);
  background-image: none;
}

.journal-table td.stock-cell .stock-meta {
  margin-top: 0;
  background-image: none;
}

.closed-list {
  display: grid;
  gap: 8px;
}

.closed-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(260px, 1.6fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px 12px;
}

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

.detail-result {
  margin-top: 18px;
}

.detail-card {
  padding: 12px;
}

.detail-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.detail-title .stock-name {
  font-size: 18px;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  margin-top: 10px;
}

.detail-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.detail-line {
  padding: 4px 0;
  color: var(--muted);
  font-size: 12px;
}

.detail-line strong {
  color: var(--text);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.data-warning {
  margin-top: 10px;
  border: 1px solid rgba(242, 59, 85, 0.35);
  border-radius: 6px;
  padding: 9px 10px;
  background: rgba(242, 59, 85, 0.08);
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 90px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 1024px) {
  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 10px 12px;
  }

  td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line-soft);
    padding: 8px 0;
    text-align: right;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-align: left;
  }

  td.row-index {
    display: none;
  }

  td.stock-cell {
    align-items: flex-start;
    text-align: left;
  }

  td.stock-cell::before {
    display: none;
  }

  td:last-child {
    border-bottom: 0;
  }

  .journal-table {
    min-width: 0;
  }

  .journal-table-wrap {
    border: 0;
    overflow: visible;
  }

  .closed-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .guide-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding-bottom: 10px;
  }

  .tabs {
    display: flex;
    overflow-x: auto;
    margin-top: 8px;
  }

  .tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 118px;
  }

  .sidebar-note {
    display: none;
  }

  .topbar {
    display: grid;
    gap: 14px;
    min-height: 0;
    padding: 18px 16px;
  }

  .topbar-meta {
    text-align: left;
    grid-template-columns: 1fr auto;
  }

  .market-switch {
    display: flex;
    width: calc(100% - 32px);
    margin: 14px 16px 0;
  }

  .market-tab {
    flex: 1;
  }

  main {
    padding: 16px;
  }

  .metric-grid,
  .home-lower-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-column {
    min-height: 0;
  }

  .top-signal-row {
    grid-template-columns: 1fr;
  }

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

  .guide-panel {
    padding: 18px 16px;
  }

  .guide-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
