/* =========================================================
   AI Duck Tools — app.css
   미니멀 유틸리티 UI / 라이트·다크 토글
   ========================================================= */

/* ---- 디자인 토큰 ---- */
:root {
  --bg: #FBFBFD;
  --surface: #FFFFFF;
  --surface-2: #F4F5F7;
  --ink: #16161A;
  --ink-muted: #6A6A75;
  --border: #E7E7EC;
  --accent: #0F9488;
  --accent-ink: #0B6B62;
  --accent-soft: rgba(15, 148, 136, 0.10);
  --danger: #D64545;
  --danger-soft: rgba(214, 69, 69, 0.10);
  --shadow: 0 1px 2px rgba(16, 16, 24, 0.04), 0 8px 24px rgba(16, 16, 24, 0.05);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, 'Liberation Mono', monospace;

  --topbar-h: 56px;
  --sidebar-w: 280px;
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #0D0E11;
  --surface: #16171B;
  --surface-2: #1E1F24;
  --ink: #ECECEF;
  --ink-muted: #9A9AA6;
  --border: #282A31;
  --accent: #2DD4BF;
  --accent-ink: #5EEAD4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ---- 리셋 ---- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---- 상단바 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 9px; }

/* 즐겨찾기 / 홈 화면 추가 버튼 */
.fav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: border-color .12s, background .12s;
}
.fav-btn:hover { border-color: var(--accent); }
.fav-btn__icon { color: var(--accent); font-size: 14px; line-height: 1; }
@media (max-width: 560px) {
  .fav-btn__label { display: none; }
  .fav-btn { padding: 6px 9px; }
}

/* 공용 토스트 (즐겨찾기 안내 등) */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  max-width: min(90vw, 420px);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .18s, transform .18s;
  z-index: 60;
  pointer-events: none;
}
.app-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.brand-mark { color: var(--accent); font-size: 15px; line-height: 1; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.theme-toggle {
  width: 40px; height: 32px;
  display: inline-grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
  font-size: 15px;
  transition: background .15s, border-color .15s;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle__icon--moon { display: none; }
[data-theme="dark"] .theme-toggle__icon--sun { display: none; }
[data-theme="dark"] .theme-toggle__icon--moon { display: inline; }

/* ---- 레이아웃 ---- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  align-items: start;
}

/* ---- 사이드바 ---- */
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 14px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
/* 모바일 드롭다운 토글 (데스크톱에서는 숨김) */
.sidebar__toggle { display: none; }

/* 카테고리 그룹 */
.nav-group + .nav-group { margin-top: 14px; }
/* 라벨: 사이드바 폭 전체를 채우는 컬러 바 (카테고리별 색) */
.nav-group__label {
  display: block;
  margin: 0 -14px 6px;
  padding: 5px 14px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  background: var(--cat-color, var(--accent));
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-ink); }
/* 활성 항목 좌측 액센트 바 */
.nav-item.is-active::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--accent);
}
/* 인덱스 키: 모노 배지 */
.nav-item__key {
  flex: none;
  min-width: 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 0;
  transition: color .12s, background .12s, border-color .12s;
}
.nav-item:hover .nav-item__key { color: var(--ink); }
.nav-item.is-active .nav-item__key {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
[data-theme="dark"] .nav-item.is-active .nav-item__key { color: #06251f; }
.nav-item__name { font-size: 14px; font-weight: 500; }
.nav-item.is-active .nav-item__name { font-weight: 600; }

/* 사이드바 하단 광고 (데스크톱 전용) */
.sidebar-ad {
  margin-top: auto;
  padding-top: 22px;
  text-align: center;
}
.sidebar-ad .ad-slot__label { margin-bottom: 8px; }

/* ---- 메인 ---- */
.main {
  min-width: 0;
  padding: 32px clamp(20px, 4vw, 48px);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--topbar-h));
}
.workbench { max-width: 860px; width: 100%; }

/* ---- 도구 헤더 ---- */
.tool-head { margin-bottom: 24px; }
.tool-head h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.tool-head p { color: var(--ink-muted); margin-top: 6px; font-size: 14px; }

/* ---- 카드/패널 ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 18px; }

/* ---- 폼 요소 ---- */
.field { display: block; }
.field + .field { margin-top: 14px; }
.field__label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 6px;
}
.input {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea.input { resize: vertical; min-height: 160px; line-height: 1.6; }
textarea.input.mono { font-family: var(--font-mono); font-size: 13px; }

/* ---- 버튼 ---- */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
[data-theme="dark"] .btn--primary { color: #06251f; }
.btn--primary:hover { filter: brightness(1.05); }

/* ---- 통계 타일 (글자수 세기 등) ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat__num {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.stat__label { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.stat { min-width: 0; }
.stat__num { overflow-wrap: anywhere; }
/* 모바일에서는 결과 카드를 한 줄에 하나씩 (좁은 폭 글자 넘침 방지) */
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
}

/* ---- 세그먼트 컨트롤 (날짜 계산기) ---- */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 20px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.segmented button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

/* ---- 메시지 ---- */
.msg {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
  font-family: var(--font-mono);
}
.msg--error { background: var(--danger-soft); color: var(--danger); }
.msg--ok { background: var(--accent-soft); color: var(--accent-ink); }
.msg:empty { display: none; }

/* ---- 결과값 강조 (날짜 계산 결과) ---- */
.result-big {
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent-ink);
}
.result-sub { color: var(--ink-muted); font-size: 14px; margin-top: 4px; }

