:root {
  --bg-page: #f4f6f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;

  --text-main: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  --brand-navy: #0f172a;
  --primary: #1e40af;
  --primary-hover: #1e3a8a;
  --primary-light: #eff6ff;

  /* 한국 증권 표준: 매수 = 적색, 매도 = 청색 */
  --buy-color: #dc2626;
  --buy-bg: #fef2f2;
  --buy-border: #fecaca;

  --sell-color: #2563eb;
  --sell-bg: #eff6ff;
  --sell-border: #bfdbfe;

  /* 자산군 컬러 */
  --risk-color: #d97706;
  --risk-bg: #fffbeb;
  --risk-border: #fde68a;

  --safe-color: #059669;
  --safe-bg: #ecfdf5;
  --safe-border: #a7f3d0;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.05);
  --max-width: 1200px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Header */
.site-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--brand-navy);
  text-decoration: none !important;
  letter-spacing: -0.02em;
}

.brand-divider {
  width: 1px;
  height: 14px;
  background: var(--border-strong);
}

.brand-sub {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.main-nav a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s;
}

.main-nav a:hover {
  color: var(--primary);
}

/* Layout */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem;
}

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 310px;
  gap: 1.5rem;
  align-items: start;
}

.main-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-column {
  position: sticky;
  top: 4.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Page Title Banner */
.hero-card {
  background: var(--brand-navy);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.75rem 2rem;
  margin-bottom: 1.25rem;
  border: 1px solid #1e293b;
}

.hero-eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.45rem;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  color: #cbd5e1;
  font-size: 0.92rem;
  max-width: 760px;
  line-height: 1.55;
}

/* AdSense Slots (Clean, Non-Intrusive) */
.ad-slot-wrap {
  margin: 0.25rem 0;
  text-align: center;
  overflow: hidden;
  min-height: 0;
}

ins.adsbygoogle[data-ad-status="unfilled"] {
  display: none !important;
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border-color);
}

.section-step {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 0.15rem;
}

.card-title {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.015em;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Status Metrics */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.05rem 1.2rem;
}

.stat-box.stat-risk {
  border-top: 3px solid var(--risk-color);
}

.stat-box.stat-safe {
  border-top: 3px solid var(--safe-color);
}

.stat-box.stat-total {
  border-top: 3px solid var(--brand-navy);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  font-variant-numeric: tabular-nums;
}

/* Ratio Gauge Bar */
.ratio-bar-wrapper {
  margin: 1.35rem 0 1.15rem;
}

.ratio-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.ratio-track {
  height: 22px;
  background: var(--safe-color);
  border-radius: 6px;
  position: relative;
  display: flex;
}

.ratio-fill-risk {
  height: 100%;
  background: var(--risk-color);
  border-radius: 6px 0 0 6px;
  transition: width 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.73rem;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
}

.ratio-fill-risk.over-limit {
  background: var(--buy-color);
}

.limit-marker-70 {
  position: absolute;
  left: 70%;
  top: -5px;
  bottom: -5px;
  width: 2px;
  background: var(--brand-navy);
  z-index: 5;
}

.limit-marker-label {
  position: absolute;
  left: 70%;
  top: -23px;
  transform: translateX(-50%);
  background: var(--brand-navy);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
}

/* Diagnostic Notice */
.rule-alert {
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rule-alert.status-ok {
  background: #f8fafc;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--safe-color);
  color: var(--text-main);
}

.rule-alert.status-warn {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 4px solid var(--buy-color);
  color: #7f1d1d;
}

.rule-alert-title {
  font-weight: 700;
  font-size: 0.94rem;
}

.rule-helper-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  font-size: 0.83rem;
  font-variant-numeric: tabular-nums;
}

/* Target Ratio Config */
.target-config-bar {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.15rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.target-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.preset-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 0.38rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.preset-btn.active {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #fff;
}

.custom-ratio-inputs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-sm {
  width: 64px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.48rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text-secondary);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--text-secondary);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

.btn-danger-ghost:hover {
  color: var(--buy-color);
  background: var(--buy-bg);
}

/* KRX Item Search Box */
.krx-search-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
}

.krx-sync-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.krx-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.krx-search-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.krx-search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.krx-search-input {
  width: 100%;
  padding: 0.58rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: inherit;
  background: #fff;
}

.krx-search-input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.krx-filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.krx-filter-chip {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.krx-filter-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.krx-filter-chip.active {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #ffffff;
}

.krx-results-panel {
  margin-top: 0.65rem;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow-y: auto;
}

.krx-result-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s;
}

