/* --- 全局样式修复，防止容器超出屏幕 --- */
*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg-light: #ffffff;
    --bg-app: #f2f2f7;
    --text-main: #333333;
    --text-sub: #8e8e93;
    --primary-blue: #007aff;
    --border-color: #e5e5ea;
    --danger-red: #ff3b30;
}

body, html {
    margin: 0; padding: 0; height: 100%;
    font-family: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;
    background-color: var(--bg-app);
    overflow: hidden;
}

/* --- 核心布局 --- */
.app-wrapper { display: flex; flex-direction: row; height: 100vh; width: 100%; }

/* 手机端顶部栏默认隐藏 */
.mobile-header { display: none; }

/* --- 侧边栏样式 --- */
.sidebar {
    width: 260px; background-color: var(--bg-light); border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 10;
}
.logo { padding: 30px 20px 20px; border-bottom: 1px solid var(--border-color); }
.logo h3 { margin: 0; font-size: 20px; color: var(--text-main); font-weight: 600; }
.logo p { margin: 8px 0 0; font-size: 12px; color: var(--text-sub); letter-spacing: 1px; }

.menu { flex: 1; padding: 10px 0; overflow-y: auto; }

.menu-item {
    display: flex; align-items: center; 
    padding: 14px 24px;       
    color: var(--text-main); text-decoration: none;
    font-size: 15px; transition: all 0.2s ease; 
    margin: 4px 12px;         
    border-radius: 8px; cursor: pointer;
}
.menu-item:active { background-color: rgba(0,0,0,0.05); }
.menu-item.active { background-color: rgba(0, 122, 255, 0.1); color: var(--primary-blue); font-weight: 600; }

/* --- 内容区域 --- */
.content { flex: 1; position: relative; height: 100%; overflow-y: auto; overflow-x: hidden; }

/* --- 手机端适配 --- */
@media (max-width: 768px) {
    body, html { height: auto; overflow-x: hidden; overflow-y: auto; }
    .app-wrapper { flex-direction: column; height: auto; padding-top: 50px; }
    
    .mobile-header {
        display: flex; align-items: center; height: 50px; background-color: var(--bg-light);
        border-bottom: 1px solid var(--border-color); padding: 0 15px;
        position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    }
    .menu-toggle { display: flex; background: none; border: none; font-size: 24px; color: var(--text-main); margin-right: 15px; }
    .mobile-title { font-size: 17px; font-weight: 600; color: var(--text-main); }

    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; width: 260px; z-index: 1000;
        background-color: var(--bg-light); transform: translateX(-100%);
        transition: transform 0.3s ease; box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 900; opacity: 0; visibility: hidden; }
    .sidebar-overlay.active { opacity: 1; visibility: visible; }
    .content { padding-bottom: 350px !important; }
    
    /* 核心修复：缩小手机端间距，避免超出屏幕和拥挤 */
    .dashboard-container { padding: 15px !important; } 
    .dashboard-grid { gap: 12px !important; }
    .tool-card { padding: 15px 10px !important; }
}

.tool-section { display: none; padding: 20px; box-sizing: border-box; }
.tool-section.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- 首页 Grid 布局 --- */
.dashboard-container { padding: 30px; max-width: 1000px; margin: 0 auto; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; max-width: 500px; margin: 0 auto; }
.tool-card {
    position: relative; /* 为星星提供绝对定位参照 */
    background: #fff; border-radius: 20px; padding: 20px; text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.04); cursor: pointer; border: 1px solid transparent;
    aspect-ratio: 1 / 1; 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}

/* ================================ */
/* ★ 收藏功能：去背景、固定分离 ★ */
/* ================================ */
.fav-star {
    position: absolute;
    top: 10px;      /* 靠右上方，不会挤压图标 */
    right: 12px;
    font-size: 22px; /* 适当缩小的星星字号 */
    color: #d1d1d6; 
    z-index: 10;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.fav-star.active {
    color: #ffcc00; /* 土豪金 */
    text-shadow: 0 0 6px rgba(255, 204, 0, 0.4);
}
.fav-star:active {
    transform: scale(1.3);
}

.tool-icon {
    font-size: 36px; margin-bottom: 12px; width: 60px; height: 60px; border-radius: 14px; 
    background: #f0f7ff; color: var(--primary-blue);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; 
}
.tool-icon .custom-svg-icon { width: 36px; height: 36px; }

.tool-name {
    margin-top: 10px;
    font-size: 14px;
    color: var(--text-main);
    font-weight: 500;
    line-height: 1.3;
    height: 2.6em;         
    display: flex;
    align-items: center;    
    justify-content: center;
    overflow: hidden;
    width: 100%;
}

/* --- 通用控件样式 --- */
.container { max-width: 600px; margin: 0 auto; }
.controls { background: #fff; padding: 20px; border-radius: 12px; margin-bottom: 15px; }
.row { display: flex; gap: 15px; margin-bottom: 15px; }
label { display: block; font-size: 12px; color: #8e8e93; margin-bottom: 6px; }
input[type="number"], select {
    width: 100%; padding: 10px; border: 1px solid #e5e5ea; border-radius: 8px; font-size: 16px;
    background: #f9f9f9; box-sizing: border-box; outline: none;
}

.tabs { display: flex; background: #e5e5ea; padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.tab-btn { flex: 1; text-align: center; padding: 8px; font-size: 13px; color: #666; cursor: pointer; }
.tab-btn.active { background: #fff; color: #007aff; font-weight: 600; border-radius: 7px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.result-card { background: #fff; border-radius: 12px; padding: 20px; margin-top: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }

/* --- 顶部栏按钮 (清空) --- */
.header-sub-row { margin-top: 5px; margin-bottom: 10px; width: 100%; }
.btn-clear {
    background: #f2f2f7; color: var(--text-sub); border: none; padding: 4px 12px;
    border-radius: 14px; font-size: 12px; font-weight: 500; cursor: pointer;
    transition: all 0.2s;
}
.btn-clear:active { background-color: #fff0f0; color: var(--danger-red); transform: scale(0.95); }

/* --- 调节按钮 (+/-) --- */
.text-btn {
    background: none; border: none; color: #007aff; font-size: 24px; font-weight: 400;
    cursor: pointer; padding: 0; height: 32px; width: 32px;
    display: flex; align-items: center; justify-content: center; transition: opacity 0.2s;
}
.text-btn.mini {
    background: #f0f7ff; border-radius: 50%; color: #007aff; font-size: 20px;
}
.text-btn:active { opacity: 0.6; transform: scale(0.9); }

.segmented-control { background: #e5e5ea; border-radius: 8px; padding: 2px; display: inline-flex; }
.segmented-btn { padding: 4px 10px; font-size: 12px; color: #666; border-radius: 6px; cursor: pointer; transition: all 0.2s; }
.segmented-btn.active { background: #fff; color: #007aff; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

.toolbar-divider { width: 1px; height: 25px; background: rgba(0,122,255,0.15); }
.toolbar-label { font-size: 0.75rem; color: #666; font-weight: 600; }
.toolbar-val { font-weight: 700; color: #007aff; font-family: monospace; }