/* ============================================
   2FA Manager - Styles
   深色/浅色双主题，响应式设计
   ============================================ */

/* --- CSS 变量：主题定义 --- */
:root {
    /* 浅色主题（默认） */
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --bg-card: #ffffff;
    --bg-input: #f0f2f5;
    --bg-modal-overlay: rgba(0, 0, 0, 0.5);
    --bg-hover: #e8eaed;
    --bg-code: #f0f4ff;

    --text-primary: #1a1a2e;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --text-code: #1a73e8;

    --border-color: #e0e0e0;
    --border-focus: #1a73e8;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --accent-light: #e8f0fe;
    --danger: #d93025;
    --danger-hover: #b3261e;
    --success: #188038;
    --warning: #f9ab00;
    --progress-bg: #e0e0e0;
    --progress-fill: #1a73e8;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-mono: 'SF Mono', 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
}

/* 深色主题 */
[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-secondary: #1e1e2e;
    --bg-tertiary: #2a2a3e;
    --bg-card: #1e1e2e;
    --bg-input: #2a2a3e;
    --bg-modal-overlay: rgba(0, 0, 0, 0.7);
    --bg-hover: #333350;
    --bg-code: #1a2744;

    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --text-muted: #5f6368;
    --text-code: #8ab4f8;

    --border-color: #333350;
    --border-focus: #8ab4f8;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    --accent: #8ab4f8;
    --accent-hover: #aecbfa;
    --accent-light: #1a2744;
    --progress-bg: #333350;
    --progress-fill: #8ab4f8;
}

/* --- 锁屏界面 --- */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    padding: 20px;
    transition: opacity 0.4s ease;
}

.lock-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.lock-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 40px 32px 32px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.4s ease;
}

.lock-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    color: var(--accent);
}

.lock-icon svg {
    width: 100%;
    height: 100%;
}

.lock-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.lock-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.lock-form,
.lock-setup {
    text-align: left;
}

.lock-form input[type="password"],
.lock-setup input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-family);
    outline: none;
    transition: border-color 0.2s ease;
    margin-bottom: 12px;
}

.lock-form input[type="password"]:focus,
.lock-setup input[type="password"]:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.lock-error {
    font-size: 0.85rem;
    color: var(--danger);
    margin-bottom: 12px;
    min-height: 1.2em;
    display: none;
}

.lock-error.active {
    display: block;
}

.lock-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    margin-bottom: 12px;
}

.lock-hint {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* --- 全局重置 --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- 布局 --- */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- 头部 --- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    white-space: nowrap;
}

.app-title .shield-icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- 搜索框 --- */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box input {
    width: 200px;
    padding: 8px 12px 8px 36px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
    outline: none;
}

.search-box input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.search-box .search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
    pointer-events: none;
}

/* --- 按钮 --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: var(--font-family);
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 50%;
    width: 36px;
    height: 36px;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-sm {
    padding: 4px 12px;
    font-size: 0.8rem;
}

/* --- 账号分组 --- */
.group-section {
    margin-bottom: 12px;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    margin-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.group-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
}

.group-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.group-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: auto;
}

.group-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
}

/* --- 编码格式检测标签 --- */
.encoding-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 10px;
    margin-top: 4px;
    transition: all 0.2s ease;
}

.encoding-base32 {
    background: #e8f5e9;
    color: #2e7d32;
}

.encoding-hex {
    background: #fff3e0;
    color: #e65100;
}

.encoding-base64 {
    background: #e3f2fd;
    color: #1565c0;
}

.encoding-text {
    background: #f3e5f5;
    color: #7b1fa2;
}

[data-theme="dark"] .encoding-base32 {
    background: #1b3a1d;
    color: #66bb6a;
}

[data-theme="dark"] .encoding-hex {
    background: #3a2a1b;
    color: #ffa726;
}

[data-theme="dark"] .encoding-base64 {
    background: #1a2744;
    color: #64b5f6;
}

[data-theme="dark"] .encoding-text {
    background: #2a1b3a;
    color: #ce93d8;
}

/* --- 建议下拉框 --- */
.suggestion-group {
    position: relative;
}

.suggestion-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 200px;
    overflow-y: auto;
    display: none;
    margin-top: 2px;
}

.suggestion-list.active {
    display: block;
}

