/* CSS 변수 정의 */
.babip-calculator-wrapper {
  --bg-primary: #f5f5f0;
  --bg-secondary: #fff;
  --bg-section: #fff;
  --border-color: #333;
  --text-primary: #222;
  --text-secondary: #555;
  --text-light: #666;
  --color-accent: #3498db;
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;
  --color-purple: #9b59b6;
  --shadow-sm: 2px 2px 0 rgba(0,0,0,0.1);
  --shadow-md: 4px 4px 0 rgba(0,0,0,0.15);
  --shadow-lg: 8px 8px 0 rgba(0,0,0,0.15);
}

/* 전역 box-sizing */
.babip-calculator-wrapper,
.babip-calculator-wrapper *,
.babip-calculator-wrapper *::before,
.babip-calculator-wrapper *::after {
  box-sizing: border-box;
}

/* 메인 컨테이너 */
.babip-calculator-container {
  max-width: 1180px;
  width: 100%;
  margin: 20px auto;
  padding: 20px;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  font-family: 'Noto Sans KR', 'Malgun Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  line-height: 1.5;
}

/* 헤더 */
.calculator-header {
  text-align: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 3px double var(--border-color);
}

.calculator-header h2 {
  margin: 0 0 6px 0;
  font-size: 26px;
  font-weight: 700;
  color: #2c3e50;
  text-shadow: 2px 2px 0 rgba(255,255,255,0.5);
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.4;
}

/* 빠른 액션 버튼 */
.quick-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-sample,
.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
  font-family: inherit;
}

.btn-sample:hover,
.btn-reset:hover {
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

.btn-sample:active,
.btn-reset:active {
  transform: translate(3px, 3px);
  box-shadow: none;
}

.btn-sample:focus-visible,
.btn-reset:focus-visible {
  outline: 3px solid var(--color-warning);
  outline-offset: 2px;
}

.btn-sample {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--border-color);
}

/* 광고 섹션 */
.ad-section {
  display: block;
  width: 100%;
  min-height: 100px;
  padding: 15px;
  text-align: center;
  background: #fff;
  border: 1px solid #ddd;
  overflow: visible;
  margin-bottom: 15px;
}

.ad-label {
  display: block;
  font-size: 10px;
  color: #999;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ad-section .adsbygoogle {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 90px;
  text-align: center;
}

/* 메인 그리드 */
.calculator-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 15px;
}

.input-section,
.result-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 15px;
  box-shadow: var(--shadow-md);
}

/* 섹션 타이틀 */
.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 700;
  color: #2c3e50;
  line-height: 1.2;
}

.input-section .section-title {
  color: var(--color-accent);
}

.result-section .section-title {
  color: var(--color-purple);
}

.history-section .section-title {
  color: var(--color-danger);
}

/* 입력 그룹 */
.input-group {
  margin-bottom: 10px;
}

.input-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* 입력 필드 */
.input-with-tooltip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.number-input {
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  transition: all 0.2s;
}

.number-input:focus {
  outline: none;
  background: #fffacd;
  border-color: var(--color-warning);
}

/* 툴팁 */
.tooltip {
  position: relative;
  cursor: help;
  display: inline-flex;
}

.info-icon {
  color: #6b7280;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: color 0.2s;
}

.tooltip:hover .info-icon {
  color: var(--color-accent);
}

.tooltip-text {
  visibility: hidden;
  width: 200px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 4px;
  padding: 8px;
  position: absolute;
  z-index: 100;
  bottom: 125%;
  left: 50%;
  margin-left: -100px;
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 12px;
  font-weight: normal;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  line-height: 1.4;
}

.tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}

.tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* 계산 버튼 */
.btn-calculate {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  background: var(--color-success);
  color: #fff;
  border: 1px solid var(--border-color);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
  font-family: inherit;
  margin-top: 5px;
}

.btn-calculate:hover {
  background: #229954;
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.2);
}

.btn-calculate:active {
  transform: translate(4px, 4px);
  box-shadow: none;
}

.btn-calculate:focus-visible {
  outline: 3px solid var(--color-warning);
  outline-offset: 2px;
}

