/* ============================================================
   在线工具箱 - 全局样式
   现代 SaaS 风格 · 紫靛渐变 · 响应式
   ============================================================ */

/* ===== CSS 变量 ===== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #8b5cf6;
    --bg: #f8fafc;
    --bg-alt: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(15,23,42,0.04);
    --shadow-md: 0 4px 16px rgba(15,23,42,0.06);
    --shadow-lg: 0 12px 40px rgba(15,23,42,0.10);
    --shadow-primary: 0 8px 24px rgba(99,102,241,0.25);
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --sidebar-w: 260px;
    --header-h: 68px;
}

/* ===== 全局重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 全局背景装饰光晕 */
body::before {
    content: '';
    position: fixed;
    top: -200px;
    right: -200px;
    width: 520px;
    height: 520px;
    background: radial-gradient(circle, rgba(99,102,241,0.10), transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}
body::after {
    content: '';
    position: fixed;
    bottom: -220px;
    left: 80px;
    width: 440px;
    height: 440px;
    background: radial-gradient(circle, rgba(139,92,246,0.08), transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

/* ===== 布局容器 ===== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ============================================================
   侧边栏
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 24px 16px;
}

/* Logo 区域（横版铺满） */
.logo-area {
    padding: 0 0 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}
.logo-area a {
    display: block;
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.logo-area a:hover {
    opacity: 0.88;
}
.logo {
    display: block;
    width: 100%;
    height: auto;
}

/* 导航 */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-item .nav-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    border-radius: 10px;
    background: var(--bg-alt);
    transition: all 0.22s ease;
    flex-shrink: 0;
    line-height: 1;
}

.nav-item:hover {
    background: var(--bg-alt);
    color: var(--text);
}
.nav-item:hover .nav-icon { transform: scale(1.06); }

.nav-item.active {
    background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(139,92,246,0.10));
    color: var(--primary-dark);
    font-weight: 600;
}
.nav-item.active .nav-icon {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    box-shadow: 0 4px 12px rgba(99,102,241,0.30);
}

.sidebar-footer {
    padding: 16px 8px 0;
    margin-top: 8px;
    border-top: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================================
   主内容区
   ============================================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-w));
}

/* 顶部栏（毛玻璃，全宽铺满） */
.main-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: rgba(248,250,252,0.82);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
    flex: 1;
}

.menu-toggle {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 38px;
    height: 38px;
    font-size: 18px;
    cursor: pointer;
    color: var(--text);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.breadcrumb {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right { display: flex; align-items: center; flex-shrink: 0; }

/* 一体化药丸搜索框 */
.search-form {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    padding: 4px 4px 4px 18px;
    transition: all 0.25s ease;
    width: 300px;
    box-shadow: var(--shadow-sm);
}
.search-form:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99,102,241,0.10);
}
.search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: var(--text);
    min-width: 0;
}
.search-input::placeholder { color: var(--text-muted); }
.search-btn {
    padding: 8px 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-primary);
    white-space: nowrap;
}
.search-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 28px rgba(99,102,241,0.35);
}
.search-btn:active { transform: translateY(0); }

/* 内容区（全宽铺满） */
.content-area {
    flex: 1;
    padding: 32px;
    width: 100%;
}

/* 广告位 */
.ad-banner {
    background: linear-gradient(135deg, rgba(99,102,241,0.045), rgba(139,92,246,0.045));
    border: 1px dashed rgba(99,102,241,0.28);
    border-radius: var(--radius-lg);
    padding: 22px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 32px;
    letter-spacing: 0.02em;
}

/* ============================================================
   首页 Hero 区
   ============================================================ */
.page-header {
    text-align: center;
    padding: 24px 0 40px;
}
.page-header h1 {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.page-header p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-top: 10px;
}

/* 分类页头部（左对齐，覆盖首页样式） */
.page-header[style*="text-align:left"] h1,
.page-header[style*="text-align: left"] h1 {
    background: none;
    -webkit-text-fill-color: var(--text);
    color: var(--text);
    font-size: 26px;
}

/* ============================================================
   工具卡片网格（无图标版）
   ============================================================ */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 26px 24px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    overflow: hidden;
}

/* 顶部渐变装饰条（替代原图标位置的视觉重心） */
.tool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.tool-card:hover {
    transform: translateY(-4px);
    border-color: rgba(99,102,241,0.28);
    box-shadow: var(--shadow-lg);
}
.tool-card:hover::before { transform: scaleX(1); }

.tool-card h3 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    transition: color 0.2s ease;
}
.tool-card:hover h3 { color: var(--primary-dark); }

.tool-card p {
    font-size: 13.5px;
    color: var(--text-secondary);
    line-height: 1.65;
}

/* ============================================================
   工具页容器
   ============================================================ */
.tool-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px;
    box-shadow: var(--shadow-md);
}
.tool-container h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.tool-container .desc {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 28px;
}

/* ============================================================
   单位转换器
   ============================================================ */
