/* ============================================================
   ZeroPass · v20.5 – 可滚动，输入在上输出在下
   - 移除所有高度截断限制
   - 移动端恢复自然文档顺序
   - 全局可滚动
   ============================================================ */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-app: #f1f4f8;
    --bg-surface: #ffffff;
    --bg-input: #ffffff;
    --border-color: #e2e8f0;
    --border-focus: #4f46e5;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-subtle: rgba(79, 70, 229, 0.08);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.08);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --font:
        -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto,
        "Inter", sans-serif;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Strength gradient */
    --strength-start: #ef4444;
    --strength-mid: #f59e0b;
    --strength-end: #10b981;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    font-size: 1rem;
    background: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: flex-start; /* 改为 flex-start，内容从顶部开始 */
    justify-content: center;
    padding: 20px;
    margin: 0;
    line-height: 1.5;
    /* 允许 body 滚动 */
    overflow-y: auto;
}

/* ---------- App container：不再固定高度，由内容撑开 ---------- */
.app {
    width: 100%;
    max-width: 520px;
    min-height: 500px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    position: relative;
    /* 移除 max-height 和 overflow:hidden，让内容自然撑开，页面可滚动 */
}

/* ---------- Header ---------- */
.app-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 72px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 6px 12px 6px 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.header-left:hover {
    background: var(--brand-subtle);
}
.header-logo {
    width: 36px;
    height: 36px;
    display: block;
    flex-shrink: 0;
}
.header-brand {
    font-size: 2rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.header-title {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-tertiary);
    letter-spacing: 0.3px;
}
.header-right .version-badge {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-app);
    padding: 3px 12px;
    border-radius: var(--radius-full);
}

/* ---------- Main ---------- */
.app-main {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    padding: 20px 20px 16px;
    gap: 16px;
    background: var(--bg-app);
}

.capture-container {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

/* ---------- Input ---------- */
.input-area {
    flex-shrink: 0;
}

.input-card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: 20px 24px 24px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.input-card-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}
.input-card-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
}
.input-card-header .subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin: 0;
    font-style: italic;
}

.input-card-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.field label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}
.field input[type="text"],
.field input[type="number"] {
    padding: 10px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--bg-input);
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
    outline: none;
    font-family: var(--font);
    width: 100%;
    color: var(--text-primary);
    height: 48px;
}
.field input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px var(--brand-subtle);
}
.field input.default-text {
    color: var(--text-tertiary);
}
.field input:not(.default-text) {
    color: var(--text-primary);
}

/* Combo box */
.combo-box {
    position: relative;
    display: flex;
    align-items: center;
}
.combo-box input[type="text"] {
    padding-right: 44px;
}
.combo-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.3rem;
    transition:
        background var(--transition),
        color var(--transition);
}
.combo-toggle:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.combo-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    padding: 6px 0;
    list-style: none;
}
.combo-menu.open {
    display: block;
}
.combo-menu li {
    padding: 10px 16px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
    color: var(--text-primary);
    font-weight: 400;
}
.combo-menu li:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.combo-menu li:active {
    background: var(--brand);
    color: #fff;
}

/* Buttons */
.action-row-buttons {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.action-row-buttons .btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    letter-spacing: 0.3px;
}
.action-row-buttons .btn.primary {
    background: var(--brand);
    color: #fff;
    flex: 2;
}
.action-row-buttons .btn.primary:hover {
    background: var(--brand-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.3);
}
.action-row-buttons .btn.primary:active {
    transform: scale(0.97);
}
.action-row-buttons .btn.secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
    flex: 1;
}
.action-row-buttons .btn.secondary:hover {
    background: var(--bg-app);
    border-color: var(--text-tertiary);
}
.action-row-buttons .btn.secondary:active {
    transform: scale(0.97);
}

/* ---------- Output ---------- */
.output-area {
    flex: 0 0 auto;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary);
    width: 100%;
    padding: 20px 0;
}
.placeholder i {
    font-size: 3rem;
    opacity: 0.3;
}
.placeholder p {
    font-size: 1rem;
    color: var(--text-secondary);
}
.placeholder p strong {
    font-weight: 600;
    color: var(--text-primary);
}

#resultView {
    width: 100%;
}