/* ---- 안내 문구 (예: 브라우저 저장 고지) ---- */
.dc-note {
  margin-top: 18px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 12px;
  line-height: 1.5;
}
.dc-saved { margin-bottom: 14px; }

/* ---- 이미지 크기 변환 ---- */
.img-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 140px;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.img-drop:hover, .img-drop.is-drag { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.img-info {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-top: 16px;
  display: grid;
  gap: 6px;
}
.img-info__row { display: flex; justify-content: space-between; gap: 16px; font-size: 14px; }
.img-info__k { color: var(--ink-muted); flex: none; }
.img-info__v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; word-break: break-all; }
.img-preview { margin-top: 16px; text-align: center; }
.img-preview img {
  max-width: 100%;
  max-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%, transparent 75%, var(--surface-2) 75%) 0 0/16px 16px,
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%, transparent 75%, var(--surface-2) 75%) 8px 8px/16px 16px;
}

/* ---- 이미지 출력 포맷 버튼 ---- */
.fmt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.fmt-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.fmt-btn:hover:not(.is-disabled) { border-color: var(--accent); }
.fmt-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.fmt-btn__name { font-size: 14px; font-weight: 600; color: var(--ink); }
.fmt-btn.is-active .fmt-btn__name { color: var(--accent-ink); }
.fmt-btn__desc { font-size: 12px; color: var(--ink-muted); }
.fmt-btn.is-disabled { opacity: .5; cursor: not-allowed; }

/* ---- JSON ↔ XML 2단 ---- */
.jx-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.jx-pane { display: flex; flex-direction: column; min-width: 0; }
.jx-pane .field__label { margin-bottom: 6px; }
.jx-pane textarea.input { min-height: 320px; }
@media (max-width: 700px) { .jx-panes { grid-template-columns: 1fr; } }

/* ---- 금융 계산기 표 ---- */
.fc-table-wrap { overflow-x: auto; margin-top: 16px; }
.fin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.fin-table th, .fin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.fin-table th { color: var(--ink-muted); font-weight: 500; font-size: 12px; }
.fin-table th:first-child, .fin-table td:first-child { text-align: left; }
.fin-table td { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.fin-table tbody tr:last-child td { border-bottom: 0; }

/* ---- 이모지 검색 ---- */
.emoji-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.emoji-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s, border-color .12s;
}
.emoji-chip:hover { border-color: var(--accent); color: var(--ink); }
.emoji-chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.emoji-count { color: var(--ink-muted); font-size: 12px; margin-top: 16px; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.emoji-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .1s, transform .05s, background .1s;
}
.emoji-btn:hover { border-color: var(--accent); background: var(--surface-2); }
.emoji-btn:active { transform: scale(0.94); }
.emoji-btn__char { font-size: 30px; line-height: 1; }
.emoji-btn__name {
  font-size: 11px;
  color: var(--ink-muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.emoji-empty { color: var(--ink-muted); font-size: 14px; padding: 24px 0; text-align: center; }
.emoji-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .18s, transform .18s;
  z-index: 50;
  pointer-events: none;
}
.emoji-toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- 광고 슬롯 (절제) ---- */
.ad-slot {
  max-width: 860px;
  width: 100%;
  margin: 32px 0 8px;
}
.ad-slot__label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  opacity: 0.6;
  margin-bottom: 6px;
}
.ad-slot__placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 28px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 13px;
  background: var(--surface-2);
}
/* 광고 반응형 노출: 폭이 넉넉할 때만 728x90, 그 외엔 300x50 */
.ad-desktop, .ad-mobile { text-align: center; overflow: hidden; }
.ad-desktop { display: none; }
.ad-mobile { display: block; }
@media (min-width: 1080px) {
  .ad-desktop { display: block; }
  .ad-mobile { display: none; }
}

/* ---- 홈 (도구 그리드) ---- */
.home-hero { margin-bottom: 28px; }
.home-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.home-hero p { color: var(--ink-muted); margin-top: 10px; font-size: 15px; }
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.tool-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color .12s, transform .1s, box-shadow .12s;
}
.tool-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.tool-card__key {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}
.tool-card__name { font-weight: 600; font-size: 16px; margin-top: 8px; }
.tool-card__desc { color: var(--ink-muted); font-size: 13px; margin-top: 4px; }

/* ---- 푸터 ---- */
.footer {
  margin-top: auto;
  padding-top: 32px;
  color: var(--ink-muted);
  font-size: 12px;
}

/* ---- 반응형: 모바일에서 사이드바를 가로 스크롤 바로 ---- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: var(--topbar-h);
    height: auto;
    overflow: visible; /* 절대배치 드롭다운이 잘리지 않도록 (기본 overflow:auto 해제) */
    z-index: 18;
    display: block;
    padding: 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }

  /* 토글 버튼 (현재 도구명 + 화살표) */
  .sidebar__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 13px 18px;
    background: transparent;
    border: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
  }
  .sidebar__toggle-caret { color: var(--ink-muted); transition: transform .15s; }
  .sidebar.is-open .sidebar__toggle-caret { transform: rotate(180deg); }

  /* 드롭다운 패널: 기본 접힘, 열리면 토글 아래로 오버레이 */
  .sidebar__nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    max-height: 70vh;
    overflow-y: auto;
  }
  .sidebar.is-open .sidebar__nav { display: block; }

  .sidebar-ad { display: none; }
  .main { padding: 24px 18px; }
}

/* ---- 접근성: 모션 최소화 ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
