/* ========================================
   SmartGap Tools — Global Stylesheet
   Mobile-first, light/dark theme
   ======================================== */

:root {
  --primary: #0f62fe;
  --primary-hover: #0353e9;
  --accent: #00c9a7;
  --accent-hover: #00b396;
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-input: #f0f2f5;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --font: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --transition: 0.2s ease;
  --bg-header: rgba(255, 255, 255, 0.85);
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-subtle: rgba(0, 0, 0, 0.03);
  --bg-footer: rgba(240, 242, 245, 0.95);
  --bg-code: rgba(0, 0, 0, 0.06);
  --bg-pre: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-card: rgba(22, 27, 34, 0.95);
  --bg-input: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --bg-header: rgba(13, 17, 23, 0.85);
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-subtle: rgba(255, 255, 255, 0.03);
  --bg-footer: rgba(22, 27, 34, 0.95);
  --bg-code: rgba(255, 255, 255, 0.08);
  --bg-pre: rgba(0, 0, 0, 0.3);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

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

a:hover {
  color: var(--accent-hover);
}

img { max-width: 100%; height: auto; }

/* ========================================
   HEADER
   ======================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 1rem;
}

.logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text) !important;
  white-space: nowrap;
}

.logo span {
  color: var(--accent);
}

.header-nav {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.header-nav::-webkit-scrollbar { display: none; }

.header-nav a {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: all var(--transition);
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--text);
  background: var(--bg-hover);
}

/* ========================================
   MAIN LAYOUT
   ======================================== */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ========================================
   BREADCRUMB + LANG SWITCHER
   ======================================== */

.breadcrumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-muted);
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb .sep {
  margin: 0 0.3rem;
  opacity: 0.5;
}

.lang-switch {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.lang-switch a {
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.lang-switch a:hover {
  color: var(--text);
}

.lang-switch a.active {
  color: var(--text);
  font-weight: 700;
  background: var(--bg-hover);
}

/* ========================================
   TOOL CARD
   ======================================== */

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.tool-card h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.tool-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

/* ========================================
   FORM ELEMENTS
   ======================================== */

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  transition: border-color var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 98, 254, 0.15);
}

textarea {
  resize: vertical;
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.5;
}

input[type="color"] {
  width: 60px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
  padding: 2px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

input[type="checkbox"] {
  accent-color: var(--primary);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.5rem 0;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text);
}

.input-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: end;
}

.input-row > * {
  flex: 1;
}

