* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #f5f7fb;
  color: #111827;
  font-family: Arial, "Malgun Gothic", "맑은 고딕", sans-serif;
  font-size: 13px;
}

body { overflow: hidden; }

.app {
  display: flex;
  gap: 12px;
  height: 100vh;
  padding: 12px;
}

.panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .05);
}

.sidebar {
  width: 56%;
  min-width: 0;
  padding: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.main {
  width: 44%;
  min-width: 0;
  overflow-y: auto;
  padding: 14px;
}

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

.hidden { display: none !important; }
.muted { color: #6b7280; font-size: 12px; }

.head-row,
.detail-head,
.section-head,
.table-head,
.detail-title-row,
.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.head-row { margin-bottom: 12px; }
.sub { margin-top: 4px; color: #6b7280; font-size: 12px; line-height: 1.5; }

.back-btn,
.ghost-btn,
.primary-btn,
.help-btn {
  border: none;
  border-radius: 9px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
}

.back-btn, .ghost-btn, .help-btn { background: #e5e7eb; color: #111827; }
.primary-btn { background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; }

.help-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
}

.help-box {
  border: 1px solid #dbeafe;
  background: #f8fbff;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 12px;
  line-height: 1.6;
}

.help-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1.5fr 0.8fr 0.8fr 0.8fr;
  gap: 8px;
  margin-bottom: 8px;
}

.filter-grid label,
.toggle-row,
.summary-cards {
  width: 100%;
}
.filter-grid label { display: flex; flex-direction: column; gap: 5px; }
.filter-grid span { font-size: 11px; color: #6b7280; }

input, select {
  border: 1px solid #d1d5db;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
}

.toggle-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}

.check-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.summary-card {
  border: 1px solid #e5e7eb;
  border-radius: 11px;
  padding: 10px;
  background: #fafafa;
}

.summary-card.good { background: #f0fdf4; border-color: #bbf7d0; }
.summary-card .label { font-size: 11px; color: #6b7280; margin-bottom: 4px; }
.summary-card .value { font-size: 18px; font-weight: 800; }
.summary-card .value.small { font-size: 12px; line-height: 1.4; }

.table-head { margin-bottom: 8px; }

.table-wrap {
  border: 1px solid #e5e7eb;
  border-radius: 11px;
  overflow: auto;
  min-height: 0;
}

.scan-table, .info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.scan-table th, .scan-table td,
.info-table th, .info-table td {
  border-bottom: 1px solid #eef2f7;
  padding: 7px 8px;
  white-space: nowrap;
  text-align: left;
}

.scan-table thead th,
.info-table thead th {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 1;
  cursor: pointer;
}

.scan-table tbody tr { cursor: pointer; }
.scan-table tbody tr:hover { background: #f3f7ff; }
.scan-table tbody tr.active { background: #eaf2ff; }


.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

#scanTable td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 종목 리스트 컬럼 폭 조정 */
#scanTable th:nth-child(1), #scanTable td:nth-child(1) { width: 55px; }   /* 종목코드 */
#scanTable th:nth-child(2), #scanTable td:nth-child(2) { width: 100px; }  /* 종목명 */
#scanTable th:nth-child(3), #scanTable td:nth-child(3) { width: 70px; }   /* 시장 */
#scanTable th:nth-child(4), #scanTable td:nth-child(4) { width: 50px; }   /* 등급 */
#scanTable th:nth-child(5), #scanTable td:nth-child(5) { width: 50px; }   /* 점수 */
#scanTable th:nth-child(6), #scanTable td:nth-child(6) { width: 62px; }   /* 코드33 */
#scanTable th:nth-child(7), #scanTable td:nth-child(7) { width: 58px; }   /* EPS */
#scanTable th:nth-child(8), #scanTable td:nth-child(8) { width: 98px; }  /* 최신분기 */
#scanTable th:nth-child(9), #scanTable td:nth-child(9) { width: 60px; }   /* 매출 YoY */
#scanTable th:nth-child(10), #scanTable td:nth-child(10) { width: 60px; } /* 영업익 YoY */
#scanTable th:nth-child(11), #scanTable td:nth-child(11) { width: 60px; } /* 마진 YoY */
#scanTable th:nth-child(12), #scanTable td:nth-child(12) { width: 60px; } /* EPS YoY */
#scanTable th:nth-child(13), #scanTable td:nth-child(13) { width: 40px; } /* RS */
#scanTable th:nth-child(14), #scanTable td:nth-child(14) { width: 62px; } /* RS등급 */


.detail-sub { margin-top: 6px; color: #4b5563; font-size: 12px; line-height: 1.5; }
.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 24px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  padding: 0 9px;
}

.badge.pass { background: #dcfce7; color: #166534; }
.badge.fail { background: #fee2e2; color: #b91c1c; }
.badge.a { background: #dbeafe; color: #1d4ed8; }
.badge.b { background: #fef3c7; color: #92400e; }
.badge.c { background: #f3f4f6; color: #4b5563; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.metric-card {
  border: 1px solid #e5e7eb;
  border-radius: 11px;
  padding: 10px;
  background: #fff;
}

.metric-card .label { font-size: 11px; color: #6b7280; margin-bottom: 4px; }
.metric-card .value { font-size: 16px; font-weight: 800; }
.metric-card .desc { margin-top: 4px; font-size: 11px; color: #6b7280; }

.section { margin-top: 12px; }

.panel-inner {
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}

.rule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

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

.rule-box {
  border: 1px solid #e5e7eb;
  border-radius: 11px;
  padding: 12px;
  background: #fafafa;
}

.rule-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.7;
  font-size: 12px;
}

.arrow {
  color: #9ca3af;
  font-weight: 700;
}

.chart-box {
  width: 100%;
  height: 320px;
  margin-top: 8px;
}

.detail-table-wrap {
  margin-top: 8px;
  max-height: 280px;
}

.empty-state {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 20px;
  color: #64748b;
  background: #f8fafc;
  font-size: 12px;
}

.summary-sections {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.summary-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-title {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
}

.summary-cards-3 {
  grid-template-columns: repeat(3, 1fr);
}

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

.filter-grid-4 {
  grid-template-columns: 1.5fr 0.8fr 0.8fr 1fr;
}

.filter-grid-5 {
  grid-template-columns: 1.5fr 0.8fr 0.8fr 0.8fr 1fr;
}

.summary-cards-4 {
  grid-template-columns: repeat(4, 1fr);
}

.text-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rs-cell {
  text-align: right;
  font-family: monospace;
}

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

.summary-card.bad {
  background: #fff7f7;
  border-color: #fecaca;
}

.help-list {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.7;
  font-size: 12px;
}

.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}
.modal-card {
  position: relative;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 60px);
  overflow: auto;
  margin: 30px auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  padding: 18px 20px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-close {
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  padding: 8px 12px;
}
.material-meta {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 10px;
}
.material-content {
  font-size: 13px;
  line-height: 1.7;
}
.material-empty {
  padding: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  color: #64748b;
}
.material-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}
.material-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.material-item-body {
  line-height: 1.7;
  color: #374151;
}

.with-help {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.mini-help-btn {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.help-section-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px;
  background: #fafafa;
}

.help-section-card h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.help-section-card p {
  font-size: 12px;
  line-height: 1.7;
  color: #374151;
}

.help-pill-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.help-pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 11px;
  font-weight: 700;
}

.help-main-desc {
  margin-bottom: 10px;
  font-size: 12px;
  line-height: 1.7;
  color: #374151;
}

.help-tip-box {
  margin-top: 10px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.7;
  color: #7c2d12;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.help-table th,
.help-table td {
  border: 1px solid #e5e7eb;
  padding: 6px 8px;
  text-align: center;
}

.help-table th {
  background: #f3f4f6;
  font-weight: 700;
}

.help-table td:first-child {
  font-weight: 600;
  text-align: left;
}

.update-text {
  font-size: 11px;
  color: #9ca3af;
  font-weight: 400;
  margin-left: 6px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rs-btn.active {
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}

.rs-btn.active.rs-a {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #93c5fd;
}

.rs-btn.active.rs-b {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}

.head-actions .ghost-btn,
.head-actions .back-btn {
  white-space: nowrap;
}

.mini-link {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}

.mini-link:hover {
  border-color: #cbd5e1;
  color: #111827;
  text-decoration: none;
}

@media (max-width: 768px) {
  .head-row {
    align-items: flex-start;
  }

  .head-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

.plus { color: #dc2626; font-weight: 700; }   /* 플러스 빨강 */
.minus { color: #2563eb; font-weight: 700; }  /* 마이너스 파랑 */
.neutral { color: #374151; }

.sort-indicator { margin-left: 3px; font-size: 10px; color: #6b7280; }

@media (max-width: 1450px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1180px) {
  body { overflow: auto; }
  .app { height: auto; flex-direction: column; }
  .sidebar, .main { width: 100%; }
  .main { overflow: visible; }
  .filter-grid,
  .summary-cards,
  .metric-grid,
  .rule-grid {
    grid-template-columns: 1fr;
  }
}

.pwa-nav {
  display: none;
  position: sticky;
  top: 0;
  z-index: 1000;
  gap: 8px;
  padding: 8px 12px;
  background: #0b1220;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.pwa-nav button {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: #1f2a44;
  color: #fff;
  cursor: pointer;
}

/* Adsense/content friendly additions - copied to match normal case3612 layout */
html, body { overflow-x: hidden !important; overflow-y: auto !important; height: auto !important; min-height: 100% !important; }
.adsense-content { background:#0f172a; color:#e5e7eb; padding:24px 16px; }
.adsense-inner { max-width:1180px; margin:0 auto; background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.12); border-radius:18px; padding:24px; box-shadow:0 16px 36px rgba(15,23,42,.16); }
.adsense-inner h2 { margin:0 0 10px; color:#fff; font-size:26px; }
.adsense-inner p { color:#cbd5e1; line-height:1.75; }
.content-label { color:#93c5fd !important; font-weight:800; font-size:13px; letter-spacing:.08em; text-transform:uppercase; margin:0 0 8px; }
.guide-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:14px; margin-top:18px; }
.guide-grid article { background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.1); border-radius:14px; padding:16px; }
.guide-grid h3 { margin:0 0 8px; color:#fff; font-size:17px; }
.ad-slot-inline { min-height:90px; border:1px dashed rgba(255,255,255,.22); border-radius:14px; margin-top:18px; display:flex; align-items:center; justify-content:center; color:#64748b; }
.legal-footer { background:#0f172a; color:#94a3b8; text-align:center; padding:24px 16px 40px; }
.legal-footer a { color:#cbd5e1; margin:0 8px; text-decoration:none; }
@media(max-width:900px){ .guide-grid{grid-template-columns:1fr}.adsense-inner{padding:18px}.adsense-inner h2{font-size:22px} }


/* ===============================
   MarketBrief 동일 차트 팝업
================================ */
.detail-stock-chart-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: #0f172a;
  padding: 0;
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.04em;
  cursor: pointer;
}
.detail-stock-chart-btn:hover {
  color: #2563eb;
  text-decoration: underline;
}
body.chart-modal-open {
  overflow: hidden;
}

.chart-modal.hidden {
  display: none !important;
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
}

.chart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.50);
}

.chart-modal-card {
  position: relative;
  z-index: 1;
  width: min(1380px, calc(100vw - 28px));
  height: min(920px, calc(100vh - 28px));
  margin: 14px auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.30);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 16px 18px 10px;
  border-bottom: 1px solid #e5e7eb;
}

.chart-modal-head h3 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.chart-modal-meta {
  color: #475569;
  font-size: 13px;
  line-height: 1.75;
}

.chart-modal-controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chart-modal-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chart-modal-controls label span {
  color: #64748b;
  font-size: 12px;
}

.chart-modal-controls select {
  width: 92px;
  padding: 10px 12px;
}

.chart-modal-controls input {
  width: 110px;
  padding: 10px 12px;
}

.chart-modal-controls button {
  width: auto;
  height: 42px;
  padding: 10px 13px;
  border-radius: 10px;
}

#btnChartReload {
  background: linear-gradient(135deg, #0f172a, #1d4ed8) !important;
  color: #fff !important;
  border: 0 !important;
  font-weight: 900 !important;
}

.chart-modal-close {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  padding: 0 !important;
  background: #fff !important;
  color: #111827 !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 10px !important;
  font-size: 22px !important;
  font-weight: 500 !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.chart-modal-note {
  padding: 10px 18px 0;
  color: #64748b;
  font-size: 12px;
}

.chart-popup {
  width: 100%;
  flex: 1;
  min-height: 0;
}

.break {
  color: #16a34a;
  font-weight: 900;
}

.fail {
  color: #dc2626;
  font-weight: 900;
}

@media (max-width: 900px) {
  .chart-modal-card {
    height: calc(100vh - 16px);
    width: calc(100vw - 16px);
    margin: 8px auto;
  }

  .chart-modal-head {
    flex-direction: column;
  }

  .chart-popup {
    min-height: 660px;
  }

  .detail-stock-chart-btn {
    font-size: 20px;
  }
}

/* =========================================================
   Mobile chart modal scroll fix - same as marketbrief
========================================================= */
@media (max-width: 900px) {
  .chart-modal {
    overflow: hidden !important;
    touch-action: none;
  }

  .chart-modal-card {
    width: calc(100vw - 10px) !important;
    height: calc(100dvh - 10px) !important;
    max-width: none !important;
    max-height: none !important;
    margin: 5px auto !important;
    border-radius: 14px !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
    display: block !important;
  }

  .chart-modal-head,
  .chart-modal-note,
  .chart-popup {
    min-width: 1040px !important;
  }

  .chart-modal-head {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #fff;
    flex-direction: row !important;
    align-items: flex-start !important;
  }

  .chart-modal-controls {
    width: auto !important;
    justify-content: flex-end !important;
    flex-wrap: nowrap !important;
  }

  .chart-modal-note {
    padding: 8px 16px 0 !important;
    white-space: nowrap;
  }

  .chart-popup {
    width: 1040px !important;
    height: 760px !important;
    min-height: 760px !important;
    flex: 0 0 auto !important;
  }
}

@media (max-width: 520px) {
  .chart-modal-head,
  .chart-modal-note,
  .chart-popup {
    min-width: 980px !important;
  }

  .chart-popup {
    width: 980px !important;
    height: 740px !important;
    min-height: 740px !important;
  }

  .chart-modal-head h3 {
    font-size: 20px !important;
  }

  .chart-modal-meta {
    font-size: 12px !important;
  }

  .chart-modal-controls select,
  .chart-modal-controls input,
  .chart-modal-controls button {
    height: 38px !important;
    padding: 8px 10px !important;
  }

  .chart-modal-close {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    padding: 0 !important;
  }
}
