* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: #f5f7fb;
  color: #111827;
  font-family: Arial, "Malgun Gothic", "맑은 고딕", sans-serif;
}

.app {
  display: flex;
  gap: 16px;
  padding: 14px;
  min-height: 100vh;
  overflow: visible;
}

.sidebar {
  width: 470px;
  min-width: 470px;
  height: calc(100vh - 28px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}

.main {
  flex: 1;
  min-width: 0;
  height: calc(100vh - 28px);
  overflow-y: auto;
  padding-right: 4px;
}

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

h1, h2 { margin: 0; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0 12px;
}

.toolbar.single { justify-content: flex-start; }

.toolbar-title {
  font-size: 15px;
  font-weight: 700;
  color: #374151;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-row.compact { grid-template-columns: 1fr 1fr; }

#selectedDt {
  width: 100%;
  min-width: 0;
}

.filter-row label,
.chart-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-row label span,
.chart-controls label span {
  font-size: 12px;
  color: #6b7280;
}

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

button { cursor: pointer; }

.help-open-btn,
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  border: none;
}

.help-open-btn {
  width: 28px;
  height: 28px;
  font-weight: 700;
  padding: 0;
}

.stats-wrap { margin-bottom: 10px; }

.stats-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.stats-head {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 14px;
}

.stats-body {
  font-size: 12px;
  line-height: 1.7;
}

.stats-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.stats-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 10px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

.list-wrap { max-height: 500px; }

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

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

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

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

.col-pattern { width: 110px; }
.col-code    { width: 66px; }
.col-name    { width: 170px; }
.col-market  { width: 80px; }

.td-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pattern-badges {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.pattern-badge {
  display: inline-flex;
  min-width: 26px;
  height: 18px;
  border-radius: 999px;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 10px;
  color: #fff;
  padding: 0 5px;
  line-height: 1;
}

.pattern-p1 { background: #3b82f6; }
.pattern-p2 { background: #f59e0b; }
.pattern-p3 { background: #16a34a; }

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 8px;
  padding: 6px 0 10px;
  background: #fff;
  border-bottom: 1px solid #eef2f7;
}

.subinfo {
  margin-top: 6px;
  font-size: 12px;
  color: #4b5563;
  line-height: 1.75;
}

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

.legend-note {
  position: sticky;
  top: 86px;
  z-index: 19;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 8px;
  padding: 6px 0 8px;
  background: #fff;
}

#chart {
  width: 100%;
  height: 660px;
}

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

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

.bottom-sections {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-panel { padding: 14px 16px; }

.sub-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sub-panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.fin-tabs { display: flex; gap: 8px; }

.fin-tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
}

.fin-tab.active {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
  font-weight: 700;
}

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

.info-table th,
.info-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-table thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
}

.pos { color: #dc2626; font-weight: 700; }
.neg { color: #2563eb; font-weight: 700; }
.neutral { color: #6b7280; }

#monthTitle {
  font-size: 16px;
  font-weight: 700;
}

#calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.cal-head, .cal-cell {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  min-height: 54px;
  background: #fff;
  padding: 6px;
}

.cal-head {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  background: #f9fafb;
}

.cal-cell.blank {
  background: transparent;
  border-color: transparent;
}

.cal-cell.selected {
  border-color: #2563eb;
  box-shadow: inset 0 0 0 1px #2563eb;
}

.cal-day {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.cal-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-line {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
}

.legend {
  margin-top: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: #4b5563;
}

.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 999px;
}

.dot-p1 { background: #3b82f6; }
.dot-p2 { background: #f59e0b; }
.dot-p3 { background: #16a34a; }
.dot-total { background: #6b7280; }

.modal.hidden { display: none; }

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

.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 - 48px);
  overflow: auto;
  margin: 24px auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.material-modal-card {
  width: min(920px, calc(100vw - 32px));
}

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

.modal-body {
  padding: 18px;
  color: #374151;
  line-height: 1.7;
  font-size: 14px;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.help-list {
  padding-left: 18px;
}

.material-meta {
  margin-bottom: 12px;
  color: #6b7280;
}

.material-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.material-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  background: #fafafa;
}

.material-line {
  font-size: 13px;
  line-height: 1.6;
  margin-top: 4px;
}

.material-time {
  color: #6b7280;
}

@media screen and (max-width: 1200px) {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    position: static !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body {
    display: block !important;
  }

  .app {
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    padding: 10px !important;
  }

  .sidebar,
  .main {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding-right: 0 !important;
  }

  .panel,
  .bottom-sections,
  .sub-panel {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  .table-wrap,
  .list-wrap,
  .table-wrap.no-scroll {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
  }

  .top-bar,
  .legend-note {
    position: static !important;
    top: auto !important;
  }

  #chart {
    width: 100% !important;
    height: 500px !important;
    touch-action: pan-y !important;
  }

  #chart canvas {
    pointer-events: none !important;
  }
}

#chart,
#chart * {
  touch-action: pan-y !important;
}

@media screen and (max-width: 1200px) {
  #chart {
    touch-action: pan-y !important;
  }

  #chart canvas {
    pointer-events: none !important;
  }
}

.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} }