.input-group {
  margin-bottom: 1rem;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.5rem;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
  min-width: 44px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-copy {
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

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

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.btn-swap {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  padding: 0.5rem;
  font-size: 1.2rem;
  min-width: 44px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.input-row > div:not(.input-group) {
  flex: 0 0 auto;
  align-self: flex-end;
  margin-bottom: 1rem;
}

.btn-swap:hover {
  background: var(--accent-hover);
}

/* ========================================
   RESULT BOX
   ======================================== */

.result-box {
  position: relative;
  background: linear-gradient(135deg, rgba(15, 98, 254, 0.08), rgba(0, 201, 167, 0.08));
  border: 1px solid rgba(15, 98, 254, 0.2);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  margin-top: 1rem;
  word-break: break-all;
}

.result-box .result-value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.result-box .result-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.result-box .btn-copy {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

[dir="rtl"] .result-box .btn-copy {
  right: auto;
  left: 0.75rem;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.result-item {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.result-item .result-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.result-item .result-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.success-msg {
  color: var(--success);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ========================================
   STRENGTH METER
   ======================================== */

.strength-meter {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  margin-top: 0.5rem;
  overflow: hidden;
}

.strength-meter .bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s, background 0.3s;
}

/* ========================================
   DIFF TOOL
   ======================================== */

.diff-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.diff-output {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.8;
  margin-top: 1rem;
}

.diff-output .added {
  background: rgba(63, 185, 80, 0.15);
  color: var(--success);
  display: block;
  padding: 0 0.5rem;
}

.diff-output .removed {
  background: rgba(248, 81, 73, 0.15);
  color: var(--danger);
  display: block;
  padding: 0 0.5rem;
}

.diff-output .unchanged {
  display: block;
  padding: 0 0.5rem;
  color: var(--text-muted);
}

/* ========================================
   MARKDOWN PREVIEW
   ======================================== */

.md-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.md-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  min-height: 200px;
  overflow-y: auto;
}

.md-preview h1, .md-preview h2, .md-preview h3 { margin: 0.75em 0 0.5em; }
.md-preview h1 { font-size: 1.5rem; }
.md-preview h2 { font-size: 1.3rem; }
.md-preview h3 { font-size: 1.1rem; }
.md-preview p { margin-bottom: 0.75em; }
.md-preview code {
  background: var(--bg-code);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.md-preview pre {
  background: var(--bg-pre);
  padding: 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin-bottom: 0.75em;
}
.md-preview pre code { background: none; padding: 0; }
.md-preview ul, .md-preview ol { padding-left: 1.5rem; margin-bottom: 0.75em; }
.md-preview blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.75em;
}

/* ========================================
   TIMER
   ======================================== */

.timer-display {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  padding: 1.5rem 0;
  letter-spacing: 0.1em;
}

/* ========================================
   TIMEZONE GRID
   ======================================== */

.tz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.tz-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}

.tz-card .tz-city {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.tz-card .tz-time {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.tz-card .tz-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========================================
   SIZE TABLE
   ======================================== */

.size-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.size-table th,
.size-table td {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  text-align: center;
}

.size-table th {
  background: rgba(15, 98, 254, 0.1);
  font-weight: 600;
}

.size-table tr:hover td {
  background: var(--bg-subtle);
}

/* ========================================
   REGEX MATCHES
   ======================================== */

.regex-match {
  background: rgba(15, 98, 254, 0.25);
  border-radius: 3px;
  padding: 0 2px;
}

.regex-output {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: 1rem;
  min-height: 80px;
}

.match-list {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.match-list .match-item {
  padding: 0.3rem 0.5rem;
  border-left: 3px solid var(--accent);
  margin-bottom: 0.3rem;
  font-family: var(--font-mono);
}

/* ========================================
   COLOR PREVIEW
   ======================================== */

.color-preview {
  width: 100%;
  height: 80px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 1rem;
}

/* ========================================
   BMI CLASSIFICATION
   ======================================== */

.bmi-class {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.bmi-under { background: rgba(56, 189, 248, 0.2); color: #38bdf8; }
.bmi-normal { background: rgba(63, 185, 80, 0.2); color: var(--success); }
.bmi-over { background: rgba(210, 153, 34, 0.2); color: var(--warning); }
.bmi-obese { background: rgba(248, 81, 73, 0.2); color: var(--danger); }

/* ========================================
   AD SLOTS
   ======================================== */

.ad-slot {
  text-align: center;
  padding: 1rem 0;
  min-height: 50px;
}

/* ========================================
   SEO CONTENT
   ======================================== */

.seo-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.seo-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
  color: var(--text);
}

.seo-content h2:first-child { margin-top: 0; }

.seo-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 1.2rem 0 0.5rem;
}

.seo-content p {
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

.seo-content a {
  color: var(--accent);
}

.seo-content ul {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.seo-content li {
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

/* ========================================
   FAQ
   ======================================== */

.faq {
  margin-top: 2rem;
}

.faq h2 {
  margin-bottom: 1rem;
}

.faq details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.faq summary {
  padding: 1rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background var(--transition);
}

.faq summary:hover {
  background: var(--bg-subtle);
}

.faq summary::after {
  content: '+';
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  transition: transform var(--transition);
}

.faq details[open] summary::after {
  content: '−';
}

.faq summary::-webkit-details-marker { display: none; }

.faq details > div {
  padding: 0 1.25rem 1rem;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ========================================
   RELATED TOOLS GRID
   ======================================== */

.related-tools {
  margin-bottom: 2rem;
}

.related-tools h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.tool-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text) !important;
  transition: all var(--transition);
}

.tool-link:hover {
  border-color: var(--accent);
  background: rgba(0, 201, 167, 0.04);
  transform: translateY(-2px);
}

.tool-link .tool-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.tool-link .tool-info {
  min-width: 0;
}

.tool-link .tool-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.tool-link .tool-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   FOOTER
   ======================================== */

footer {
  background: var(--bg-footer);
  border-top: 1px solid var(--border);
  padding: 3rem 1rem 2rem;
  margin-top: 2rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.footer-col a {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.2rem 0;
  transition: color var(--transition);
}

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

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

.footer-bottom a {
  color: var(--text-muted);
  margin: 0 0.5rem;
}

/* ========================================
   TOAST
   ======================================== */

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent);
  color: #000;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========================================
   INDEX PAGE — HERO
   ======================================== */

.hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.hero h1 .accent { color: var(--accent); }

.hero .hero-sub {
  font-size: 1.1rem;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 1rem;
}

.hero .hero-count {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.index-seo {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-top: 2rem;
  line-height: 1.8;
}

.index-seo h2 { font-size: 1.3rem; margin: 1.2rem 0 0.5rem; }
.index-seo h2:first-child { margin-top: 0; }
.index-seo p { color: var(--text-muted); margin-bottom: 0.6rem; }

/* ========================================
   THEME TOGGLE
   ======================================== */

.theme-toggle {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 50px;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text);
  transition: all var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-subtle);
  border-color: var(--accent);
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
  .header-nav { display: none; }

  .tool-card { padding: 1.25rem; }
  .tool-card h1 { font-size: 1.4rem; }
  .seo-content { padding: 1.25rem; }

  .tools-grid {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  .input-row {
    flex-direction: column;
  }

  .diff-container,
  .md-container {
    grid-template-columns: 1fr;
  }

  .timer-display {
    font-size: 2.5rem;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .breadcrumb {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ========================================
   RTL SUPPORT
   ======================================== */

[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .header-inner {
  flex-direction: row-reverse;
}

[dir="rtl"] .header-nav {
  flex-direction: row-reverse;
}

[dir="rtl"] .breadcrumb {
  flex-direction: row-reverse;
}

[dir="rtl"] .lang-switch {
  flex-direction: row-reverse;
}

[dir="rtl"] .tool-link {
  flex-direction: row-reverse;
}

[dir="rtl"] .seo-content ul {
  padding-left: 0;
  padding-right: 1.5rem;
}

[dir="rtl"] .faq summary {
  flex-direction: row-reverse;
}

[dir="rtl"] .md-preview blockquote {
  border-left: none;
  border-right: 3px solid var(--accent);
  padding-left: 0;
  padding-right: 1rem;
}

[dir="rtl"] .match-list .match-item {
  border-left: none;
  border-right: 3px solid var(--accent);
}

/* ========================================
   UTILITIES
   ======================================== */

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-mono { font-family: var(--font-mono); }
.hidden { display: none !important; }