.suggestion-item {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s ease;
}

.suggestion-item:hover {
    background: var(--bg-hover);
}

.suggestion-item:first-child {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.suggestion-item:last-child {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* --- 卡片备注 --- */
.account-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 3px;
    padding-top: 3px;
    border-top: 1px dashed var(--border-color);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- 账号卡片网格 (分组模式) --- */
.accounts-grid {
    flex: 1;
}

/* --- 单个卡片 --- */
.account-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    animation: cardFadeIn 0.3s ease;
}

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

.account-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.account-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.account-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: #ffffff;
    flex-shrink: 0;
}

.account-info {
    flex: 1;
    min-width: 0;
}

.account-issuer {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-name {
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.account-card-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.account-card:hover .account-card-actions {
    opacity: 1;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.action-btn.delete-btn:hover {
    color: var(--danger);
}

/* --- TOTP 验证码显示 --- */
.totp-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
}

.totp-code {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--text-code);
    cursor: pointer;
    user-select: all;
    transition: color 0.15s ease;
}

.totp-code:hover {
    opacity: 0.85;
}

.totp-code.copied {
    color: var(--success);
}

/* --- 倒计时进度条 --- */
.totp-timer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.progress-ring {
    position: relative;
    width: 40px;
    height: 40px;
}

.progress-ring svg {
    transform: rotate(-90deg);
}

.progress-ring .bg {
    fill: none;
    stroke: var(--progress-bg);
    stroke-width: 3;
}

.progress-ring .fill {
    fill: none;
    stroke: var(--progress-fill);
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.3s linear, stroke 0.3s ease;
}

.progress-ring .fill.warning {
    stroke: var(--warning);
}

.progress-ring .fill.danger {
    stroke: var(--danger);
}

.progress-ring .time-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

/* --- 空状态 --- */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 300px;
    line-height: 1.5;
}

/* --- 模态框 --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-modal-overlay);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: visible;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
    display: flex;
    flex-direction: column;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 24px 20px;
}

/* --- 表单 --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-family);
    transition: all 0.2s ease;
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group .hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-group .error-text {
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 4px;
    display: none;
}

.form-group.has-error input {
    border-color: var(--danger);
}

.form-group.has-error .error-text {
    display: block;
}

/* --- Tab 切换 --- */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.tab-btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-family);
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* --- QR 扫描区域 --- */
.qr-scanner-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto 16px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    position: relative;
}

.qr-scanner-container video {
    width: 100%;
    display: block;
}

.qr-scanner-container #qr-reader {
    border: none !important;
}

.qr-scanner-container #qr-reader__dashboard_section_csr {
    display: flex !important;
    justify-content: center !important;
    padding: 8px !important;
}

#qr-reader__dashboard_section_csr button,
#qr-reader__dashboard_section_csr span {
    font-family: var(--font-family) !important;
}

/* --- 粘贴 URI 输入 --- */
.uri-paste-area {
    margin-top: 16px;
}

.uri-paste-area textarea {
    width: 100%;
    height: 80px;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-mono);
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
}

.uri-paste-area textarea:focus {
    border-color: var(--border-focus);
}

/* --- Toast 通知 --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    font-weight: 500;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.2s;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

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

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

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

/* --- 底部状态栏 --- */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.app-footer .footer-actions {
    display: flex;
    gap: 8px;
}

/* --- 响应式 --- */
@media (max-width: 640px) {
    .app-container {
        padding: 12px;
    }

    .app-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .app-title {
        font-size: 1.25rem;
    }

    .header-actions {
        justify-content: space-between;
    }

    .search-box input {
        width: 100%;
    }

    .search-box {
        flex: 1;
    }

    .group-cards {
        grid-template-columns: 1fr;
    }

    .account-card {
        padding: 16px;
    }

    .totp-code {
        font-size: 1.6rem;
    }

    .modal {
        max-width: 100%;
        margin: 10px;
        border-radius: var(--radius-lg);
    }

    .modal-body {
        padding: 16px 20px;
    }

    .empty-state {
        padding: 40px 16px;
    }
}

/* --- 滚动条美化 --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- 更多选项区域 --- */
.more-actions {
    margin-top: 16px;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.more-actions summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.more-actions summary:hover {
    color: var(--text-primary);
}

.import-export-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
