/* ==========================================================================
   Pages — 블로그 공통 스타일시트 (1080px 단일 프레임워크 & 다크모드)
   ========================================================================== */

:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --card-bg: #fafafa;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --code-bg: #f1f5f9;
  --th-bg: #f1f5f9;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --highlight: #f8fafc;
  --up: #dc2626;
  --down: #2563eb;
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1a1a1a;
  --card-bg: #1a1a1a;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #262626;
  --code-bg: #1e2430;
  --th-bg: #1f2530;
  --accent: #60a5fa;
  --accent-bg: #1e293b;
  --highlight: #1e293b;
  --up: #f87171;
  --down: #60a5fa;
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

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

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  letter-spacing: -0.01em;
  padding: 2.25rem 1.25rem 6rem;
  max-width: 1080px;
  margin: 0 auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  word-break: keep-all;
}

@media (max-width: 640px) {
  body {
    padding: 1.25rem 0.85rem 4rem;
    font-size: 15px;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   Header
   ========================================================================== */

header {
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.25rem;
  position: relative;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-heading {
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  display: inline-flex;
}

.site-title {
  display: inline-flex;
  align-items: center;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--text);
  transition: color 0.15s ease;
}

.site-title:hover {
  color: var(--accent);
}

@media (max-width: 640px) {
  .site-title {
    font-size: 1.4rem;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background-color: var(--card-bg);
}

.icon-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background-color: var(--accent-bg);
}

/* Theme Toggle Icons */
.sun-icon, .sun { display: none; }
.moon-icon, .moon { display: block; }
[data-theme="dark"] .sun-icon, [data-theme="dark"] .sun { display: block; }
[data-theme="dark"] .moon-icon, [data-theme="dark"] .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sun-icon, :root:not([data-theme="light"]) .sun { display: block; }
  :root:not([data-theme="light"]) .moon-icon, :root:not([data-theme="light"]) .moon { display: none; }
}

/* Floating Circular Back Button Widget */
.floating-back-btn {
  position: fixed;
  bottom: 2.25rem;
  left: 2.25rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  z-index: 1000;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

.floating-back-btn:hover {
  transform: scale(1.1);
  background: var(--highlight);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.floating-back-btn:active {
  transform: scale(0.95);
}

@media (max-width: 640px) {
  .floating-back-btn {
    bottom: 1.25rem;
    left: 1.25rem;
    width: 42px;
    height: 42px;
  }
}

/* ==========================================================================
   Main Index: Search, Categories, Cards Grid
   ========================================================================== */

/* Main Search Box */
.search-box {
  margin-bottom: 1.5rem;
}

.search-box.hidden {
  display: none;
}

.search-box .search-input {
  width: 100%;
  padding: 0.8rem 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-box .search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Category Filter Bar */
.category-bar {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1.75rem;
}

.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
}

.cat-pill:hover {
  color: var(--text);
  border-color: var(--accent);
}

.cat-pill.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.cat-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.725rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--text-muted);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.cat-pill.active .cat-count {
  background: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

/* Main Post List - 2-Column Responsive Grid on 1080px */
#post-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 1.25rem;
}

@media (max-width: 640px) {
  #post-list {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

.post-card {
  padding: 1.5rem;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.post-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.05);
}

.post-card.pinned {
  border-color: rgba(234, 88, 12, 0.38);
}

.post-card.pinned:hover {
  border-color: #ea580c;
  box-shadow: 0 6px 18px rgba(234, 88, 12, 0.08);
}

.post-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.post-card-badges {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.pin-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #ea580c;
  background: rgba(234, 88, 12, 0.1);
  border: 1px solid rgba(234, 88, 12, 0.25);
  border-radius: 5px;
  padding: 0;
  line-height: 1;
}

.pin-badge .pin-icon {
  display: block;
  flex-shrink: 0;
}

[data-theme="dark"] .pin-badge {
  color: #fb923c;
  background: rgba(251, 146, 60, 0.12);
  border-color: rgba(251, 146, 60, 0.3);
}

.category-badge {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: -0.01em;
}

.post-date {
  font-size: 0.825rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.post-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.4;
  letter-spacing: -0.02em;
  color: var(--text);
}

.post-excerpt {
  color: var(--text-muted);
  font-size: 0.925rem;
  line-height: 1.6;
  flex-grow: 1;
}

.no-results {
  text-align: center;
  padding: 3rem 0;
  color: var(--text-muted);
  display: none;
  grid-column: 1 / -1;
  font-size: 0.95rem;
}

/* ==========================================================================
   Article Detail & Markdown Content Typography
   ========================================================================== */

.post-meta-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.5rem 0 1.75rem;
  font-variant-numeric: tabular-nums;
}

#content h1 {
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1.35;
  margin: 1.25rem 0 0.5rem;
  letter-spacing: -0.025em;
  color: var(--text);
  overflow-wrap: break-word;
  word-break: keep-all;
}

@media (max-width: 640px) {
  #content h1 {
    font-size: 1.4rem;
    line-height: 1.35;
    word-break: break-word;
  }
}

#content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 2.2rem 0 0.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  letter-spacing: -0.02em;
}

#content h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 1.6rem 0 0.6rem;
  letter-spacing: -0.015em;
}

