/* ============================================
   FreeToolbox — Global Stylesheet v4
   사이드바 + 메인 레이아웃, 다크 테마
   ============================================ */

/* --- CSS Variables --- */
:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --text-muted: #5a5a72;
  --accent: #6c5ce7; /* 도구별 override */
  --accent-glow: rgba(108, 92, 231, 0.3);
  --green: #00d2a0;
  --red: #ff6b6b;
  --orange: #ffa94d;
  --sidebar-w: 260px;
  --header-h: 56px;
  --tabbar-h: 56px;
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================
   HEADER
   ============================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  z-index: 100;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.4rem;
}

.logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text) !important;
  text-decoration: none !important;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.header-search {
  flex: 1;
  max-width: 400px;
}
.header-search input {
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.header-search input:focus { border-color: var(--accent); }
.header-search input::placeholder { color: var(--text-muted); }

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

/* Language selector */
.lang-selector { position: relative; }
.lang-selector button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.lang-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 160px;
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.lang-dropdown.open { display: block; }
.lang-dropdown a {
  display: block;
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  text-decoration: none;
  transition: background 0.15s;
}
.lang-dropdown a:hover {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

/* ============================================
   LAYOUT (sidebar + main)
   ============================================ */
.layout {
  display: flex;
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
  position: relative;
  z-index: 1;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding-bottom: 1rem;
}

.sidebar-nav { flex: 1; padding: 0.5rem 0; }

.sidebar-category { border-bottom: 1px solid var(--border); }

.category-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s, background 0.15s;
}
.category-toggle:hover { color: var(--text); background: var(--surface2); }
.category-toggle.active { color: var(--accent); }

.category-tools {
  list-style: none;
  display: none;
  padding: 0 0 0.35rem;
}
.category-tools.open { display: block; }

.category-tools li a {
  display: block;
  padding: 0.35rem 1rem 0.35rem 2.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.category-tools li a:hover {
  color: var(--text);
  background: var(--surface2);
  text-decoration: none;
}
.category-tools li a.current {
  color: var(--accent);
  font-weight: 600;
}

/* Cross links */
.cross-links {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.cross-links a {
  display: block;
  padding: 0.4rem 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
}
.cross-links a:hover { color: var(--accent); text-decoration: none; }

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem 3rem;
  max-width: 900px;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
}
.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumb a:hover { color: var(--accent); }

/* H1 + subtitle */
h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

/* Tool body */
.tool-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Ad slots */
.ad-slot {
  min-height: 90px;
  margin: 1.5rem 0;
  border-radius: 8px;
}

/* Promo banner */
.promo-banner {
  margin: 1.5rem 0;
}
.promo-banner a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  transition: border-color 0.2s;
}
.promo-banner a:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

/* ============================================
   SEO CONTENT
   ============================================ */
.seo-content {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.seo-content h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.5rem 0 0.6rem;
  color: var(--text);
}
.seo-content p, .seo-content li {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.7;
}
.seo-content p { margin-bottom: 0.6rem; }
.seo-content ul, .seo-content ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.seo-content li { margin-bottom: 0.3rem; }
.seo-content strong { color: var(--text); }

/* TOC */
.toc {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.toc h2 {
  font-size: 0.8rem !important;
  margin: 0 0 0.4rem !important;
  color: var(--text-muted) !important;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.toc ol { margin: 0; padding-left: 1.5rem; }
.toc li { margin-bottom: 0.2rem; }
.toc a { color: var(--accent); font-size: 0.82rem; text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* Comparison table */
.seo-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.82rem;
}
.seo-content th, .seo-content td {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  text-align: left;
}
.seo-content th { background: var(--surface); font-weight: 600; color: var(--text); }
.seo-content td { color: var(--text-dim); }

/* FAQ details */
.seo-content details {
  margin-bottom: 0.4rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.seo-content summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--text);
}
.seo-content details p { margin-top: 0.5rem; }

/* Related tools */
.related-tools { margin-top: 2rem; }
.related-tools h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.75rem; }
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.6rem;
}
.related-grid a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 0.82rem;
  text-decoration: none;
  transition: border-color 0.2s;
}
.related-grid a:hover { border-color: var(--accent); color: var(--text); text-decoration: none; }

/* ============================================
   FOOTER
   ============================================ */
footer {
  text-align: center;
  padding: 2rem 0 1.5rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}
footer p { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; }
footer a { color: var(--text-muted); }
footer a:hover { color: var(--accent); }

/* ============================================
   MOBILE TABBAR
   ============================================ */
.mobile-tabbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tabbar-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}
.mobile-tabbar a, .mobile-tabbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  color: var(--text-dim);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}
.mobile-tabbar a:hover, .mobile-tabbar button:hover { color: var(--text); }

/* Processing overlay */
.processing-overlay {
  text-align: center;
  padding: 2rem;
}
.processing-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-sub { font-size: 0.82rem; color: var(--text-muted); }

/* ============================================
   RTL (Arabic)
   ============================================ */
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .main-content { margin-left: 0; }
[dir="rtl"] .breadcrumb { direction: rtl; }
[dir="rtl"] .category-tools li a { padding-left: 1rem; padding-right: 2.2rem; }
[dir="rtl"] .lang-dropdown { right: auto; left: 0; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-h);
    width: 280px;
    height: calc(100vh - var(--header-h));
    z-index: 90;
    transition: left 0.25s ease;
  }
  .sidebar.open { left: 0; }
  [dir="rtl"] .sidebar { left: auto; right: -100%; }
  [dir="rtl"] .sidebar.open { right: 0; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-h);
    background: rgba(0,0,0,0.5);
    z-index: 80;
  }
  .sidebar-overlay.open { display: block; }

  .hamburger { display: block; }
  .mobile-tabbar { display: flex; }
  .main-content {
    padding: 1.2rem 1rem 5rem;
  }
  .header-search { max-width: 200px; }
}

@media (max-width: 480px) {
  .header-search { display: none; }
  .main-content { padding: 1rem 0.75rem 5rem; }
  h1 { font-size: 1.4rem; }
  .related-grid { grid-template-columns: 1fr; }
}
