/* =================================================================
   1. Global & Reset Styles (사이트 전체 공통)
================================================================= */
* {
  box-sizing: border-box;
}

body {
  font-family: 'MabinogiClassic', 'Segoe UI', 'Noto Sans KR', sans-serif;
  background: #f9f9f9;
  color: #333;
  margin: 0;
  font-size: clamp(16px, 4.5vw, 18px);
  line-height: 1.6;
}

h1, h2 {
  color: #333;
  margin: 0;
  font-size: 1.5em;
  line-height: 1.2;
}

p {
  font-size: 0.9em;
  color: #555;
}

a {
  color: #007bff;
  text-decoration: none;
}

.item-image {
  width: 32px;
  height: 32px;
  margin-right: 10px;
  vertical-align: middle;
}

/* =================================================================
   2. Layout Components (공통 레이아웃)
================================================================= */
.navbar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2rem;
  padding: 1rem;
  background: #f8f9fa;
  border-bottom: 1px solid #ddd;
}

@media (max-width: 768px) {
  .navbar {
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .navbar .nav-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

.main-layout {
  display: flex;
  height: calc(100vh - 80px);
}

.content-area {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.footer-credit {
  padding: 20px;
  text-align: center;
  font-size: 0.9em;
  color: gray;
}

/* =================================================================
   3. Shared UI Components (공통 UI 요소)
================================================================= */
.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  color: #333;
}

.nav-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.nav-btn:hover {
  background-color: #e9ecef;
}

.nav-btn.active {
  background-color: #007bff;
  color: white;
  font-weight: bold;
}

.loading-spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.price-up { color: #d32f2f; }
.price-down { color: #1976d2; }
.price-same { color: #757575; }

/* =================================================================
   4. Page: Exchange Rate (환율 페이지 전용)
================================================================= */
.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.view-toggle-btn {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  transition: all 0.2s ease-in-out;
  flex-shrink: 0;
}

.view-toggle-btn:hover {
  border-color: #007bff;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  transform: translateY(-2px);
}

.icon-table, 
.icon-card {
  width: 20px;
  height: 20px;
  background-size: contain;
  background-repeat: no-repeat;
}

.icon-table {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='3' y1='9' x2='21' y2='9'%3E%3C/line%3E%3Cline x1='3' y1='15' x2='21' y2='15'%3E%3C/line%3E%3Cline x1='9' y1='3' x2='9' y2='21'%3E%3C/line%3E%3Cline x1='15' y1='3' x2='15' y2='21'%3E%3C/line%3E%3C/svg%3E");
}

.icon-card {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='6' rx='2'%3E%3C/rect%3E%3Crect x='3' y='14' width='18' height='6' rx='2'%3E%3C/rect%3E%3C/svg%3E");
}

.icon-card {
  display: none;
}

body.view-as-table .icon-card {
  display: block;
}

body.view-as-table .icon-table {
  display: none;
}

body.view-as-cards .icon-table {
  display: block;
}

body.view-as-cards .icon-card {
  display: none;
}

.responsive-exchange-table {
  border-collapse: collapse;
  width: 100%;
  border: 1px solid #ddd;
}

.responsive-exchange-table thead {
  display: table-header-group;
  background-color: #f2f2f2;
  font-size: 0.9em;
}

.responsive-exchange-table tr {
  display: table-row;
  background: white;
  border-bottom: 1px solid #ddd;
}

.responsive-exchange-table th, 
.responsive-exchange-table td {
  display: table-cell;
  text-align: center;
  padding: 12px 15px;
}

.responsive-exchange-table td::before {
  content: "";
  display: none;
}

@media screen and (max-width: 768px) {
  .responsive-exchange-table thead {
    display: none;
  }
  .responsive-exchange-table tr {
    display: block;
    margin-bottom: 16px;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    background: #fff;
    padding: 8px;
  }
  .responsive-exchange-table td {
    display: flex;
    justify-content: space-between;
    padding: 12px 8px;
    text-align: right;
    border: none;
    border-bottom: 1px solid #f2f2f2;
  }
  .responsive-exchange-table td:last-child {
    border-bottom: none;
  }
  .responsive-exchange-table td::before {
    content: attr(data-label);
    font-weight: bold;
    text-align: left;
    margin-right: 10px;
    color: #555;
    font-size: 0.9em;
    display: inline-block;
  }
  .responsive-exchange-table td:first-child {
    font-weight: bold;
    font-size: 1.1em;
    justify-content: center;
  }
  .responsive-exchange-table td:first-child::before {
    content: "";
    margin-right: 0;
  }
}

.responsive-exchange-table tr.best-item {
  border: 2px solid #007bff;
}

body.view-as-cards .responsive-exchange-table thead {
  display: none;
}
body.view-as-cards .responsive-exchange-table tr {
  display: block;
  margin-bottom: 15px;
  border: 1px solid #ccc;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  background: #fff;
  padding: 8px;
}
body.view-as-cards .responsive-exchange-table td {
  display: flex;
  justify-content: space-between;
  padding: 10px 15px;
  text-align: right;
  border: none;
  border-bottom: 1px solid #eee;
}
body.view-as-cards .responsive-exchange-table td:last-child {
  border-bottom: none;
}
body.view-as-cards .responsive-exchange-table td::before {
  content: attr(data-label);
  font-weight: bold;
  text-align: left;
  margin-right: 10px;
  color: #555;
  display: inline-block;
}
body.view-as-cards .responsive-exchange-table td:first-child {
  font-weight: bold;
  font-size: 1.1em;
  justify-content: center;
}
body.view-as-cards .responsive-exchange-table td:first-child::before {
  content: "";
  margin-right: 0;
}

@media screen and (max-width: 768px) {
  body.view-as-table .responsive-exchange-table thead {
    display: table-header-group;
  }
  body.view-as-table .responsive-exchange-table tr {
    display: table-row;
    margin-bottom: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  body.view-as-table .responsive-exchange-table td {
    display: table-cell;
    text-align: center;
    border: 1px solid #ddd;
  }
  body.view-as-table .responsive-exchange-table td::before {
    display: none;
  }
  body.view-as-table .responsive-exchange-table td:first-child {
    font-weight: normal;
    font-size: 1em;
  }
}

.details-row > td {
  padding: 0 !important;
}
.details-content {
  padding: 1.5rem;
  background-color: #f8f9fa;
  border-top: 2px solid #007bff;
}
.details-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
}
.details-chart-area, .details-info-area {
  min-width: 0;
}
.item-row.active-row {
  background-color: #e7f1ff;
}
.market-depth-table { width: 100%; border-collapse: collapse; }
.market-depth-table th, .market-depth-table td { padding: 8px; text-align: right; border-bottom: 1px solid #eee; }
.market-depth-table th { text-align: center; font-size: 0.9em; }

.exchange-ticker-container {
  width: 100%;
  overflow: hidden;
  background-color: #333;
  color: white;
  padding: 10px 0;
  box-sizing: border-box;
  white-space: nowrap;
  position: relative;
  font-size: 0.9em;
}
.exchange-ticker-content {
  display: inline-block;
  padding-left: 100%;
  animation: scroll-left 30s linear infinite;
}
.ticker-item {
  margin-right: 30px;
  display: inline-block;
}
@keyframes scroll-left {
  0% { transform: translateX(0%); }
  100% { transform: translateX(-100%); }
}

/* =================================================================
   5. Page: Item Charts (차트 페이지 전용)
================================================================= */
.item-list-sidebar {
  display: block; /* Always visible on desktop */
  width: 250px; /* Example width, adjust as needed */
  padding: 20px;
  box-sizing: border-box;
  overflow-y: auto;
  border-right: 1px solid #eee; /* Separator */
  background: #f4f4f4;
  border-left: 1px solid #ccc;
  flex-shrink: 0;
}
.item-list-sidebar h3 {
  margin-top: 0;
  font-size: 1.1rem;
  border-bottom: 1px solid #ccc;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}
.item-list-sidebar button {
  display: block;
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.7rem;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
  text-align: left;
  border-radius: 4px;
  font-size: 0.9rem;
  transition: background 0.2s, border-color 0.2s;
}
.item-list-sidebar button:hover {
  background: #e9ecef;
  border-color: #bbb;
}

.item-list-bottom-bar {
  display: none; /* Hidden by default */
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #f8f8f8;
  border-top: 1px solid #eee;
  padding: 10px 0;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  z-index: 1000;
  box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
}
.item-list-bottom-bar button {
  display: inline-block;
  margin: 0 5px;
  padding: 8px 15px;
  border: 1px solid #ddd;
  border-radius: 5px;
  background-color: #fff;
  cursor: pointer;
}
.item-list-bottom-bar button.active {
  background-color: #007bff;
  color: white;
  border-color: #007bff;
}

@media (max-width: 768px) {
  .item-list-sidebar {
    display: none; /* Hide sidebar on mobile */
  }
  .item-list-bottom-bar {
    display: block; /* Show bottom bar on mobile */
  }
  .main-layout {
    padding-bottom: 70px; /* Make space for the bottom bar */
  }
  .details-grid { grid-template-columns: 1fr; }
}

.range-selector {
  margin-bottom: 1.5rem;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.range-btn {
  padding: 8px 15px;
  border: 1px solid #ccc;
  background-color: #fff;
  border-radius: 20px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.range-btn:hover {
  background-color: #f0f0f0;
}
.range-btn.active {
  background-color: #007bff;
  color: white;
  border-color: #007bff;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-container {
  width: 100%;
  margin-bottom: 1.5rem;
  position: relative;
}
.chart-container canvas {
  width: 100% !important;
  height: auto;
}

.canvas-container {
  width: 90%;
  margin: 0 auto; /* Center the chart */
  max-height: 300px;
  overflow: hidden;
}
#priceChart {
  max-height: 400px;
}
#volumeChart {
  max-height: 150px;
}

#timestamp {
  margin-top: 20px;
  font-size: 0.9em;
  color: #555;
  text-align: center;
}

.quantity-cell {
  position: relative;
  text-align: right;
  padding-right: 10px;
}
.quantity-bar {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  background-color: rgba(0, 123, 255, 0.3);
  z-index: 1;
}
.quantity-cell span {
  position: relative;
  z-index: 2;
}
#key-metrics-board, .key-metrics-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  padding: 1rem;
  background-color: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  text-align: center;
}
.metric { padding: 0.5rem; }
.metric-title { font-size: 0.9rem; color: #666; margin-bottom: 0.25rem; }
.metric-value { font-size: 1.2rem; font-weight: bold; color: #333; }
.metric-value.up { color: #d32f2f; }
.metric-value.down { color: #1976d2; }

/* =================================================================
   6. Page: Common Additions (공통 추가 요소)
================================================================= */
.site-description {
  margin-bottom: 1.5rem;
  color: #555;
  font-size: 1.05rem;
}
.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
  font-size: 0.9rem;
  color: #666;
}
.footer-links {
  margin-top: 1rem;
}
.footer-links a {
  color: #555;
  text-decoration: none;
  margin: 0 10px;
}
.footer-links a:hover {
  text-decoration: underline;
}
.contact-info {
  border: 1px solid #e0e0e0;
  padding: 1.5rem;
  border-radius: 8px;
  background-color: #f9f9f9;
  display: inline-block;
}