/* Reset & base */
* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: #f5f7fa;
    color: #333;
    font-size: 14px;
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: #1f2937;
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    transition: margin-left 0.25s ease, transform 0.3s;
}

.sidebar.collapsed {
    margin-left: -240px;
}

.logo {
    padding: 18px 20px;
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid #374151;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 22px;
}

.menu {
    padding: 12px 0;
}

.menu-group {
    margin-bottom: 8px;
}

.menu-title {
    padding: 8px 20px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.menu-title:hover {
    color: #e5e7eb;
}

.menu-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.menu-group.closed .menu-arrow {
    transform: rotate(-90deg);
}

.menu-group.closed .menu-item {
    display: none;
}

.menu-item {
    display: block;
    padding: 9px 20px 9px 32px;
    color: #d1d5db;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: #374151;
    color: #fff;
}

.menu-item.active {
    background: #2563eb;
    color: #fff;
    border-left-color: #60a5fa;
}

/* Main */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.topbar {
    height: 56px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    padding: 0 20px;
    flex-shrink: 0;
}

.topbar h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.menu-toggle {
    display: block;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    margin-right: 12px;
    color: #374151;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
}

.menu-toggle:hover {
    background: #f3f4f6;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* Tool card */
.tool-card {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    max-width: 960px;
}

.tool-card h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 18px;
    color: #111827;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 12px;
}

.form-group.full {
    flex-basis: 100%;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #4b5563;
}

input[type="text"],
input[type="number"],
input[type="color"],
textarea,
select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: 'Consolas', 'Monaco', 'SF Mono', monospace;
    transition: border-color 0.2s, box-shadow 0.2s;
}

textarea {
    min-height: 140px;
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.checkbox-group label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    cursor: pointer;
}

/* Radio group */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.radio-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 400;
    font-size: 14px;
    transition: all 0.2s;
    background: #fff;
    color: #4b5563;
}

.radio-item:hover {
    border-color: #2563eb;
    background: #eff6ff;
}

.radio-item input[type="radio"] {
    display: none;
}

.radio-item:has(input:checked) {
    border-color: #2563eb;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 600;
}

/* Convert modules */
.convert-modules {
    display: flex;
    flex-direction: row;
    gap: 20px;
    margin-top: 8px;
}

.convert-module {
    flex: 1;
    min-width: 0;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
}

.convert-module h3 {
    margin: 0 0 16px;
    font-size: 15px;
    color: #111827;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.btn {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    margin-right: 8px;
    margin-bottom: 8px;
}

.btn:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #6b7280;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: #16a34a;
}

.btn-success:hover {
    background: #15803d;
}

.btn-danger {
    background: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
}

.result {
    margin-top: 16px;
    padding: 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    min-height: 48px;
    font-family: 'Consolas', 'Monaco', 'SF Mono', monospace;
    font-size: 13px;
    word-break: break-all;
    white-space: pre-wrap;
}

.result.error {
    color: #dc2626;
    background: #fef2f2;
    border-color: #fecaca;
}

.result.success {
    color: #16a34a;
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.result-area {
    display: flex;
    gap: 16px;
}

.result-area > div {
    flex: 1;
}

.result-label {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 500;
}

/* Diff */
.diff-container {
    display: flex;
    gap: 16px;
}

.diff-box {
    flex: 1;
}

.diff-line {
    padding: 2px 6px;
    font-family: monospace;
    font-size: 13px;
}

.diff-added { background: #d1fae5; color: #065f46; }
.diff-removed { background: #fee2e2; color: #991b1b; }
.diff-unchanged { color: #6b7280; }

/* Markdown preview */
.markdown-preview {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 16px;
    background: #fff;
    min-height: 160px;
}

.markdown-preview h1, .markdown-preview h2, .markdown-preview h3 {
    margin-top: 0;
}

.markdown-preview code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
}

.markdown-preview pre code {
    display: block;
    padding: 12px;
    overflow-x: auto;
}

/* QR Code */
#qrcode-canvas {
    margin-top: 16px;
}

/* IP info */
.info-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.info-table th,
.info-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
}

.info-table th {
    background: #f9fafb;
    color: #4b5563;
    font-weight: 600;
    width: 140px;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.dashboard-card {
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    text-decoration: none;
    color: #374151;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: transform 0.15s, box-shadow 0.15s;
}

.dashboard-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.dashboard-card .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.dashboard-card .name {
    font-size: 14px;
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        margin-left: 0;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .menu-toggle {
        display: block;
    }
    .content {
        padding: 16px;
    }
    .diff-container,
    .result-area {
        flex-direction: column;
    }
}

/* 密码生成：滑块 / 强度 / 历史记录 */
.hint {
    margin: -4px 0 16px;
    font-size: 13px;
    color: #6b7280;
}

.range-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-row input[type="range"] {
    flex: 1;
    min-width: 120px;
    accent-color: #2563eb;
}

.range-row input[type="number"] {
    width: 84px;
    flex-shrink: 0;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    margin: 0;
}

.strength-wrap {
    margin-top: 14px;
}

.strength-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0;
    background: #16a34a;
    transition: width 0.25s, background 0.25s;
}

.strength-text {
    margin-top: 6px;
    font-size: 13px;
    color: #4b5563;
}

.history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.history-head h3 {
    margin: 0;
    font-size: 16px;
    color: #111827;
}

.history-count {
    display: inline-block;
    min-width: 20px;
    padding: 1px 7px;
    margin-left: 6px;
    border-radius: 10px;
    background: #e5e7eb;
    color: #4b5563;
    font-size: 12px;
    font-weight: 600;
    vertical-align: middle;
}

.history-list {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.history-pwd {
    flex: 1;
    min-width: 0;
    font-family: 'Consolas', 'Monaco', 'SF Mono', monospace;
    font-size: 13px;
    color: #111827;
    word-break: break-all;
}

.history-meta {
    flex-shrink: 0;
    font-size: 12px;
    color: #9ca3af;
}

.history-actions {
    flex-shrink: 0;
    display: flex;
    gap: 6px;
}

.history-empty {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    background: #f9fafb;
    border: 1px dashed #e5e7eb;
    border-radius: 6px;
}

@media (max-width: 768px) {
    .history-item {
        flex-wrap: wrap;
    }
    .history-pwd {
        flex-basis: 100%;
    }
}
