: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, "PingFang HK", "PingFang SC", "Microsoft YaHei", "Microsoft JhengHei", "Noto Sans HK", "Noto Sans TC", 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;
    position: relative;
    box-sizing: border-box;
}

[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;
    vertical-align: middle;
}

/* 收款連結列表不用截斷 */
[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: 0;
    }

    .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;
    }
}

/* ==========================================================================
   ADMIN PANEL ENHANCED LAYOUT & DESIGN SYSTEM
   ========================================================================== */

/* Overall Page Setup */
body.admin-body-page {
    padding: 20px;
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: visible; /* 避免與 html 的 overflow-y: auto 重疊造成雙滾動條與 sticky 偏移計算異常 */
}

/* Guest / Login Container */
.admin-login-wrapper {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.admin-login-wrapper .card {
    width: 100%;
    max-width: 440px;
    margin: auto;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    padding: 36px;
}

/* Admin Layout (Two Columns: Left Sidebar + Right Main) */
.admin-layout {
    display: flex;
    gap: 20px;
    width: 100%;
    max-width: 1560px;
    margin: 0 auto;
    align-items: stretch;
    flex: 1;
    position: relative;
}

/* Left Sidebar */
.admin-sidebar {
    width: 260px;
    min-width: 260px;
    flex-shrink: 0;
    align-self: flex-start; /* 防止 flex 容器 stretch 干擾 sticky 計算 */
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 20px;
    height: calc(100vh - 40px);
    z-index: 100;
    overflow: hidden; /* 確保四個角的 16px 圓角不被子元素直角背景覆蓋裁切 */
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease; /* 絕不對 top 或 all 做 transition，否則滾動時 sticky 計算會產生動畫延遲與空白放大 */
}

[data-theme="dark"] .admin-sidebar {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

/* Sidebar Brand Header - Height 72px matches Right Header 72px! */
.admin-brand {
    height: 72px;
    min-height: 72px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    box-sizing: border-box;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
}

.admin-brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.admin-logo-img {
    height: 36px;
    max-height: 38px;
    width: auto;
    object-fit: contain;
    display: block;
}

.admin-brand-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.admin-brand-title {
    font-size: 1.05em;
    font-weight: 800;
    letter-spacing: -0.2px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-brand-badge {
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary-color);
    background: rgba(74, 144, 226, 0.12);
    padding: 1px 7px;
    border-radius: 9999px;
    display: inline-block;
    width: fit-content;
}

[data-theme="dark"] .admin-brand-badge {
    background: rgba(187, 134, 252, 0.15);
}

/* Sidebar Navigation Menu */
.admin-menu {
    flex: 1;
    overflow-y: auto;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-menu-section-label {
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-color);
    opacity: 0.5;
    padding: 8px 12px 4px 12px;
    user-select: none;
}

.admin-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    border: 1px solid transparent;
}

.admin-menu-item:hover {
    background: var(--input-bg);
    color: var(--primary-color);
}

.admin-menu-item.active {
    background: rgba(74, 144, 226, 0.12);
    color: var(--primary-color);
    border-color: rgba(74, 144, 226, 0.2);
    font-weight: 800;
}

[data-theme="dark"] .admin-menu-item.active {
    background: rgba(187, 134, 252, 0.15);
    border-color: rgba(187, 134, 252, 0.25);
}

.admin-menu-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0.85;
    transition: transform 0.2s;
}

.admin-menu-item:hover .admin-menu-icon,
.admin-menu-item.active .admin-menu-icon {
    opacity: 1;
    transform: scale(1.08);
}

.admin-menu-text {
    flex: 1;
    font-size: 0.9em;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.admin-menu-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.admin-menu-item.active .admin-menu-indicator {
    opacity: 1;
}

/* Sidebar Footer */
.admin-sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--input-bg);
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-sizing: border-box;
    border-bottom-left-radius: 15px;
    border-bottom-right-radius: 15px;
}

.admin-sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.85em;
    opacity: 0.75;
    transition: all 0.2s ease;
}

