/* Custom styles to complement Tailwind */
:root {
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* Custom Mesh Gradient Background */
body {
    background-image: 
        radial-gradient(at 0% 0%, hsla(210,100%,95%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,100%,95%,1) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,100%,95%,1) 0, transparent 50%);
    background-attachment: fixed;
}

/* Hide scrollbar but keep functionality */
.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
    animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Top table */
.top-table-wrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
    --top-thead-h: 3.5rem;
    --top-row-h: 4rem;
    --top-visible-rows: 30;
    max-height: calc(var(--top-thead-h) + var(--top-row-h) * var(--top-visible-rows));
    border-radius: 1rem;
    border: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.35);
}

.top-table {
    width: 100%;
    min-width: 580px;
    border-collapse: separate;
    border-spacing: 0;
}

.top-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
    vertical-align: bottom;
    box-shadow: 0 1px 0 #e2e8f0;
}

.top-table thead th.col-sticky-left {
    left: 0;
    z-index: 6;
}

.top-table thead th.col-sticky-left-2 {
    left: 3rem;
    z-index: 6;
    box-shadow: 4px 0 8px -4px rgba(15, 23, 42, 0.06);
}

.top-table tbody td.col-sticky-left,
.top-table tbody td.col-sticky-left-2 {
    position: sticky;
    z-index: 1;
    background: #fff;
}

.top-table tbody td.col-sticky-left {
    left: 0;
}

.top-table tbody td.col-sticky-left-2 {
    left: 3rem;
    box-shadow: 4px 0 8px -4px rgba(15, 23, 42, 0.08);
}

.top-table tbody tr:hover td.col-sticky-left,
.top-table tbody tr:hover td.col-sticky-left-2 {
    background: #f8fafc;
}

.top-table thead th.col-amount {
    text-align: right;
}

.top-th-name {
    display: block;
    font-size: 0.6875rem;
    line-height: 1.3;
    text-transform: none;
    letter-spacing: normal;
    max-width: 7rem;
    white-space: normal;
}

.top-th-unit {
    display: block;
    font-size: 0.625rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: lowercase;
    margin-top: 0.125rem;
}

.top-table tbody td {
    padding: 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(241, 245, 249, 0.9);
    font-size: 0.875rem;
    color: #334155;
    background: rgba(255, 255, 255, 0.65);
}

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

.top-table tbody tr:hover td {
    background: rgba(248, 250, 252, 0.95);
}

.top-table .col-rank {
    width: 3rem;
    text-align: center;
}

.top-table .col-name {
    min-width: 9rem;
}

.top-table .col-region {
    min-width: 6rem;
    color: #64748b;
    font-size: 0.8125rem;
}

.top-table .col-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: #cbd5e1;
    min-width: 4.5rem;
}

.top-table .col-total {
    min-width: 5.5rem;
    border-left: 1px solid #e2e8f0;
}

.top-table thead th.col-total {
    background: #f1f5f9;
}

.top-table thead th.col-total .top-th-name {
    color: #0f172a;
}

.top-table .col-total.has-value {
    color: #0f172a;
    font-weight: 800;
}

