/* ============================================================
 * C++多功能计算器 - 全局样式
 * 深色科技主题，支持响应式布局
 * ============================================================ */

/* ===== CSS变量定义 ===== */
:root {
  --bg: #0a0e1a;
  --bg-card: #111827;
  --bg-card-trans: rgba(17, 24, 39, 0.85);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #0ea5e9;
  --primary-light: #38bdf8;
  --primary-dark: #0284c7;
  --border: rgba(148, 163, 184, 0.15);
  --border-hover: rgba(14, 165, 233, 0.4);
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 0.75rem;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(14, 165, 233, 0.25);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* ===== 基础重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea {
  font-family: inherit; color: var(--text);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.5rem 0.75rem; font-size: 0.95rem;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}
hr.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: 280px; min-width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-header {
  padding: 1.5rem; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon {
  width: 2.5rem; height: 2.5rem; border-radius: 0.625rem;
  background: rgba(14, 165, 233, 0.15); display: flex; align-items: center; justify-content: center;
}
.logo-icon i { width: 1.25rem; height: 1.25rem; color: var(--primary); }
.logo-title { font-size: 1.125rem; font-weight: 700; }
.logo-subtitle { font-size: 0.75rem; color: var(--text-muted); }
.sidebar-close { display: none; background: none; border: none; color: var(--text-muted); padding: 0.25rem; }
.sidebar-close:hover { color: var(--text); }

/* 导航菜单 */
.nav-menu { padding: 0.75rem; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem 1rem; border-radius: var(--radius);
  color: var(--text-muted); transition: all 0.2s; margin-bottom: 0.25rem;
}
.nav-item i { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }
.nav-item .nav-label { display: block; font-size: 0.875rem; font-weight: 500; }
.nav-item .nav-desc { display: block; font-size: 0.75rem; opacity: 0.7; }
.nav-item:hover { background: rgba(148, 163, 184, 0.1); color: var(--text); }
.nav-item.active { background: rgba(14, 165, 233, 0.12); color: var(--primary); border: 1px solid rgba(14, 165, 233, 0.2); }

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

/* 遮罩层 */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.overlay.active { opacity: 1; pointer-events: all; }

/* ===== 主内容区域 ===== */
.main-content {
  flex: 1; margin-left: 280px; min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: rgba(17, 24, 39, 0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.menu-btn {
  display: none; background: none; border: none; color: var(--text-muted); padding: 0.25rem;
}
.menu-btn:hover { color: var(--text); }
.breadcrumb { font-size: 0.875rem; color: var(--text-muted); flex: 1; }

/* 服务器配置按钮 */
.server-config-btn {
  display: flex; align-items: center; gap: 0.375rem;
  padding: 0.375rem 0.75rem; border-radius: var(--radius);
  background: rgba(14, 165, 233, 0.1); border: 1px solid rgba(14, 165, 233, 0.25);
  color: var(--primary); font-size: 0.8rem; transition: all 0.2s;
}
.server-config-btn:hover { background: rgba(14, 165, 233, 0.2); box-shadow: var(--shadow-glow); }
.server-config-btn i { width: 1rem; height: 1rem; }

/* 页面容器 */
.page-container { flex: 1; padding: 1.5rem; overflow-y: auto; }
.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 通用组件 ===== */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.875rem; display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.page-header h1 i { color: var(--primary); width: 2rem; height: 2rem; }
.page-header p { color: var(--text-muted); }

.glass-card {
  background: var(--bg-card-trans); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

/* 标签页 */
.tabs { display: flex; gap: 0.25rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab-btn {
  padding: 0.5rem 1rem; border-radius: var(--radius);
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted); font-size: 0.875rem; transition: all 0.2s;
}
.tab-btn:hover { background: rgba(148, 163, 184, 0.1); color: var(--text); }
.tab-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* 按钮 */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; border-radius: var(--radius);
  background: var(--primary); color: white; border: none;
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-glow); transition: all 0.2s;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 0 30px rgba(14, 165, 233, 0.4); }
.btn-outline {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; border-radius: var(--radius);
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); font-size: 0.875rem; transition: all 0.2s;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: rgba(14, 165, 233, 0.05); }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.625rem; border-radius: var(--radius);
  background: rgba(148, 163, 184, 0.1); border: none; color: var(--text-muted);
}
.btn-icon:hover { background: rgba(14, 165, 233, 0.2); color: var(--primary); }
.toggle-btn {
  padding: 0.5rem 1rem; border-radius: var(--radius);
  background: rgba(148, 163, 184, 0.1); border: none;
  color: var(--text-muted); font-size: 0.875rem; transition: all 0.2s;
}
.toggle-btn:hover { background: rgba(14, 165, 233, 0.15); color: var(--text); }
.toggle-btn.active { background: var(--primary); color: white; }

/* 输入框 */
.calc-input {
  width: 100%; padding: 0.625rem 0.875rem;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 0.95rem; transition: all 0.2s;
}
.calc-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1); }
.calc-input.font-mono { font-family: var(--font-mono); }
.input-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.5rem; }
.input-label i { color: var(--primary); width: 1rem; height: 1rem; }
.input-group { flex: 1; min-width: 100px; }
.input-group.small { min-width: 60px; flex: 0.5; }
.input-group.flex-3 { flex: 3; }
.input-group label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.input-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-bottom: 0.75rem; }
.operator { font-size: 1.25rem; color: var(--primary); padding-bottom: 0.5rem; font-weight: bold; }
.button-group { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.button-row { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

/* 快捷按钮 */
.quick-buttons { display: flex; flex-wrap: wrap; gap: 0.375rem; margin: 0.75rem 0; }
.quick-buttons button {
  padding: 0.375rem 0.625rem; border-radius: 0.5rem;
  background: rgba(148, 163, 184, 0.08); border: none;
  color: var(--text-muted); font-size: 0.8rem; cursor: pointer; transition: all 0.2s;
}
.quick-buttons button:hover { background: rgba(14, 165, 233, 0.2); color: var(--primary); }
.quick-label { font-size: 0.75rem; color: var(--text-muted); align-self: center; margin-right: 0.25rem; }

/* 结果显示 */
.result-display {
  background: rgba(148, 163, 184, 0.06);
  border: 1px solid rgba(14, 165, 233, 0.25);
  border-radius: var(--radius); padding: 1rem;
  font-family: var(--font-mono); margin-top: 0.75rem;
}
.result-display .label { color: var(--text-muted); font-size: 0.875rem; }
.result-display .value { color: var(--primary); font-weight: 700; font-size: 1.25rem; }
.error-display {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius); padding: 0.875rem;
  color: var(--error); font-size: 0.875rem; margin-top: 0.75rem;
}

/* 矩阵编辑器 */
.matrix-editor { display: inline-flex; flex-direction: column; gap: 0.25rem; }
.matrix-row { display: flex; gap: 0.25rem; }
.matrix-editor input {
  width: 4rem; height: 2rem; text-align: center;
  padding: 0; font-size: 0.85rem; font-family: var(--font-mono);
}
.matrix-controls { display: flex; gap: 0.25rem; margin-top: 0.5rem; }
.matrix-controls button {
  padding: 0.25rem 0.5rem; font-size: 0.75rem;
  background: rgba(148, 163, 184, 0.1); border: none;
  border-radius: 0.375rem; color: var(--text-muted); cursor: pointer;
}
.matrix-controls button:hover { background: rgba(14, 165, 233, 0.2); color: var(--primary); }

/* ===== 首页 ===== */
.hero { text-align: center; padding: 2rem 0 3rem; }
.badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem; border-radius: 9999px;
  background: rgba(14, 165, 233, 0.1); color: var(--primary);
  font-size: 0.875rem; margin-bottom: 1.5rem;
}
.badge i { width: 1rem; height: 1rem; }
.hero-title {
  font-size: 2.5rem; font-weight: 800; margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--primary), #38bdf8, #818cf8);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.hero-desc { color: var(--text-muted); font-size: 1.1rem; max-width: 600px; margin: 0 auto 2rem; }