.result-view {
    width: 100%;
    display: flex;
    flex-direction: column;
}
.result-view .result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    border-bottom: 1.5px solid var(--border-color);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}
.result-view .result-header .result-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}
.result-view .result-header .result-actions {
    display: flex;
    gap: 8px;
}
.result-view .result-header .result-actions .action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: transparent;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}
.result-view .result-header .result-actions .action-btn:hover {
    background: var(--brand-subtle);
    border-color: var(--brand);
    color: var(--brand);
}
.result-view .result-header .result-actions .action-btn:active {
    transform: scale(0.94);
}
.result-view .result-header .result-actions .action-btn.copied {
    color: var(--text-tertiary);
    border-color: var(--border-color);
    pointer-events: none;
}
.result-view .result-header .result-actions .action-btn i {
    font-size: 0.85rem;
}

.result-view .result-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 12px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    gap: 16px;
}
.result-row .label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    min-width: 80px;
}
.result-row .value {
    font-size: 1rem;
    color: var(--text-primary);
    text-align: right;
    word-break: break-all;
    font-family: "SF Mono", "Fira Code", monospace;
}

.result-row .value.password {
    color: var(--brand);
    font-weight: 800;
    font-size: 1.6rem;
    flex: 1;
    letter-spacing: 0.5px;
    line-height: 1.3;
}

/* Strength bar */
.strength-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}
.strength-bar-track {
    flex: 1;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--border-color);
    overflow: hidden;
    position: relative;
}
.strength-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: var(--radius-full);
    background: linear-gradient(
        to right,
        var(--strength-start),
        var(--strength-mid),
        var(--strength-end)
    );
    transition: width 0.6s ease;
}
.strength-info {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-shrink: 0;
}
.strength-label {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 40px;
}
.strength-entropy {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ---------- History ---------- */
.history-area {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}
.history-header span i {
    margin-right: 6px;
}
.history-header-actions {
    display: flex;
    gap: 8px;
}
.history-clear,
.history-show-all {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.history-clear:hover,
.history-show-all:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 8px;
    max-height: 160px;
    overflow-y: auto;
}
.history-list::-webkit-scrollbar {
    width: 3px;
}
.history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-app);
    cursor: default;
    transition: background var(--transition);
    font-size: 1rem;
}
.history-item:hover {
    background: var(--brand-subtle);
}
.history-item .h-left {
    flex: 0 0 50%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}