.top-table thead th.cat-color-0 .top-th-name { color: #4f46e5; }
.top-table thead th.cat-color-1 .top-th-name { color: #059669; }
.top-table thead th.cat-color-2 .top-th-name { color: #d97706; }
.top-table thead th.cat-color-3 .top-th-name { color: #e11d48; }
.top-table thead th.cat-color-4 .top-th-name { color: #0284c7; }

.top-table .cat-color-0.has-value { color: #4f46e5; }
.top-table .cat-color-1.has-value { color: #059669; }
.top-table .cat-color-2.has-value { color: #d97706; }
.top-table .cat-color-3.has-value { color: #e11d48; }
.top-table .cat-color-4.has-value { color: #0284c7; }

.top-rank {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    font-weight: 800;
    background: #f1f5f9;
    color: #64748b;
}

.top-rank.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #fff;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.top-rank.silver {
    background: linear-gradient(135deg, #e2e8f0, #94a3b8);
    color: #fff;
}

.top-rank.bronze {
    background: linear-gradient(135deg, #fdba74, #ea580c);
    color: #fff;
}

.top-name-main {
    font-weight: 700;
    color: #1e293b;
    line-height: 1.3;
}

.top-name-sub {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.4;
}

@media (max-width: 640px) {
    .top-table-wrap {
        --top-row-h: 3.5rem;
        max-height: min(85vh, calc(var(--top-thead-h) + var(--top-row-h) * var(--top-visible-rows)));
    }

    .top-table .col-region {
        display: none;
    }
    .top-table thead th.col-region {
        display: none;
    }
    .top-table {
        min-width: 420px;
    }
}

/* Date range picker */
.date-range-picker {
    position: relative;
    z-index: 10;
}
.date-range-picker.is-open {
    z-index: 50;
}
.date-range-dropdown {
    z-index: 50;
}
.history-filters {
    position: relative;
    z-index: 40;
}
#history-content {
    position: relative;
    z-index: 0;
}

/* Practice amounts box */
.practice-amounts-box {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.practice-amount-row:last-child {
    padding-bottom: 0;
}
.practice-amount-row:first-child {
    padding-top: 0;
}

#history-section .glass-panel {
    overflow: visible;
}

.date-preset-btn,
.top-preset-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #475569;
    background: #fff;
    text-align: center;
    transition: all 0.15s ease;
    cursor: pointer;
}
.date-preset-btn:hover,
.top-preset-btn:hover {
    border-color: #93c5fd;
    background: #f8fafc;
}
.date-preset-btn.active,
.top-preset-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

/* Admin layout — prevent flex overflow */
.admin-main {
    min-width: 0;
    max-width: 100%;
}

/* Admin logs table */
.admin-logs-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.admin-logs-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}

.admin-logs-table th,
.admin-logs-table td {
    padding: 0.625rem 0.75rem;
    vertical-align: top;
    font-size: 0.8125rem;
}

.admin-logs-table thead th {
    font-size: 0.625rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    background: rgba(248, 250, 252, 0.8);
    white-space: nowrap;
}

.admin-logs-table .col-id { width: 3rem; }
.admin-logs-table .col-time { width: 4.5rem; }
.admin-logs-table .col-user { width: 24%; min-width: 7rem; }
.admin-logs-table .col-meta { width: 18%; min-width: 6rem; }
.admin-logs-table .col-dedication { width: 14%; min-width: 5.5rem; max-width: 9rem; }
.admin-logs-table .col-amount { width: 5.5rem; }
.admin-logs-table .col-actions { width: 5rem; }

.admin-logs-table .log-dedication-preview {
    display: block;
    width: 100%;
    max-width: 100%;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
    line-height: 1.4;
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 0;
    transition: color 0.15s ease;
}

.admin-logs-table .log-dedication-preview:hover {
    color: #2563eb;
    text-decoration: underline;
}

.admin-logs-table .cell-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-logs-table .log-name {
    font-weight: 700;
    color: #1e293b;
    line-height: 1.3;
}

.admin-logs-table .log-sub {
    font-size: 0.6875rem;
    color: #94a3b8;
    line-height: 1.4;
    margin-top: 0.125rem;
}

.admin-logs-table .log-amount {
    font-weight: 800;
    color: #334155;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.admin-logs-table .log-unit {
    font-size: 0.625rem;
    font-weight: 600;
    color: #94a3b8;
}

.admin-logs-table .log-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.5625rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.admin-logs-table .log-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

.admin-logs-table .log-actions button,
.admin-logs-table .log-actions form {
    flex-shrink: 0;
}

.admin-logs-table .log-actions button {
    padding: 0.375rem;
    border-radius: 0.625rem;
}

.admin-logs-table .log-actions svg {
    width: 1rem;
    height: 1rem;
}

.admin-logs-meta-mobile {
    display: none;
}

@media (max-width: 1023px) {
    .admin-logs-table .col-id,
    .admin-logs-table .col-meta {
        display: none;
    }

    .admin-logs-meta-mobile {
        display: block;
        margin-top: 0.25rem;
    }

    .admin-logs-table .col-user { width: 40%; }
    .admin-logs-table .col-actions { width: 5rem; }
}

@media (max-width: 767px) {
    .admin-logs-wrap {
        overflow-x: visible;
    }

    .admin-logs-table thead {
        display: none;
    }

    .admin-logs-table,
    .admin-logs-table tbody,
    .admin-logs-table tr,
    .admin-logs-table td {
        display: block;
        width: 100%;
    }

    .admin-logs-table tr {
        padding: 0.875rem 1rem;
        border-bottom: 1px solid #f1f5f9;
    }

    .admin-logs-table tr:hover {
        background: rgba(248, 250, 252, 0.6);
    }

    .admin-logs-table td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 0.25rem 0;
        border: none;
    }

    .admin-logs-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        width: 4.5rem;
        font-size: 0.5625rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: #94a3b8;
        padding-top: 0.125rem;
    }

    .admin-logs-table .col-id,
    .admin-logs-table .col-time,
    .admin-logs-table .col-meta {
        display: none;
    }

    .admin-logs-table .col-user,
    .admin-logs-table .col-dedication,
    .admin-logs-table .col-amount,
    .admin-logs-table .col-actions {
        width: 100%;
    }

    .admin-logs-table .col-user::before { content: 'Phật tử'; }
    .admin-logs-table .col-dedication::before { content: 'Tâm nguyện'; }
    .admin-logs-table .col-amount::before { content: 'Số lượng'; }
    .admin-logs-table .col-actions::before { content: 'Thao tác'; }

    .admin-logs-table .col-amount,
    .admin-logs-table .col-dedication,
    .admin-logs-table .col-actions {
        text-align: right;
    }

    .admin-logs-table .col-dedication .log-dedication-preview {
        text-align: right;
        max-width: 100%;
    }

    .admin-logs-table .col-actions .log-actions {
        justify-content: flex-end;
    }
}

/* Admin compact pagination */
.admin-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-top: 1px solid #f8fafc;
}

@media (min-width: 768px) {
    .admin-pagination {
        padding: 0.875rem 1.5rem;
    }
}

.admin-pagination-info {
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    margin: 0;
    white-space: nowrap;
}

.admin-pagination-info strong {
    color: #2563eb;
}

.admin-pagination-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.admin-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.375rem;
    border-radius: 0.625rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
    background: #f8fafc;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.admin-page-btn:hover {
    background: #f1f5f9;
    color: #334155;
}

.admin-page-btn--nav {
    min-width: 2rem;
    font-size: 1rem;
    line-height: 1;
}

.admin-page-btn--active {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.admin-page-btn--disabled {
    opacity: 0.35;
    pointer-events: none;
}

.admin-page-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 2rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: #cbd5e1;
    user-select: none;
}

/* Top 30 — print sheet (ẩn màn hình, chỉ hiện khi in) */
.top-print-sheet {
    display: none;
}

.top-print-header {
    text-align: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #1e293b;
}

.top-print-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 0.5rem;
}

.top-print-meta {
    font-size: 0.75rem;
    color: #475569;
    margin: 0.15rem 0;
}

.top-print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.6875rem;
}

.top-print-table th,
.top-print-table td {
    border: 1px solid #cbd5e1;
    padding: 0.35rem 0.45rem;
    vertical-align: top;
}

.top-print-table thead th {
    background: #f1f5f9;
    font-weight: 700;
    text-align: center;
    font-size: 0.625rem;
}

.top-print-table thead th small {
    font-weight: 600;
    color: #64748b;
}

.top-print-table .top-print-rank {
    text-align: center;
    font-weight: 800;
    width: 2rem;
}

.top-print-table .top-print-name {
    font-weight: 700;
    min-width: 6rem;
}

.top-print-table .top-print-phone {
    font-family: monospace;
    font-size: 0.625rem;
    white-space: nowrap;
}

.top-print-table .top-print-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.top-print-table .col-total {
    background: #f8fafc;
    font-weight: 800;
}

.top-print-footer {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.625rem;
    color: #94a3b8;
}

@media print {
    @page {
        size: A4 landscape;
        margin: 12mm;
    }

    body * {
        visibility: hidden;
    }

    #top-print-sheet,
    #top-print-sheet * {
        visibility: visible;
    }

    #top-print-sheet {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        padding: 0;
        background: #fff;
        color: #000;
    }

    .top-print-table {
        page-break-inside: auto;
    }

    .top-print-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }
}