.krx-result-item:last-child {
  border-bottom: none;
}

.krx-result-item:hover {
  background: var(--bg-subtle);
}

.krx-item-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.krx-item-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 0.1rem 0.38rem;
  border-radius: 4px;
}

.krx-item-price {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* Holdings & Result Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.holdings-table th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  text-align: left;
  padding: 0.65rem 0.6rem;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.holdings-table td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.holdings-table tr:hover {
  background-color: #fafbfc;
}

.input-text,
.input-num,
.select-type {
  width: 100%;
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-family: inherit;
  background: #fff;
  color: var(--text-main);
}

.input-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.input-text:focus,
.input-num:focus,
.select-type:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Badges */
.badge-type {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.18rem 0.48rem;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-risk {
  background: var(--risk-bg);
  color: var(--risk-color);
  border: 1px solid var(--risk-border);
}

.badge-safe {
  background: var(--safe-bg);
  color: var(--safe-color);
  border: 1px solid var(--safe-border);
}

.badge-cash {
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

/* Weight Summary */
.weight-summary-bar {
  margin-top: 0.9rem;
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.84rem;
}

.weight-warn {
  color: var(--buy-color);
  font-weight: 600;
}

.weight-ok {
  color: var(--safe-color);
  font-weight: 600;
}

/* Action Pills */
.action-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.76rem;
}

.action-buy {
  background: var(--buy-bg);
  color: var(--buy-color);
  border: 1px solid var(--buy-border);
}

.action-sell {
  background: var(--sell-bg);
  color: var(--sell-color);
  border: 1px solid var(--sell-border);
}

.action-hold {
  background: var(--bg-muted);
  color: var(--text-muted);
}

.amount-buy {
  color: var(--buy-color);
  font-weight: 700;
}

.amount-sell {
  color: var(--sell-color);
  font-weight: 700;
}

.execution-steps {
  margin-top: 1.25rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--brand-navy);
  border-radius: var(--radius-sm);
  padding: 1rem 1.2rem;
}

.execution-steps h4 {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.execution-steps ol {
  padding-left: 1.2rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Editorial / Guide Content */
.guide-article h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-main);
  letter-spacing: -0.015em;
}

.guide-article h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 1.25rem;
  margin-bottom: 0.45rem;
  color: var(--text-main);
}

.guide-article p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.7rem;
}

.guide-article ul {
  padding-left: 1.2rem;
  color: var(--text-secondary);
  font-size: 0.88rem;
  margin-bottom: 0.8rem;
}

.guide-article li {
  margin-bottom: 0.35rem;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.15rem;
  background: var(--bg-subtle);
}

.faq-q {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}

.faq-a {
  font-size: 0.86rem;
  color: var(--text-secondary);
}

/* Sidebar */
.sidebar-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  box-shadow: var(--shadow-sm);
}

.sidebar-card h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.sidebar-list {
  list-style: none;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--bg-muted);
  padding-bottom: 0.4rem;
}

.sidebar-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

/* Footer */
.site-footer {
  background: var(--brand-navy);
  color: #94a3b8;
  margin-top: 3rem;
  padding: 2.25rem 1.5rem;
  font-size: 0.82rem;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.footer-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid #1e293b;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.footer-links a {
  color: #e2e8f0;
  font-weight: 500;
  text-decoration: none;
}

.footer-links a:hover {
  color: #ffffff;
  text-decoration: underline;
}

.footer-disclaimer {
  color: #64748b;
  font-size: 0.78rem;
  line-height: 1.55;
}

/* Responsive */
@media (max-width: 1024px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-column {
    position: static;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.8rem 1rem;
    gap: 0.55rem;
  }

  .main-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    gap: 1rem;
    white-space: nowrap;
  }

  .hero-card {
    padding: 1.25rem;
  }

  .hero-title {
    font-size: 1.25rem;
  }

  .status-grid {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .rule-helper-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 1.1rem;
  }

  .holdings-table thead {
    display: none;
  }

  .holdings-table,
  .holdings-table tbody,
  .holdings-table tr,
  .holdings-table td {
    display: block;
    width: 100%;
  }

  .holdings-table tr {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--bg-surface);
  }

  .holdings-table td {
    border-bottom: 1px solid var(--bg-muted);
    padding: 0.45rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }

  .holdings-table td:last-child {
    border-bottom: none;
  }

  .holdings-table td::before {
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
  }

  .holdings-table td .input-text,
  .holdings-table td .input-num,
  .holdings-table td .select-type {
    max-width: 210px;
  }
}