.tech-features { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.5rem; }
.tech-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1.25rem; border-radius: var(--radius);
  background: var(--bg-card); border: 1px solid var(--border);
}
.tech-item i { width: 1.25rem; height: 1.25rem; color: var(--primary); }
.tech-item strong { display: block; font-size: 0.875rem; }
.tech-item span { display: block; font-size: 0.75rem; color: var(--text-muted); }

.section-title { font-size: 1.25rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.section-title i { color: var(--primary); width: 1.25rem; height: 1.25rem; }

.feature-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.feature-card {
  display: block; padding: 1.5rem;
  background: var(--bg-card-trans); backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: all 0.3s; cursor: pointer; box-shadow: var(--shadow);
}
.feature-card:hover { transform: scale(1.02); border-color: var(--border-hover); box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(14,165,233,0.15); }
.feature-icon {
  width: 3rem; height: 3rem; border-radius: 0.75rem;
  display: flex; align-items: center; justify-content: center; margin-bottom: 1rem;
}
.feature-icon i { width: 1.5rem; height: 1.5rem; color: white; }
.feature-icon.cyan { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.feature-icon.emerald { background: linear-gradient(135deg, #10b981, #14b8a6); }
.feature-icon.violet { background: linear-gradient(135deg, #8b5cf6, #a855f7); }
.feature-icon.amber { background: linear-gradient(135deg, #f59e0b, #f97316); }
.feature-icon.rose { background: linear-gradient(135deg, #f43f5e, #ec4899); }
.feature-card h3 { font-size: 1.125rem; margin-bottom: 0.25rem; }
.feature-card p { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.tags span {
  padding: 0.25rem 0.5rem; border-radius: 0.375rem;
  background: rgba(14, 165, 233, 0.12); color: var(--primary);
  font-size: 0.7rem; font-weight: 500;
}

.tips-card ol { padding-left: 1.25rem; color: var(--text-muted); font-size: 0.9rem; }
.tips-card li { margin-bottom: 0.375rem; }

/* ===== 排列组合 ===== */
.perm-types { display: flex; flex-direction: column; gap: 0.375rem; }
.perm-type {
  display: flex; flex-direction: column; padding: 0.75rem;
  border-radius: var(--radius); border: 1px solid transparent;
  background: transparent; color: var(--text); text-align: left; cursor: pointer; transition: all 0.2s;
}
.perm-type:hover { background: rgba(148, 163, 184, 0.08); }
.perm-type.active { background: rgba(14, 165, 233, 0.1); border-color: rgba(14, 165, 233, 0.25); }
.perm-type .type-label { font-weight: 500; font-size: 0.875rem; }
.perm-type .type-desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.125rem; }
.perm-type .type-formula { font-size: 0.7rem; color: var(--primary); font-family: var(--font-mono); margin-top: 0.25rem; }

.factorial-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 0.5rem; }
.factorial-item { padding: 0.5rem; border-radius: var(--radius); background: rgba(148, 163, 184, 0.06); text-align: center; cursor: pointer; transition: all 0.2s; }
.factorial-item:hover { background: rgba(14, 165, 233, 0.15); }
.factorial-item .fact-label { font-size: 0.75rem; color: var(--text-muted); }
.factorial-item .fact-value { font-size: 0.875rem; font-family: var(--font-mono); font-weight: 500; }

/* ===== 几何公式 ===== */
.shape-list { display: flex; flex-direction: column; gap: 0.375rem; }
.shape-item {
  padding: 0.625rem 0.875rem; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer; transition: all 0.2s;
}
.shape-item:hover { background: rgba(148, 163, 184, 0.08); }
.shape-item.active { background: rgba(14, 165, 233, 0.1); border-color: rgba(14, 165, 233, 0.25); }
.shape-item .shape-label { font-weight: 500; font-size: 0.875rem; }
.shape-item .shape-formula { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); }
.input-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 0.75rem; }

/* ===== 表格 ===== */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th { text-align: left; padding: 0.625rem; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 500; }
.data-table td { padding: 0.625rem; border-bottom: 1px solid rgba(148, 163, 184, 0.08); font-family: var(--font-mono); }
.data-table tr:hover { background: rgba(148, 163, 184, 0.04); }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); width: 90%; max-width: 520px;
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  transform: scale(0.95); transition: transform 0.25s;
}
.modal-overlay.active .modal { transform: scale(1); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { display: flex; align-items: center; gap: 0.5rem; font-size: 1.125rem; }
.modal-header h2 i { color: var(--primary); width: 1.25rem; height: 1.25rem; }
.modal-close { background: none; border: none; color: var(--text-muted); padding: 0.25rem; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.75rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-muted); }

/* 预设服务器 */
.server-presets { display: flex; flex-direction: column; gap: 0.5rem; }
.server-preset {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: rgba(148, 163, 184, 0.04);
  cursor: pointer; transition: all 0.2s;
}
.server-preset:hover { border-color: var(--primary); background: rgba(14, 165, 233, 0.05); }
.server-preset.active { border-color: var(--primary); background: rgba(14, 165, 233, 0.1); }
.server-preset .preset-name { font-weight: 500; font-size: 0.875rem; }
.server-preset .preset-url { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); }
.current-server {
  padding: 0.75rem; border-radius: var(--radius);
  background: rgba(14, 165, 233, 0.08); border: 1px solid rgba(14, 165, 233, 0.2);
  font-family: var(--font-mono); font-size: 0.875rem; color: var(--primary); word-break: break-all;
}
.connection-status { margin-top: 0.5rem; font-size: 0.875rem; text-align: center; }
.connection-status.success { color: var(--success); }
.connection-status.error { color: var(--error); }

/* 两列布局 */
.two-col-layout { display: grid; grid-template-columns: 280px 1fr; gap: 1rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.space-y-4 > * + * { margin-top: 1rem; }

/* ===== 工具类 ===== */
.text-center { text-align: center; }
.text-primary { color: var(--primary); }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.flex-1 { flex: 1; }
.flex-3 { flex: 3; }
.hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.help-list { list-style: none; color: var(--text-muted); font-size: 0.875rem; }
.help-list li { margin-bottom: 0.375rem; padding-left: 1rem; position: relative; }
.help-list li::before { content: "-"; position: absolute; left: 0; color: var(--primary); }

/* ===== 响应式适配 ===== */
@media (max-width: 1024px) {
  .two-col-layout { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-btn { display: block; }
  .sidebar-close { display: block; }
  .hero-title { font-size: 1.75rem; }
  .feature-grid { grid-template-columns: 1fr; }
  .input-row { flex-direction: column; align-items: stretch; }
  .operator { align-self: flex-start; padding: 0; }
  .server-config-btn span { display: none; }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }
