/* Tenant history — page, tabs, cards, pagination */
.tenant-history-page {
    font-family: 'Kanit', sans-serif;
    padding: 16px 12px 24px;
    max-width: 960px;
    margin: 0 auto;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .tenant-history-page {
        padding: 20px 16px 32px;
    }
}

.tenant-history-tabs {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -4px 16px;
    padding: 8px 4px 10px;
    background: linear-gradient(to bottom, #f8fafc 85%, rgba(248, 250, 252, 0));
}

.tenant-history-tabs__scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding: 2px 2px 4px;
}

.tenant-history-tabs__scroll::-webkit-scrollbar {
    display: none;
}

.tenant-history-tab {
    flex: 0 0 auto;
    scroll-snap-align: start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border: 1.5px solid #e2e8f0;
    border-radius: 999px;
    background: #fff;
    color: #64748b;
    font-family: 'Kanit', sans-serif;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.tenant-history-tab i {
    font-size: 0.9rem;
    opacity: 0.85;
}

.tenant-history-tab:hover {
    border-color: #cbd5e1;
    color: #334155;
    background: #f8fafc;
}

.tenant-history-tab:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.tenant-history-tab--active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
}

.tenant-history-tab--active i {
    opacity: 1;
}

.tenant-history-tab__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    background: rgba(100, 116, 139, 0.12);
    color: #64748b;
}

.tenant-history-tab--active .tenant-history-tab__badge {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.tenant-history-list {
    min-height: 240px;
}

.tenant-history-empty {
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
    font-size: 0.95rem;
    line-height: 1.5;
}

.tenant-history-empty i {
    display: block;
    font-size: 2.2rem;
    margin-bottom: 12px;
    opacity: 0.35;
}

.tenant-history-card {
    background: #fff;
    border-radius: 16px;
    padding: 16px 18px;
    border: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.tenant-history-card:hover {
    border-color: #93c5fd;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.08);
}

.tenant-history-card--parcel:hover {
    border-color: #fdba74;
    box-shadow: 0 6px 16px rgba(249, 115, 22, 0.08);
}

.tenant-history-card__main {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

.tenant-history-card__icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.tenant-history-card__body {
    min-width: 0;
}

.tenant-history-card__title {
    font-weight: 700;
    color: #1e293b;
    font-size: 1rem;
    line-height: 1.35;
    word-break: break-word;
}

.tenant-history-card__meta {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 4px;
}

.tenant-history-card__aside {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.tenant-history-card__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tenant-history-card__badge {
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: #dcfce7;
    color: #16a34a;
    white-space: nowrap;
}

.tenant-history-card__sub {
    font-size: 0.72rem;
    color: #94a3b8;
    line-height: 1.4;
}

.tenant-history-card__reply-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.tenant-history-card__reply-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
    background: #eff6ff;
}

.tenant-history-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.tenant-history-pagination__btn {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    border-radius: 12px;
    border: 1px solid #f1f5f9;
    background: #fff;
    color: #64748b;
    font-family: 'Kanit', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tenant-history-pagination__btn:hover:not(:disabled) {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.tenant-history-pagination__btn:disabled {
    background: #f8fafc;
    color: #cbd5e1;
    cursor: default;
}

.tenant-history-pagination__btn--active {
    border-color: #3b82f6;
    background: #3b82f6;
    color: #fff;
}

.tenant-history-pagination__pages {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    .tenant-history-tab {
        padding: 10px 14px;
        font-size: 0.82rem;
    }

    .tenant-history-card {
        flex-direction: column;
        align-items: stretch;
        padding: 14px 16px;
    }

    .tenant-history-card__aside {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        text-align: left;
        padding-top: 10px;
        border-top: 1px solid #f1f5f9;
    }

    .tenant-history-card__sub {
        width: 100%;
    }

    .tenant-history-pagination__pages {
        max-width: calc(100vw - 120px);
    }
}

/* Native app: offset sticky tabs below mobile header */
body.is-native-app .tenant-history-tabs {
    top: calc(var(--mobile-header-height, 56px) - 4px);
}

/* Parcel detail panel (history tab) */
body.tenant-parcel-detail-open {
    overflow: hidden;
}

.tenant-parcel-detail {
    position: fixed;
    inset: 0;
    z-index: 100050;
    background: #fff;
    font-family: 'Kanit', sans-serif;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.28s ease, transform 0.28s ease;
}

.tenant-parcel-detail.is-visible {
    opacity: 1;
    transform: translateX(0);
}

.tenant-parcel-detail__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
}

.tenant-parcel-detail__back,
.tenant-parcel-detail__close {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #2563eb;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.tenant-parcel-detail__close {
    color: #64748b;
    margin-left: auto;
}

.tenant-parcel-detail__back:hover,
.tenant-parcel-detail__close:hover {
    background: #f8fafc;
}

.tenant-parcel-detail__title {
    margin: 0;
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e3a5f;
    line-height: 1.3;
}

.tenant-parcel-detail__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.tenant-parcel-detail__summary {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px;
    margin-bottom: 8px;
    background: #fff;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.tenant-parcel-detail__icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: #fff7ed;
    color: #f97316;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.tenant-parcel-detail__summary-text {
    flex: 1;
    min-width: 0;
}

.tenant-parcel-detail__summary-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.35;
}

.tenant-parcel-detail__summary-meta {
    margin-top: 4px;
    font-size: 0.82rem;
    color: #94a3b8;
}

.tenant-parcel-detail__status {
    flex-shrink: 0;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: #dcfce7;
    color: #16a34a;
    white-space: nowrap;
    align-self: flex-start;
}

.tenant-parcel-detail__rows {
    background: #fff;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    overflow: hidden;
}

.tenant-parcel-detail__row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
}

.tenant-parcel-detail__row:last-child {
    border-bottom: none;
}

.tenant-parcel-detail__label {
    flex: 0 0 auto;
    font-size: 0.88rem;
    color: #94a3b8;
    line-height: 1.4;
}

.tenant-parcel-detail__value {
    flex: 1;
    text-align: right;
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.4;
    word-break: break-word;
}

body.is-native-app .tenant-parcel-detail__header {
    padding-top: calc(14px + var(--safe-area-top, 0px));
}

@media (min-width: 768px) {
    .tenant-parcel-detail {
        inset: auto;
        top: 50%;
        left: 50%;
        width: min(480px, calc(100% - 32px));
        max-height: min(90vh, 720px);
        border-radius: 20px;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
        transform: translate(-50%, -48%);
    }

    .tenant-parcel-detail.is-visible {
        transform: translate(-50%, -50%);
    }

    body.tenant-parcel-detail-open::before {
        content: '';
        position: fixed;
        inset: 0;
        z-index: 100040;
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(4px);
    }
}
