:root {
    --bg-color: #f4f7f6;
    --text-color: #333;
    --card-bg: #ffffff;
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --border-color: #e1e8ed;
    --error-color: #e74c3c;
    --success-color: #2ecc71;
    --input-bg: #f9f9f9;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --primary-color: #bb86fc;
    --primary-hover: #9c64e8;
    --border-color: #333;
    --input-bg: #2c2c2c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-weight: 800 !important;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar for all elements */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
    margin: 20px 0;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

html {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.container {
    width: 100%;
    max-width: 800px;
    margin: auto;
    /* Replaces body align-items center */
}

.dashboard-container {
    width: 100%;
    max-width: 1400px;
    /* Wider for full screen effect */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    align-items: stretch;
    margin: 40px auto;
    /* Centered with top margin */
}

.dashboard-container .nav {
    grid-column: 1 / -1;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dashboard-container .card {
    margin-bottom: 0;
    /* Let grid gap handle spacing */
    height: 100%;
    /* Make cards in same row equal height */
}

/* Make tables span full width */
.dashboard-container .card.full-width {
    grid-column: 1 / -1;
}

@media (max-width: 768px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

[data-theme="dark"] .card {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

h2,
h3 {
    margin-bottom: 35px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    opacity: 0.8;
}

input[type="email"],
input[type="password"],
input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 12px 20px;
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    background: var(--input-bg);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input:focus {
    border-color: var(--primary-color);
}

button {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.3s ease;
}

button:hover {
    background: var(--primary-hover);
}

button.secondary {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    margin-top: 10px;
}

button.secondary:hover {
    background: rgba(74, 144, 226, 0.1);
}

.theme-toggle {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 10px 15px;
    border-radius: 9999px;
    cursor: pointer;
    color: var(--text-color);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    width: auto;
}

.theme-toggle:hover {
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
}

.message {
    border-radius: 9999px;
    overflow: hidden;

    /* Hidden state */
    max-height: 0;
    opacity: 0;
    padding: 0 20px;
    /* horizontally keep it so it doesn't squish weirdly */
    margin-bottom: 0;
    border-width: 0;
    transform: translateY(-10px) scale(0.95);

    /* We use display block always, but hide it visually and dimensionally */
    display: block;
    transition: all 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message.show {
    /* Visible state */
    max-height: 200px;
    opacity: 1;
    padding: 12px 20px;
    margin-bottom: 15px;
    border-width: 1px;
    transform: translateY(0) scale(1);
}

.message.error {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error-color);
    border: 1px solid var(--error-color);
}

.message.success {
    background: rgba(46, 204, 113, 0.1);
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    table-layout: fixed;
}

th,
td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 收款链接列表不用截断 */
[data-mobile-page="page-links"] table th,
[data-mobile-page="page-links"] table td {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

/* Table Row Easing Animation */
tbody tr {
    opacity: 0;
    animation: rowFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes rowFadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

tbody tr:nth-child(1) {
    animation-delay: 0.00s;
}

tbody tr:nth-child(2) {
    animation-delay: 0.04s;
}

tbody tr:nth-child(3) {
    animation-delay: 0.08s;
}

tbody tr:nth-child(4) {
    animation-delay: 0.12s;
}

tbody tr:nth-child(5) {
    animation-delay: 0.16s;
}

tbody tr:nth-child(6) {
    animation-delay: 0.20s;
}

tbody tr:nth-child(7) {
    animation-delay: 0.24s;
}

tbody tr:nth-child(8) {
    animation-delay: 0.28s;
}

tbody tr:nth-child(9) {
    animation-delay: 0.32s;
}

tbody tr:nth-child(10) {
    animation-delay: 0.36s;
}

tbody tr:nth-child(11) {
    animation-delay: 0.40s;
}

tbody tr:nth-child(12) {
    animation-delay: 0.44s;
}

tbody tr:nth-child(n+13) {
    animation-delay: 0.48s;
}

th {
    opacity: 0.7;
    font-size: 0.9em;
}

.amount.positive {
    color: var(--success-color);
    font-weight: 600;
}

.amount.negative {
    color: var(--error-color);
    font-weight: 600;
}

.hidden {
    display: none !important;
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.balance-display {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--primary-color);
    margin: 10px 0 20px 0;
}

.desktop-narrow-form {
    flex: 1;
    min-width: 250px;
}

.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.nav a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

.nav a:hover {
    text-decoration: underline;
}

/* Spinner for loading */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes simpleFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.card:not(.hidden) {
    animation: simpleFadeIn 500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 500ms cubic-bezier(0.16, 1, 0.3, 1), visibility 500ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 30px;
    width: 90%;
    max-width: 460px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.modal.show .modal-content {
    transform: translateY(0);
}

.modal-content h3 {
    margin-bottom: 15px;
    text-align: center;
}

.modal-content .details {
    background: var(--input-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9em;
}

.modal-content .details p {
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.modal-content .details span {
    font-weight: 600;
    text-align: right;
    word-break: break-all;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions button {
    flex: 1;
    margin: 0;
}

/* Pagination Styles */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.pagination button {
    width: auto;
    padding: 8px 15px;
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination span {
    font-size: 0.9em;
    opacity: 0.8;
}

/* Bottom Navigation (Hidden on desktop) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

[data-theme="dark"] .bottom-nav {
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0;
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.3s, color 0.3s;
}

.bottom-nav .nav-item.active {
    opacity: 1;
    color: var(--primary-color);
}

.bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
}

.bottom-nav .nav-item span {
    font-size: 0.75rem;
}

@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .dashboard-container {
        margin: 20px auto 80px auto;
    }

    .dashboard-container .nav {
        padding: 15px;
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .card {
        padding: 15px;
    }

    /* 隐藏仅限桌面的元素 */
    .desktop-only {
        display: none !important;
    }

    /* 底部导航和分页切换 */
    .bottom-nav {
        display: flex;
    }

    .dashboard-container [data-mobile-page] {
        display: none !important;
    }

    .dashboard-container.show-page-home [data-mobile-page="page-home"],
    .dashboard-container.show-page-scan [data-mobile-page="page-scan"],
    .dashboard-container.show-page-transfer [data-mobile-page="page-transfer"],
    .dashboard-container.show-page-links [data-mobile-page="page-links"],
    .dashboard-container.show-page-wallet [data-mobile-page="page-wallet"] {
        display: block !important;
    }

    /* 调整表格、标题和表单的尺寸以更易触控 */
    th,
    td {
        padding: 10px 8px;
        font-size: 0.85em;
        white-space: nowrap;
    }

    td {
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    td button {
        display: none !important;
    }

    td:last-child,
    th:last-child {
        width: auto !important;
        max-width: 110px !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    h2 {
        font-size: 1.3em;
        margin-bottom: 12px;
    }

    h3 {
        font-size: 1.1em;
    }

    .balance-display {
        font-size: 1.8em;
        margin: 5px 0 10px 0;
    }

    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="text"],
    button {
        padding: 12px;
        font-size: 0.95em;
    }

    /* 隐藏滚动条但保留滚动功能 */
    * {
        scrollbar-width: none;
        /* Firefox */
        -ms-overflow-style: none;
        /* IE and Edge */
    }

    *::-webkit-scrollbar {
        display: none;
        /* Chrome, Safari, Opera */
    }
}

@keyframes spin-anim {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.icon-spin {
    animation: spin-anim 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Toast Notification */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--card-bg);
    color: var(--text-color);
    padding: 12px 24px;
    border-radius: 8px;
    /* Changed from pill to banner style */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 0.95em;
    font-weight: 500;
    opacity: 0;
    transform: translateX(50px) scale(0.95);
    /* Slide in from right */
    transition: all 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--primary-color);
}

.toast.show {
    opacity: 1;
    transform: translateX(0) scale(1);
}

.toast.error {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error-color);
    border-color: var(--error-color);
    border-left: 4px solid var(--error-color);
}

.toast.success {
    background: var(--success-color);
    color: #fff;
    border: none;
    border-left: 4px solid #27ae60;
}

/* --- DESKTOP SPA LOGIC --- */
@media (min-width: 769px) {
    .desktop-narrow-form {
        flex: 0 0 280px;
        align-self: flex-start;
        margin-top: 60px;
    }

    .dashboard-container {
        display: flex;
        flex-direction: column;
        gap: 20px;
        max-width: 1100px;
        margin: 15px auto 150px auto;
    }

    .dashboard-container [data-desktop-page] {
        display: none !important;
    }

    /* Always show home page on desktop */
    .dashboard-container [data-desktop-page="page-home"] {
        display: flex !important;
        animation: simpleFadeIn 400ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }

    /* Overlay for modal pages */
    .dashboard-container.show-d-page-transfer::before,
    .dashboard-container.show-d-page-wallet::before,
    .dashboard-container.show-d-page-links::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(8px);
        z-index: 100;
        animation: simpleFadeIn 0.3s ease;
    }

    /* Modal box styling for the 3 function pages */
    .dashboard-container.show-d-page-transfer [data-desktop-page="page-transfer"],
    .dashboard-container.show-d-page-wallet [data-desktop-page="page-wallet"],
    .dashboard-container.show-d-page-links [data-desktop-page="page-links"] {
        display: block !important;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 101;
        width: 95%;
        max-width: 1200px;
        max-height: 85vh;
        overflow-y: auto;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
        margin: 0;
        border: 1px solid var(--border-color);
        border-radius: 20px;
        animation: desktopModalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }

    /* Specific overrides for transfer window */
    .dashboard-container.show-d-page-transfer [data-desktop-page="page-transfer"] {
        max-width: 400px !important;
        height: 500px !important;
        /* 直接强制设定窗口高度 */
        padding: 30px !important;
    }

    /* Specific overrides for wallet (vouchers) window */
    .dashboard-container.show-d-page-wallet [data-desktop-page="page-wallet"] {
        max-width: 1150px !important;
    }

    /* Specific overrides for links window */
    .dashboard-container.show-d-page-links [data-desktop-page="page-links"] {
        height: 70vh !important;
        max-width: 1250px !important;
        /* 85vh 的四分之三约为 64vh */
    }

    @keyframes desktopModalSlideUp {
        from {
            opacity: 0;
            transform: translate(-50%, calc(-50% + 30px));
        }

        to {
            opacity: 1;
            transform: translate(-50%, -50%);
        }
    }

    /* Closing Animations */
    .dashboard-container.closing-modal::before {
        animation: simpleFadeOut 0.3s ease forwards;
    }

    .dashboard-container.closing-modal [data-desktop-page="page-transfer"],
    .dashboard-container.closing-modal [data-desktop-page="page-wallet"],
    .dashboard-container.closing-modal [data-desktop-page="page-links"] {
        animation: desktopModalSlideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }

    @keyframes desktopModalSlideDown {
        from {
            opacity: 1;
            transform: translate(-50%, -50%);
        }

        to {
            opacity: 0;
            transform: translate(-50%, calc(-50% + 30px));
        }
    }

    @keyframes simpleFadeOut {
        from {
            opacity: 1;
        }

        to {
            opacity: 0;
        }
    }
}

.desktop-func-btn-vertical {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: transparent;
    color: var(--text-color);
    border: none;
    border-radius: 0;
    padding: 35px 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    flex: 1;
}

.desktop-func-btn-vertical:not(:last-child)::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 1px;
    background: var(--border-color);
    z-index: 1;
}

.desktop-func-btn-vertical svg {
    width: 32px;
    height: 32px;
    stroke: currentColor;
    opacity: 0.8;
}

.desktop-func-btn-vertical span {
    font-size: 1.3em;
    font-weight: 600;
}

.desktop-func-btn-vertical:hover {
    background: var(--input-bg);
    color: var(--primary-color);
}

[data-theme="dark"] .desktop-func-btn-vertical:hover {
    box-shadow: none;
}

.desktop-close-btn {
    display: none;
    background: transparent;
    color: var(--text-color);
    border: none;
    padding: 0;
    margin-bottom: 20px;
    font-size: 1.1em;
    cursor: pointer;
    width: auto;
    opacity: 0.5;
    transition: opacity 0.3s, transform 0.2s;
    z-index: 10;
}

.desktop-close-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    background: transparent;
}

@media (min-width: 769px) {
    .desktop-close-btn {
        display: inline-flex;
        position: absolute;
        top: 20px;
        right: 20px;
        align-items: center;
        justify-content: center;
        margin: 0;
    }
}