.converter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: end;
}
.converter-grid .field { display: flex; flex-direction: column; gap: 8px; }
.converter-grid label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}
.converter-grid select,
.converter-grid input {
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
    font-family: inherit;
    outline: none;
    width: 100%;
}
.converter-grid select:focus,
.converter-grid input:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 4px rgba(99,102,241,0.10);
}
.converter-grid .swap-btn {
    grid-column: 1 / -1;
    justify-self: center;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px 0;
}
.converter-grid .swap-btn:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #fff;
    border-color: transparent;
    transform: rotate(180deg);
    box-shadow: var(--shadow-primary);
}
.result-box {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(99,102,241,0.07), rgba(139,92,246,0.07));
    border: 1px solid rgba(99,102,241,0.18);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: -0.01em;
    word-break: break-all;
}

/* ============================================================
   文本计数器
   ============================================================ */
.text-counter textarea {
    width: 100%;
    min-height: 220px;
    padding: 18px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.75;
    resize: vertical;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
    outline: none;
}
.text-counter textarea:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 4px rgba(99,102,241,0.10);
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 14px;
    margin-top: 22px;
}
.stat-item {
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 18px 14px;
    text-align: center;
    transition: all 0.25s ease;
}
.stat-item:hover {
    background: var(--surface);
    border-color: rgba(99,102,241,0.28);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.stat-item .number {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}
.stat-item .label {
    font-size: 12.5px;
    color: var(--text-secondary);
    margin-top: 6px;
    font-weight: 500;
}

/* ============================================================
   底部
   ============================================================ */
.main-footer {
    text-align: center;
    padding: 24px 0 8px;
    font-size: 13px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-light);
    margin-top: 32px;
}
.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 2px 4px;
    transition: color 0.2s ease;
}
.footer-links a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
    text-underline-offset: 3px;
}
.footer-sep {
    color: var(--border);
    font-size: 12px;
    user-select: none;
}
.footer-copy {
    margin: 0;
    color: var(--text-muted);
    font-size: 12.5px;
}

/* ============================================================
   搜索高亮（仅搜索结果页使用）
   ============================================================ */
.highlight {
    background: linear-gradient(transparent 62%, rgba(250, 204, 21, 0.55) 62%);
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
    color: inherit;
}

/* ============================================================
   响应式
   ============================================================ */

/* 中等屏：压缩间距 */
@media (max-width: 992px) {
    :root { --sidebar-w: 240px; }
    .main-header { padding: 0 24px; }
    .content-area { padding: 24px; }
    .search-form { width: 240px; }
    .tool-container { padding: 28px; }
}

/* 平板 + 手机：侧边栏抽屉化 */
@media (max-width: 768px) {
    body::before, body::after { display: none; }

    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }

    /* 抽屉打开时页面遮罩（使用 :has 现代选择器，无需改 HTML） */
    body:has(.sidebar.open) .main-content::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(15,23,42,0.45);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        z-index: 999;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .menu-toggle { display: flex; }

    .main-header {
        padding: 0 16px;
        height: 64px;
        gap: 12px;
    }
    .breadcrumb { font-size: 13px; }

    .search-form {
        width: auto;
        flex: 1;
        max-width: 210px;
        padding: 3px 3px 3px 14px;
    }
    .search-btn { padding: 7px 14px; font-size: 12.5px; }

    .content-area { padding: 20px 16px; }

    .page-header { padding: 12px 0 28px; }
    .page-header h1 { font-size: 26px; }

    /* 卡片：一行 2 个 */
    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .tool-card {
        padding: 16px 14px;
        gap: 6px;
        border-radius: var(--radius);
    }
    .tool-card h3 {
        font-size: 14px;
        line-height: 1.35;
    }
    .tool-card p {
        font-size: 12px;
        line-height: 1.5;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .tool-container {
        padding: 22px 18px;
        border-radius: var(--radius);
    }
    .tool-container h1 { font-size: 22px; }
    .tool-container .desc { font-size: 14px; margin-bottom: 22px; }

    .converter-grid { grid-template-columns: 1fr; }
    .converter-grid .swap-btn { grid-column: 1; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-item { padding: 14px 10px; }
    .stat-item .number { font-size: 22px; }

    .ad-banner { padding: 18px; margin-bottom: 22px; border-radius: var(--radius); }
}

/* 小手机 */
@media (max-width: 480px) {
    .search-form { max-width: 150px; }
    .search-input { font-size: 13px; }
    .logo-text { font-size: 16px; }
    .result-box { font-size: 18px; padding: 18px; }
    .tool-container h1 { font-size: 20px; }

    /* 小屏也保持一行 2 个，卡片更紧凑 */
    .tools-grid { gap: 8px; }
    .tool-card { padding: 14px 12px; }
    .tool-card h3 { font-size: 13px; }
    .tool-card p { font-size: 11.5px; -webkit-line-clamp: 2; }
}

/* 深色模式（跟随系统，可选，默认关闭） */
@media (prefers-color-scheme: dark) {
    /*
    :root {
        --bg: #0b1220;
        --bg-alt: #131c2e;
        --surface: #101a2b;
        --border: #1e293b;
        --border-light: #1a2436;
        --text: #e2e8f0;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
    }
    */
}