.admin-sidebar-link:hover {
    opacity: 1;
    color: var(--primary-color);
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .admin-sidebar-link:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* Right Main Area */
.admin-main {
    flex: 1;
    min-width: 0; /* Critical: prevent flex child overflow */
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Top Header Bar - Height 72px matches Sidebar Brand 72px! */
.admin-header {
    height: 72px;
    min-height: 72px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
    position: sticky;
    top: 20px;
    z-index: 90;
    transition: box-shadow 0.3s ease, background-color 0.3s ease;
}

[data-theme="dark"] .admin-header {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.admin-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

/* Mobile Toggle Hamburger */
.admin-mobile-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    width: auto;
    height: 38px;
    align-items: center;
    justify-content: center;
}

.admin-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-bc-root {
    font-size: 0.9em;
    font-weight: 700;
    opacity: 0.6;
}

.admin-bc-sep {
    font-size: 0.85em;
    opacity: 0.35;
}

.admin-bc-current {
    font-size: 1.15em;
    font-weight: 800;
    color: var(--text-color);
}

.admin-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.admin-header-actions .theme-toggle {
    margin: 0;
    padding: 8px 14px;
    font-size: 0.88em;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    box-sizing: border-box;
}

.admin-logout-btn {
    width: auto;
    height: 38px;
    padding: 0 16px;
    background: transparent;
    color: var(--error-color);
    border: 1px solid var(--error-color);
    border-radius: 9999px;
    cursor: pointer;
    font-size: 0.88em;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-sizing: border-box;
}

.admin-logout-btn:hover {
    background: rgba(231, 76, 60, 0.1);
    color: var(--error-color);
}

/* Admin Content Body / Cards */
.admin-content-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    padding: 28px;
    min-height: calc(100vh - 132px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    box-sizing: border-box;
}

[data-theme="dark"] .admin-content-card {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

/* Admin Tab Panels */
.admin-panel {
    display: none;
}

.admin-panel.active {
    display: block;
    animation: adminPanelFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.admin-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 12px;
}

.admin-panel-title {
    font-size: 1.35em;
    font-weight: 800;
    margin: 0;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-panel-desc {
    font-size: 0.85em;
    color: var(--text-color);
    opacity: 0.6;
    margin-top: 4px;
    font-weight: 500;
}

/* Aligned Search / Filter Toolbar */
.admin-toolbar-form {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.admin-toolbar-input {
    flex: 1;
    min-width: 240px;
    height: 42px !important;
    line-height: 42px !important;
    padding: 0 16px !important;
    margin: 0 !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 10px !important;
    background: var(--input-bg) !important;
    color: var(--text-color) !important;
    font-size: 0.95em !important;
    outline: none !important;
    box-sizing: border-box !important;
    transition: all 0.2s ease;
}

.admin-toolbar-input:focus {
    border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15) !important;
}

.admin-toolbar-btn {
    width: auto !important;
    height: 42px !important;
    padding: 0 22px !important;
    border-radius: 10px !important;
    font-size: 0.92em !important;
    font-weight: 700 !important;
    background: var(--primary-color) !important;
    color: #fff !important;
    border: none !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    transition: background 0.2s ease, transform 0.1s ease;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.admin-toolbar-btn:hover {
    background: var(--primary-hover) !important;
}

.admin-toolbar-btn:active {
    transform: scale(0.98);
}

/* Admin Table Container & Styling */
.admin-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    margin-bottom: 20px;
    box-sizing: border-box;
}

.admin-table-wrapper table {
    width: 100%;
    margin-top: 0;
    table-layout: auto;
    border-collapse: collapse;
}

.admin-table-wrapper th {
    background: var(--input-bg);
    padding: 13px 16px;
    font-size: 0.85em;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.admin-table-wrapper td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
    font-size: 0.9em;
    white-space: nowrap;
}

.admin-table-wrapper tbody tr:last-child td {
    border-bottom: none;
}

.admin-table-wrapper tbody tr:hover {
    background: rgba(74, 144, 226, 0.04);
}

[data-theme="dark"] .admin-table-wrapper tbody tr:hover {
    background: rgba(187, 134, 252, 0.06);
}

/* Pagination Visual Alignment */
.admin-panel .pagination {
    margin-top: 15px;
    margin-bottom: 0;
    padding-bottom: 0;
    justify-content: flex-end;
}

/* Mobile Overlay Backdrop */
.admin-sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 95;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.admin-sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
    .admin-mobile-toggle {
        display: inline-flex;
    }

    .admin-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        border-radius: 0;
        transform: translateX(-105%);
        z-index: 100;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .admin-brand,
    .admin-sidebar-footer {
        border-radius: 0;
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    .admin-layout {
        flex-direction: column;
        gap: 16px;
    }

    .admin-content-card {
        padding: 20px;
    }

    .admin-header {
        padding: 0 16px;
        top: 8px;
    }
}