.history-item .h-domain {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item .h-identity {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item .h-actions {
    flex: 0 0 50%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: 0;
}
.history-item .h-pwd {
    font-family: "SF Mono", monospace;
    font-size: 0.875rem;
    color: var(--brand);
    font-weight: 600;
    word-break: break-word;
    white-space: normal;
    overflow: visible;
    max-width: none;
    flex: 1;
    text-align: right;
}
.history-item .h-copy-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.history-item .h-copy-btn:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.history-item .h-copy-btn.copied {
    color: var(--text-tertiary);
    pointer-events: none;
}

.history-empty {
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    padding: 12px 0;
    font-style: italic;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.modal-overlay.active {
    display: flex;
    opacity: 1;
}
.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 80%;
    height: 80%;
    max-width: 800px;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content {
    transform: scale(1);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1.5rem;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}
.modal-body .history-item {
    background: var(--bg-app);
    margin-bottom: 6px;
}
.modal-body .history-item:hover {
    background: var(--brand-subtle);
}
.modal-body::-webkit-scrollbar {
    width: 6px;
}
.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- Footer ---------- */
.app-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 48px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}
.footer-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.footer-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    transition: all var(--transition);
    text-decoration: none;
}
.footer-link:hover {
    background: var(--brand-subtle);
    color: var(--brand);
}
.footer-link i {
    font-size: 1rem;
}
.footer-right {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    padding: 10px 24px;
    background: var(--text-primary);
    backdrop-filter: blur(16px);
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s ease;
    box-shadow: var(--shadow-md);
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Mobile adjustments – 自然滚动，输入在上输出在下
   ============================================================ */
@media (max-width: 720px) {
    body {
        padding: 0;
        background: var(--bg-app);
        align-items: flex-start;
    }

    .app {
        max-width: 100%;
        min-height: 100vh; /* 至少占满视口高度，但内容多时可滚动 */
        border-radius: 0;
        box-shadow: none;
        /* 移除 height:100vh 和 overflow:hidden，允许滚动 */
    }

    .app-header {
        padding: 0 16px;
        height: 64px;
    }
    .header-logo {
        width: 32px;
        height: 32px;
    }
    .header-brand {
        font-size: 1.6rem;
    }
    .header-title {
        font-size: 0.875rem;
    }
    .header-right .version-badge {
        font-size: 0.7rem;
        padding: 2px 10px;
    }

    .app-main {
        padding: 16px 16px 12px;
        gap: 14px;
        /* 移除 overflow:hidden，让内容可滚动 */
    }

    .capture-container {
        gap: 14px;
    }

    /* 输入区在上，输出区在下（移除 order 调换） */
    .input-area {
        order: 0;
        flex-shrink: 0;
    }
    .output-area {
        order: 0; /* 保持正常文档顺序 */
        flex: 0 0 auto;
        padding: 16px 20px;
    }
    .history-area {
        order: 0;
    }

    .input-card {
        padding: 16px 18px 18px;
    }
    .input-card-header h2 {
        font-size: 1.3rem;
    }
    .input-card-header .subtitle {
        font-size: 0.875rem;
    }
    .input-card-body {
        gap: 12px;
    }
    .field label {
        font-size: 0.875rem;
    }
    .field input[type="text"],
    .field input[type="number"] {
        font-size: 1rem;
        height: 44px;
        padding: 8px 12px;
    }
    .action-row-buttons .btn {
        font-size: 0.875rem;
        height: 44px;
    }

    .result-view .result-header .result-title {
        font-size: 1.1rem;
    }
    .result-view .result-header .result-actions .action-btn {
        font-size: 0.75rem;
        padding: 4px 10px;
    }
    .result-row .label {
        font-size: 0.875rem;
        min-width: 60px;
    }
    .result-row .value {
        font-size: 0.875rem;
    }
    .result-row .value.password {
        font-size: 1.3rem;
    }

    .strength-bar-track {
        height: 5px;
    }
    .strength-label {
        font-size: 0.75rem;
        min-width: 32px;
    }
    .strength-entropy {
        font-size: 0.65rem;
    }

    .history-item {
        font-size: 0.875rem;
        padding: 4px 8px;
    }
    .history-item .h-left {
        flex: 0 0 50%;
    }
    .history-item .h-actions {
        flex: 0 0 50%;
    }
    .history-item .h-pwd {
        font-size: 0.75rem;
    }
    .history-item .h-identity {
        font-size: 0.75rem;
    }

    .modal-content {
        width: 90%;
        height: 80%;
        max-height: 90vh;
        border-radius: var(--radius-md);
    }
    .modal-body {
        padding: 12px 16px;
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
    .modal-body::-webkit-scrollbar {
        width: 0;
        background: transparent;
    }

    .app-footer {
        padding: 0 16px;
        height: 44px;
    }
    .footer-left {
        gap: 12px;
    }
    .footer-link {
        width: 24px;
        height: 24px;
    }
    .footer-link i {
        font-size: 0.9rem;
    }
    .footer-right {
        font-size: 0.65rem;
    }

    .toast {
        bottom: 20px;
        padding: 8px 20px;
        font-size: 0.875rem;
    }
}

@media (max-width: 400px) {
    .app-header {
        padding: 0 12px;
        height: 56px;
    }
    .header-logo {
        width: 28px;
        height: 28px;
    }
    .header-brand {
        font-size: 1.4rem;
    }
    .header-title {
        font-size: 0.75rem;
    }

    .app-main {
        padding: 12px 12px 10px;
        gap: 10px;
    }
    .capture-container {
        gap: 10px;
    }

    .input-card {
        padding: 12px 14px 14px;
    }
    .input-card-header h2 {
        font-size: 1.1rem;
    }
    .input-card-header .subtitle {
        font-size: 0.75rem;
    }
    .field input[type="text"],
    .field input[type="number"] {
        font-size: 0.875rem;
        height: 40px;
        padding: 6px 10px;
    }
    .action-row-buttons .btn {
        font-size: 0.8rem;
        height: 40px;
        padding: 4px 10px;
    }

    .output-area {
        padding: 12px 14px;
    }

    .result-row .label {
        font-size: 0.75rem;
        min-width: 50px;
    }
    .result-row .value {
        font-size: 0.8rem;
    }
    .result-row .value.password {
        font-size: 1.1rem;
    }

    .history-item .h-pwd {
        font-size: 0.65rem;
    }

    .app-footer {
        height: 40px;
        padding: 0 12px;
    }
    .footer-right {
        font-size: 0.6rem;
    }
}
