:root {
    --bg: #ebe7df;
    --bg-line: rgba(44, 42, 38, 0.06);
    --paper: #f7f5f0;
    --ink: #2c2a26;
    --ink-soft: #5c5850;
    --ink-muted: #8a8478;
    --line: #d8d3c8;
    --accent: #3d6b59;
    --accent-hover: #2f5546;
    --accent-soft: rgba(61, 107, 89, 0.1);
    --accent-2: #b85c38;
    --danger: #a33b2a;
    --danger-bg: #f8ebe8;
    --ok: #3d6b59;
    --ok-bg: #eef4f0;
    --shadow: 0 1px 0 rgba(44, 42, 38, 0.04), 0 8px 24px rgba(44, 42, 38, 0.06);
    --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --mono: "JetBrains Mono", "SF Mono", "Consolas", monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--ink);
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--bg-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--bg-line) 1px, transparent 1px);
    background-size: 24px 24px;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.head {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.head-back {
    font-family: var(--mono);
    font-size: 0.8125rem;
    color: var(--ink-muted);
    margin-bottom: 8px;
    display: inline-block;
}

.head h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
    font-weight: 600;
}

.head p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--ink-soft);
    line-height: 1.55;
    max-width: 42em;
}

.main-content {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.6fr) minmax(220px, 0.9fr);
    gap: 16px;
    align-items: start;
}

.add-key-section,
.codes-section,
.settings-section {
    background: var(--paper);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 20px;
}

.add-key-section h2,
.codes-section h2,
.settings-section h2 {
    margin: 0 0 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
    font-size: 0.8125rem;
    font-family: var(--mono);
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 18px;
}

.input-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: var(--font);
    background: #fff;
    color: var(--ink);
    transition: border-color 0.12s, box-shadow 0.12s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(61, 107, 89, 0.15);
}

.btn-primary,
.btn-secondary,
.btn-danger {
    font-family: var(--font);
    font-size: 0.8125rem;
    padding: 9px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.btn-primary {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-secondary {
    border: 1px solid var(--line);
    background: var(--paper);
    color: var(--ink);
}

.btn-secondary:hover {
    border-color: #c4bfb4;
    background: var(--bg);
}

.btn-danger {
    border: 1px solid var(--danger);
    background: var(--danger-bg);
    color: var(--danger);
}

.btn-danger:hover {
    background: #f0ddd8;
}

.migration-step-box {
    margin-bottom: 14px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    font-size: 0.8125rem;
    color: var(--ink-soft);
}

.migration-step-label {
    font-family: var(--mono);
    font-weight: 500;
    color: var(--accent);
    margin-right: 6px;
}

.qr-section {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.qr-section h3 {
    margin: 0 0 12px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ink);
}

.qr-section .desc {
    margin: 10px 0 0;
    font-size: 0.75rem;
    color: var(--ink-muted);
    line-height: 1.55;
}

.qr-section .desc kbd {
    font-family: var(--mono);
    font-size: 0.6875rem;
    padding: 1px 5px;
    border: 1px solid var(--line);
    background: var(--bg);
    border-radius: 2px;
}

.qr-upload-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#qrPreview img {
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 4px;
}

.codes-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 140px;
}

.search-wrap input {
    width: 100%;
    padding: 8px 28px 8px 11px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.8125rem;
    background: #fff;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.search-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(61, 107, 89, 0.15);
}

.search-wrap input::placeholder {
    color: var(--ink-muted);
}

.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    font-size: 16px;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: 2px;
}

.search-clear:hover {
    color: var(--accent);
    background: var(--accent-soft);
}

.codes-count {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--ink-muted);
    white-space: nowrap;
}

.codes-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.code-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 16px;
    position: relative;
    transition: border-color 0.12s;
    animation: fadeIn 0.35s ease;
}

.code-card:hover {
    border-color: #c4bfb4;
}

.code-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
    border-radius: 4px 4px 0 0;
}

.code-card--empty-search {
    text-align: center;
    color: var(--ink-muted);
    background: var(--bg);
}

.code-card--empty-search::before {
    display: none;
}

.code-card--empty-search .desc-hint {
    font-size: 0.75rem;
    margin-top: 6px;
    color: var(--ink-muted);
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
}

.pagination-bar .pagination-info {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--ink-muted);
    margin: 0 6px;
}

.pagination-bar .btn-page {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--paper);
    color: var(--ink);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}

.pagination-bar .btn-page:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.pagination-bar .btn-page:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.pagination-bar .btn-page.current {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 8px;
}

.code-name-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.code-name {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--ink);
    word-break: break-all;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 2px;
}

.code-name:hover {
    background: var(--accent-soft);
}

.code-name-edit {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 600;
}

.code-name-edit:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(61, 107, 89, 0.2);
}

.btn-edit-remark {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--bg);
    color: var(--ink-soft);
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}

.btn-edit-remark:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.code-time {
    font-family: var(--mono);
    font-size: 0.6875rem;
    color: var(--ink-muted);
    background: var(--bg);
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    white-space: nowrap;
}

.code-value {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--ink);
    text-align: center;
    font-family: var(--mono);
    letter-spacing: 0.12em;
    margin: 8px 0;
    user-select: all;
}

.code-progress {
    width: 100%;
    height: 3px;
    background: var(--line);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}

.code-progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 1s linear;
}

.code-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.code-actions button {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.copy-btn {
    background: var(--ok-bg);
    color: var(--ok);
    border-color: rgba(61, 107, 89, 0.35);
}

.copy-btn:hover {
    background: #e3ede7;
}

.delete-btn {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(163, 59, 42, 0.35);
}

.delete-btn:hover {
    background: #f0ddd8;
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.setting-item input,
.setting-item select {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 0.875rem;
    background: #fff;
}

.setting-item input:focus,
.setting-item select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(61, 107, 89, 0.15);
}

.setting-item:has(.btn-secondary):has(.btn-danger) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.setting-item:has(.btn-secondary):has(.btn-danger) .btn-secondary,
.setting-item:has(.btn-secondary):has(.btn-danger) .btn-danger {
    margin: 0;
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #fff;
    background: var(--ink);
    transform: translateX(120%);
    transition: transform 0.22s ease;
    z-index: 1000;
    max-width: min(360px, calc(100vw - 40px));
    box-shadow: var(--shadow);
}

.notification.show {
    transform: translateX(0);
}

.notification.success {
    background: var(--accent);
}

.notification.error {
    background: var(--danger);
}

.notification.info {
    background: var(--ink-soft);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .page {
        padding: 24px 16px 40px;
    }

    .code-value {
        font-size: 1.45rem;
        letter-spacing: 0.08em;
    }

    .notification {
        left: 16px;
        right: 16px;
        transform: translateY(-120%);
    }

    .notification.show {
        transform: translateY(0);
    }
}