/* 정보 박스 */
.info-box {
  margin-top: 12px;
  padding: 12px;
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
}

.info-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--color-success);
  font-size: 13px;
}

.info-box p {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* 결과 디스플레이 */
.result-display {
  text-align: center;
  padding: 20px;
  background: #eff6ff;
  border: 2px solid var(--color-accent);
  margin-bottom: 15px;
}

.babip-value {
  font-size: 48px;
  font-weight: 700;
  color: var(--color-accent);
  margin-bottom: 4px;
  font-family: 'Courier New', monospace;
}

.babip-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* 차트 컨테이너 */
.chart-container {
  height: 250px;
  margin-bottom: 15px;
  padding: 10px;
  background: #fff;
  border: 1px solid #ddd;
}

/* 결과 해석 */
.interpretation-section {
  padding: 12px;
  background: #f9f9f9;
  border: 1px solid #ddd;
}

.interpretation-title {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.interpretation-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.interpretation-content p {
  margin: 0 0 8px 0;
}

.interpretation-content p:last-child {
  margin-bottom: 0;
}

/* 히스토리 섹션 */
.history-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 15px;
  box-shadow: var(--shadow-md);
  margin-bottom: 15px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-header .section-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.btn-clear-history {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid var(--border-color);
  font-size: 11px;
  font-weight: 600;
  color: var(--color-danger);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  font-family: inherit;
}

.btn-clear-history:hover {
  background: #ffe6e6;
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.btn-clear-history:focus-visible {
  outline: 2px solid var(--color-warning);
  outline-offset: 2px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  padding: 30px;
  font-size: 13px;
  color: #999;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid #ddd;
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  background: #f0f0f0;
  transform: translateX(2px);
}

.history-data {
  font-size: 12px;
  color: var(--text-secondary);
}

.history-babip {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-accent);
  font-family: 'Courier New', monospace;
}

/* 푸터 노트 */
.footer-note {
  margin-top: 15px;
  padding: 15px;
  background: #f0f0f0;
  border: 2px dashed #999;
}

.footer-note p {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.footer-note ul {
  margin: 0;
  padding-left: 20px;
  list-style-type: disc;
}

.footer-note li {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
  line-height: 1.5;
}

.footer-note li:last-child {
  margin-bottom: 0;
}

/* 반응형: 태블릿 */
@media (max-width: 1024px) {
  .calculator-main {
    grid-template-columns: 1fr;
  }
}

/* 반응형: 모바일 */
@media (max-width: 768px) {
  .babip-calculator-container {
    margin: 10px 5px;
    padding: 10px;
    width: calc(100% - 10px);
    max-width: 100%;
  }
  
  .calculator-header h2 {
    font-size: 22px;
  }
  
  .subtitle {
    font-size: 12px;
  }
  
  .quick-actions {
    flex-direction: column;
  }
  
  .btn-sample,
  .btn-reset {
    width: 100%;
    justify-content: center;
  }
  
  .chart-container {
    height: 200px;
  }
  
  .babip-value {
    font-size: 40px;
  }
}

/* 반응형: 작은 모바일 */
@media (max-width: 480px) {
  .babip-calculator-container {
    margin: 10px 5px;
    padding: 10px;
    width: calc(100% - 10px);
    max-width: 100%;
    border-width: 1px;
  }
  
  .calculator-header h2 {
    font-size: 20px;
  }
  
  .babip-value {
    font-size: 36px;
  }
  
  .chart-container {
    height: 180px;
  }
  
  .tooltip-text {
    width: 150px;
    margin-left: -75px;
    font-size: 11px;
  }
}

/* Emergency mobile overflow clamp: 2026-06-02 */
@media (max-width: 480px) {
  .babip-calculator-wrapper .tooltip-text {
    left: auto;
    right: 0;
    margin-left: 0;
    max-width: calc(100vw - 48px);
  }

  .babip-calculator-wrapper .tooltip-text::after {
    left: auto;
    right: 8px;
    margin-left: 0;
  }
}
