/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #ea580c;
  --warning-light: #fff7ed;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --max-width: 720px;
  --sidebar-width: 280px;
}

html { font-size: 16px; scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === Header === */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 0.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
}
.site-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.site-logo .logo-icon { font-size: 1.25rem; }

/* === Hamburger Menu Button === */
.menu-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  gap: 5px;
  border-radius: 6px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  z-index: 200;
}
.menu-btn:active { background: var(--bg); }
.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.25s ease;
  transform-origin: center;
}
/* Animate to X */
.menu-btn.open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.menu-btn.open span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.menu-btn.open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* === Overlay === */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 149;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}
.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  max-width: 85vw;
  height: 100vh;
  height: 100dvh;
  background: var(--card-bg);
  z-index: 150;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 20px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar.open {
  transform: translateX(0);
}
.sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  flex-shrink: 0;
}
.sidebar-header .sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.sidebar-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  touch-action: manipulation;
}
.sidebar-close:active { background: var(--bg); }
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0;
}
.sidebar-category {
  padding: 1rem 1rem 0.3rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}
.sidebar-category:first-child { padding-top: 0.3rem; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
  transition: background 0.1s;
  touch-action: manipulation;
}
.sidebar-link:active { background: var(--primary-light); color: var(--primary); }
.sidebar-link .sl-icon { font-size: 1rem; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-link .sl-name { flex: 1; }
@media (min-width: 640px) {
  .sidebar-link:hover { background: var(--primary-light); color: var(--primary); }
}

/* === Layout === */
.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 0.75rem 3rem;
}

/* === Hero === */
.hero { text-align: center; padding: 2rem 0 1.5rem; }
.hero h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.5rem; }
.hero p { color: var(--text-secondary); font-size: 1rem; max-width: 320px; margin: 0 auto; }
@media (min-width: 640px) {
  .hero { padding: 2.5rem 0 2rem; }
  .hero h1 { font-size: 1.8rem; }
}

/* === Card Grid === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}
@media (min-width: 500px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
  .card-grid { grid-template-columns: repeat(4, 1fr); gap: 1rem; }
}
.tool-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  touch-action: manipulation;
}
.tool-card:active { transform: scale(0.97); background: var(--primary-light); border-color: var(--primary); }
@media (min-width: 640px) {
  .tool-card { padding: 1.25rem 1rem; }
  .tool-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary); }
}
.tool-card .card-icon { font-size: 1.75rem; margin-bottom: 0.5rem; }
.tool-card h3 { font-size: 0.9rem; margin-bottom: 0.25rem; font-weight: 600; }
.tool-card p { font-size: 0.72rem; color: var(--text-secondary); line-height: 1.35; }

/* === Calculator Page === */
.calc-header { margin-bottom: 1.25rem; }
.calc-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  padding: 0.25rem 0;
  touch-action: manipulation;
}
.calc-header .back-link:active { color: var(--primary); }
.calc-header h1 { font-size: 1.35rem; font-weight: 800; }
.calc-header .subtitle { color: var(--text-secondary); margin-top: 0.15rem; font-size: 0.85rem; }
@media (min-width: 640px) {
  .calc-header h1 { font-size: 1.6rem; }
}

/* === Form === */
.calc-form {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  box-shadow: var(--shadow);
}
@media (min-width: 640px) {
  .calc-form { padding: 1.5rem; }
}
.form-section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
@media (min-width: 500px) {
  .form-row:not(.force-single) { grid-template-columns: 1fr 1fr; }
}
.form-row.single, .form-row.force-single { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-group input, .form-group select {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
  min-height: 42px;
}
.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 2rem;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.5rem; width: 100%; }
.input-suffix .suffix {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.8rem;
  pointer-events: none;
}

/* === Buttons === */
.btn-calculate {
  display: block;
  width: 100%;
  padding: 0.7rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 0.75rem;
  font-family: inherit;
  touch-action: manipulation;
  min-height: 46px;
  -webkit-appearance: none;
}
.btn-calculate:active { opacity: 0.85; }
@media (min-width: 640px) {
  .btn-calculate:hover { background: var(--primary-dark); }
}

/* === Results === */
.results {
  margin-top: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  box-shadow: var(--shadow);
  display: none;
}
@media (min-width: 640px) {
  .results { padding: 1.5rem; }
}
.results.visible { display: block; }
.results h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
@media (max-width: 380px) {
  .result-grid { grid-template-columns: 1fr; }
}
.result-item {
  background: var(--bg);
  padding: 0.75rem 0.5rem;
  border-radius: 8px;
  text-align: center;
}
.result-item .r-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}
.result-item .r-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}
.result-item.highlight {
  background: var(--primary-light);
  border: 1px solid var(--primary);
}
.result-highlight {
  background: var(--primary-light);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 1rem 0.75rem;
  text-align: center;
  margin-bottom: 0.75rem;
}
.result-highlight .r-value { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.result-highlight .r-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.2rem; }

.result-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.78rem; }
.result-table th, .result-table td { padding: 0.45rem 0.5rem; text-align: right; border-bottom: 1px solid var(--border); }
.result-table th { background: var(--bg); font-weight: 600; color: var(--text-secondary); font-size: 0.7rem; }
.result-table td:first-child, .result-table th:first-child { text-align: left; }

/* === Tabs === */
.tabs { display: flex; margin-bottom: 0.75rem; border-bottom: 2px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  font-family: inherit;
  touch-action: manipulation;
}
.tab-btn:active { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
@media (min-width: 640px) { .tab-btn:hover { color: var(--primary); } }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Notice === */
.notice {
  background: var(--warning-light);
  border: 1px solid #fdba74;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  color: #9a3412;
  margin-top: 1rem;
  line-height: 1.45;
}

/* === Footer === */
.site-footer {
  text-align: center;
  padding: 1.5rem 0.75rem;
  color: var(--text-secondary);
  font-size: 0.72rem;
  border-top: 1px solid var(--border);
  max-width: var(--max-width);
  margin: 0 auto;
}

/* === Schedule toggle === */
.schedule-toggle { margin-top: 0.75rem; text-align: center; }
.schedule-toggle button {
  background: none; border: 1px solid var(--border); padding: 0.5rem 1rem;
  border-radius: 8px; cursor: pointer; font-size: 0.85rem; color: var(--primary);
  font-family: inherit; touch-action: manipulation;
}
.schedule-toggle button:active { background: var(--primary-light); }
.schedule-container {
  margin-top: 0.75rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
  max-height: 350px; overflow-y: auto; display: none;
}
.schedule-container.visible { display: block; }

/* === Category section on homepage === */
.tool-section { margin-top: 1.5rem; }
.tool-section h2 {
  font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem;
  display: flex; align-items: center; gap: 0.4rem;
}
.tool-section h2 .section-icon { font-size: 1.1rem; }

/* === WeChat / Mobile === */
@media screen and (max-width: 480px) {
  html { font-size: 15px; }
  .main-content { padding: 1rem 0.5rem 2rem; }
  .form-group input, .form-group select { font-size: 0.9rem; min-height: 44px; }
  .btn-calculate { min-height: 48px; font-size: 1.05rem; }
}

/* === Prevent body scroll when sidebar open === */
body.sidebar-open { overflow: hidden; }