#content p {
  margin-bottom: 1.2rem;
  line-height: 1.75;
}

#content ul, #content ol {
  margin: 0 0 1.2rem 1.5rem;
}

#content li {
  margin-bottom: 0.35rem;
}

#content blockquote {
  border-left: 4px solid var(--accent);
  padding: 0.65rem 1rem;
  background: var(--card-bg);
  border-radius: 0 8px 8px 0;
  margin: 0.75rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

#content blockquote p {
  margin-bottom: 0;
}

#content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

#content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.25rem 0;
}

#content pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.875rem;
  line-height: 1.5;
}

#content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5rem auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

#content em {
  display: block;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: -0.75rem;
  margin-bottom: 1.5rem;
  font-style: normal;
}

#content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ==========================================================================
   Markdown Tables & Native Accordion Details (100% Full-Width & Proportional)
   ========================================================================== */

/* Explicit Column Alignments */
#content th[align="center"], #content td[align="center"] {
  text-align: center !important;
}
#content th[align="right"], #content td[align="right"] {
  text-align: right !important;
}
#content th[align="left"], #content td[align="left"] {
  text-align: left !important;
}

.table-box {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  -webkit-overflow-scrolling: touch;
  margin: 1.25rem 0;
}

#content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

#content th {
  background: var(--th-bg);
  color: var(--text);
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  letter-spacing: -0.01em;
}

#content td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* 일반 마크다운 표 가로 스크롤 및 텍스트 줄바꿈 보장 */
#content table:not(#mainTable):not(.sheet-table) {
  min-width: 520px;
}
#content table:not(#mainTable):not(.sheet-table) th,
#content table:not(#mainTable):not(.sheet-table) td {
  white-space: normal;
}

#content tr:hover {
  background: var(--highlight);
}


/* ==========================================================================
   ATP Dashboard & Interactive Data Table (Inline Collapsible Rows)
   ========================================================================== */

.atp-dashboard {
  width: 100%;
  line-height: 1.5;
}

/* Charts Grid (6.2 : 3.8 ratio on desktop) */
.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 6.2fr) minmax(0, 3.8fr);
  gap: 14px;
  margin-bottom: 18px;
  align-items: stretch;
  width: 100%;
}

.charts-grid .chart-box {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.charts-grid .chart-box .chart-canvas-wrapper {
  margin-top: auto;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 900px) {
  .charts-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Chart Box */
.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px 12px 16px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  min-width: 0;
  max-width: 100%;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 28px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

#content .chart-header h2,
.chart-header h2 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.chart-tab-group {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.chart-tab {
  background: transparent;
  border: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 3px 9px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  line-height: 1.4;
}

.chart-tab:hover {
  color: var(--text);
}

.chart-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

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

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.chart-canvas-wrapper {
  position: relative;
  height: 260px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.chart-canvas-wrapper canvas {
  max-width: 100% !important;
}

@media (max-width: 640px) {
  .chart-canvas-wrapper {
    height: 210px;
  }
}

/* Table Controls */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.controls .search-input {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 260px;
  max-width: 100%;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
}

.controls .search-input:focus {
  border-color: var(--accent);
}

.btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  background: var(--highlight);
  border-color: var(--accent);
}

/* Data Table Box */
table#mainTable, table.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

table#mainTable {
  min-width: 820px;
}

table.sheet-table {
  min-width: 880px;
}

table#mainTable th, table.sheet-table th {
  background: var(--th-bg);
  color: var(--text);
  font-weight: 700;
  padding: 11px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  letter-spacing: -0.01em;
  user-select: none;
}

table#mainTable td, table.sheet-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text);
  line-height: 1.45;
}

tr.main-row, tr.sheet-main-row, table.sheet-table tr {
  transition: background 0.1s ease;
}

tr.main-row, tr.sheet-main-row {
  cursor: pointer;
}

tr.main-row:hover, tr.sheet-main-row:hover, table.sheet-table tbody tr:hover {
  background: var(--highlight);
}

tr.main-row.active, tr.sheet-main-row.active {
  background: var(--highlight);
}

tr.sheet-sub-row td {
  background: var(--bg);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

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

/* Sub-table (Accordion under row) */
tr.sub-row {
  display: none;
}

tr.sub-row.open {
  display: table-row;
}

tr.sub-row td {
  padding: 0 !important;
  background: var(--bg);
  white-space: normal !important;
}

.sub-box {
  padding: 14px 18px 16px 18px;
  border-top: 1px solid var(--border);
  border-bottom: 2px solid var(--border);
  width: 100%;
  box-sizing: border-box;
}

.sub-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

table.inner-table {
  width: 100%;
  table-layout: fixed;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  border-collapse: collapse;
  font-size: 12px;
}

table.inner-table th {
  background: var(--th-bg);
  font-size: 11px;
  font-weight: 700;
  padding: 7px 10px;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}

table.inner-table td {
  font-size: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

table.inner-table td:nth-child(2) strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

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

table.inner-table tr:hover {
  background: var(--highlight);
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
  margin-top: 4.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-link {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}

.footer-link:hover {
  color: var(--accent);
}

.footer-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: -2.5px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease, transform 0.15s ease;
  margin-left: 0.35rem;
}

.footer-icon-link:hover {
  color: var(--accent);
  transform: translateY(-1px);
}
