/* Popup Overlay */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    opacity: 0;
}

.popup-overlay.active {
    display: flex;
    opacity: 1;
    justify-content: center;
    align-items: flex-end;
    padding: 0;
}

/* Popup Container - Mobile First */
.popup-container {
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    overflow: hidden;
}

.popup-overlay.active .popup-container {
    transform: translateY(0);
}

/* Popup Header */
.popup-header {
    padding: 20px 20px 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    position: relative;
    flex-shrink: 0;
}

.popup-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
}

.popup-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

.popup-close {
    background: #f3f4f6;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.popup-close:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Palace Info Section */
.palace-info {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.palace-info-item {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 4px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    min-height: 50px;
}

.palace-info-item:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.palace-info-value {
    color: #dc2626;
    font-weight: 700;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.2;
}

/* Main Tabs */
.popup-tabs {
    display: flex;
    background: white;
    padding: 0 20px;
    border-bottom: 1px solid #f0f0f0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-shrink: 0;
}

.popup-tabs::-webkit-scrollbar {
    display: none;
}

.popup-tab {
    padding: 12px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 0.95rem;
    min-width: fit-content;
}

.popup-tab:hover {
    color: #374151;
}

.popup-tab.active {
    color: #dc2626;
    border-bottom-color: #dc2626;
    font-weight: 600;
}

/* Popup Content */
.popup-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #fafafa;
}

.tab-content {
    display: none;
    flex: 1;
    overflow: auto;
    padding: 20px;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* Sub Tabs */
.sub-tabs {
    display: flex;
    margin-bottom: 16px;
    background: white;
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-shrink: 0;
}

.sub-tabs::-webkit-scrollbar {
    display: none;
}

.sub-tab {
    padding: 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: #6b7280;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    white-space: nowrap;
    min-width: fit-content;
}

.sub-tab:hover {
    color: #374151;
    background: #f9fafb;
}

.sub-tab.active {
    color: white;
    background: #dc2626;
    font-weight: 600;
}

.sub-content {
    display: none;
    flex: 1;
    overflow: auto;
}

.sub-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Tables */
.popup-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    table-layout: fixed;
    flex-shrink: 0;
}

.popup-table th {
    background: #dc2626;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: white;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popup-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    line-height: 1.5;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.popup-table tr:hover {
    background: #fef2f2;
}

.popup-table td:first-child {
    font-weight: 600;
    color: #dc2626;
    background: #fef2f2;
    width: 30%;
    min-width: 120px;
}

.popup-table td:nth-child(2) {
    width: 70%;
}

/* Special styling for content cells */
.popup-table td:not(:first-child) {
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Description Area */
.description-area {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    margin-top: 16px;
    min-height: 100px;
    color: #374151;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.description-area strong {
    color: #dc2626;
    font-size: 1.05rem;
}

/* Two Section Layout for Tab 3 */
.two-section-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #dc2626;
    margin-bottom: 12px;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Desktop Styles */
@media screen and (min-width: 769px) {
    .popup-overlay.active {
        align-items: center;
        padding: 20px;
    }

    .popup-container {
        border-radius: 16px;
        width: 1000px;
        max-width: 90vw;
        height: 700px;
        max-height: 90vh;
        transform: translateY(0);
    }

    .popup-overlay.active .popup-container {
        transform: translateY(0);
    }
    
    .popup-header::before {
        display: none;
    }
    
    .popup-header {
        padding: 24px 28px 20px 28px;
    }
    
    .popup-title {
        font-size: 1.5rem;
    }
    
    .palace-info {
        padding: 16px 28px;
        font-size: 0.9rem;
        gap: 12px;
    }
    
    .palace-info-item {
        padding: 16px 8px;
        min-height: 60px;
    }
    
    .palace-info-value {
        font-size: 1.3em;
    }
    
    .popup-tabs {
        padding: 0 28px;
    }
    
    .popup-tab {
        padding: 14px 24px;
        font-size: 1rem;
    }
    
    .tab-content {
        padding: 28px;
    }
    
    .sub-tabs {
        padding: 6px;
        margin-bottom: 20px;
    }
    
    .sub-tab {
        padding: 10px 20px;
        font-size: 0.95rem;
    }
    
    .popup-table th:first-child,
    .popup-table td:first-child {
        width: 15%;
    }
    
    .popup-table th:nth-child(2),
    .popup-table td:nth-child(2) {
        width: 35%;
    }
    
    .popup-table th {
        padding: 10px 18px;
        font-size: 0.85rem;
        line-height: 1.2;
    }
    
    .popup-table td {
        padding: 12px 18px;
        font-size: 0.9rem;
        line-height: 1.5;
    }
}

/* Tablet Styles */
@media screen and (max-width: 768px) and (min-width: 481px) {
    .popup-container {
        width: 95vw;
        height: 90vh;
        border-radius: 16px;
    }

    .popup-overlay.active {
        align-items: center;
        padding: 20px;
    }

    .popup-overlay.active .popup-container {
        transform: translateY(0);
    }
    
    .popup-header::before {
        display: none;
    }
    
    .palace-info {
        gap: 10px;
        font-size: 0.8rem;
    }
    
    .palace-info-item {
        padding: 14px 6px;
        min-height: 55px;
    }
    
    .popup-table th:first-child,
    .popup-table td:first-child {
        width: 35%;
    }
    
    .popup-table th:nth-child(2),
    .popup-table td:nth-child(2) {
        width: 65%;
    }
    
    .popup-table td {
        padding: 12px 14px;
        font-size: 0.9rem;
    }
    
    .popup-table th {
        padding: 12px 14px;
        font-size: 0.9rem;
    }
}

/* Mobile Styles */
@media screen and (max-width: 480px) {
    .popup-container {
        border-radius: 20px 20px 0 0;
        width: 100%;
        height: 85vh;
        max-height: none;
        max-width: none;
    }
    
    .popup-header {
        padding: 16px 20px 12px 20px;
    }
    
    .popup-title {
        font-size: 1.1rem;
    }
    
    .popup-close {
        width: 28px;
        height: 28px;
        font-size: 1.1rem;
    }
    
    .palace-info {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 6px;
        padding: 8px 20px;
        font-size: 0.75rem;
    }
    
    .palace-info-item {
        padding: 10px 4px;
        min-height: 45px;
    }
    
    .palace-info-item:nth-child(4) {
        grid-column: 1 / 3;
    }
    
    .palace-info-item:nth-child(5) {
        grid-column: 3;
    }
    
    .palace-info-value {
        font-size: 1.1em;
    }
    
    .popup-tabs {
        padding: 0 20px;
    }
    
    .popup-tab {
        padding: 10px 12px;
        font-size: 0.85rem;
        min-width: 80px;
    }
    
    .tab-content {
        padding: 16px 20px;
    }
    
    .sub-tabs {
        margin-bottom: 12px;
        padding: 3px;
    }
    
    .sub-tab {
        padding: 6px 12px;
        font-size: 0.8rem;
        min-width: 60px;
    }
    
    .popup-table {
        display: block;
        overflow: visible;
        white-space: normal;
        table-layout: auto;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
        font-size: 0.85rem;
        margin-bottom: 12px;
    }
    
    .popup-table thead,
    .popup-table tbody,
    .popup-table th,
    .popup-table td,
    .popup-table tr {
        display: block;
    }
    
    .popup-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .popup-table tr {
        border: 1px solid #e9ecef;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 16px;
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        position: relative;
    }
    
    .popup-table td {
        border: none !important;
        padding: 8px 0 !important;
        position: relative;
        padding-left: 45% !important;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        width: auto !important;
        min-height: 28px;
        display: flex;
        align-items: center;
        font-size: 0.85rem !important;
        line-height: 1.4;
    }
    
    .popup-table td:before {
        content: attr(data-label) ": ";
        position: absolute;
        left: 0;
        width: 40%;
        padding-right: 8px;
        white-space: normal;
        font-weight: 600;
        color: #dc2626;
        background: #fef2f2;
        padding: 6px 8px;
        border-radius: 4px;
        font-size: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        line-height: 1.2;
    }
    
    .popup-table td:first-child {
        background: transparent !important;
        color: #374151 !important;
        font-weight: 500 !important;
        width: auto !important;
        min-width: auto !important;
    }
    
    .description-area {
        padding: 16px;
        margin-top: 12px;
        min-height: 80px;
        font-size: 0.9rem;
    }
    
    .section-title {
        font-size: 1rem;
        padding: 10px 12px;
        margin-bottom: 8px;
    }
    
    .two-section-layout {
        gap: 16px;
    }
}

/* Enhanced animations */
.popup-tab,
.sub-tab {
    position: relative;
    overflow: hidden;
}

.popup-tab::before,
.sub-tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.popup-tab:hover::before,
.sub-tab:hover::before {
    left: 100%;
}

/* Table animations */
.popup-table tbody tr {
    transition: all 0.2s ease;
}

.popup-table tbody tr:hover {
    transform: translateX(2px);
}

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

.tab-content.active {
    animation: fadeIn 0.3s ease;
}

.sub-content.active {
    animation: fadeIn 0.2s ease;
}

/* Cell Info Popup Styles */
.cell-info-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1001;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cell-info-popup-overlay.active {
    opacity: 1;
}

.cell-info-popup-container {
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    animation: fadeInSimple 0.3s ease;
}

@keyframes fadeInSimple {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.cell-info-popup-header {
    padding: 24px 28px 20px 28px;
    border-bottom: 2px solid #f0e68c;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #f5f5dc 0%, #deb887 100%);
    position: relative;
}

.cell-info-popup-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #2c1810;
    margin: 0;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.cell-info-popup-close {
    background: linear-gradient(135deg, #d4af37 0%, #b8860b 100%);
    border: 2px solid #8b4513;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    color: #2c1810;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(139, 69, 19, 0.3);
}

.cell-info-popup-close:hover {
    background: linear-gradient(135deg, #b8860b 0%, #d4af37 100%);
}

.cell-info-popup-content {
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: linear-gradient(135deg, #fafafa 0%, #f5f5f5 100%);
}

.cell-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #d4af37;
    transition: all 0.2s ease;
}

.cell-info-row:hover {
    background: #f0f1f5;
    transform: translateX(4px);
}

.cell-info-label {
    font-weight: 600;
    color: #4b5563;
    font-size: 0.95rem;
    min-width: 100px;
}

.cell-info-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #d4af37;
    text-align: right;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .cell-info-popup-container {
        width: 95%;
        border-radius: 12px;
    }

    .cell-info-popup-header {
        padding: 16px;
    }

    .cell-info-popup-title {
        font-size: 1.1rem;
    }

    .cell-info-popup-content {
        padding: 16px;
        gap: 12px;
    }

    .cell-info-row {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .cell-info-label {
        font-size: 0.85rem;
        min-width: 80px;
    }

    .cell-info-value {
        font-size: 0.95rem;
    }
}

/* Cell Info Tabs Styles */
.cell-info-tabs {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #f5f5dc 0%, #faf8f0 100%);
    border-bottom: 2px solid #f0e68c;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-wrap: wrap;
}

.cell-info-tabs::-webkit-scrollbar {
    display: none;
}

.cell-info-tab {
    padding: 8px 14px;
    background: white;
    border: 2px solid #deb887;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    color: #2c1810;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: fit-content;
    box-shadow: 0 2px 4px rgba(139, 69, 19, 0.1);
}

.cell-info-tab:hover {
    color: #2c1810;
    border-color: #d4af37;
    background: #faf8f0;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(139, 69, 19, 0.15);
}

.cell-info-tab.active {
    color: #2c1810;
    background: linear-gradient(135deg, #d4af37 0%, #b8860b 100%);
    border-color: #8b4513;
    font-weight: 700;
    box-shadow: 0 3px 8px rgba(139, 69, 19, 0.3);
}

.cell-info-tab-content {
    display: none;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.cell-info-tab-content.active {
    display: block;
}

.cell-info-loading {
    text-align: center;
    padding: 20px;
    color: #9ca3af;
    font-size: 0.9rem;
}

.cell-info-error {
    text-align: center;
    padding: 20px;
    color: #8b4513;
    font-size: 0.9rem;
    background: #fef3c7;
    border-radius: 8px;
    border: 1px solid #f0e68c;
}

.cell-info-item {
    background: white;
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #deb887;
    box-shadow: 0 2px 4px rgba(139, 69, 19, 0.1);
}

.cell-info-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0e68c;
}

.cell-info-item-name {
    font-weight: 700;
    color: #2c1810;
    font-size: 1.05rem;
}

.cell-info-item-status {
    display: inline-block;
    padding: 4px 12px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.cell-info-item-content {
    color: #2c1810;
    line-height: 1.7;
    font-size: 0.9rem;
}

.cell-info-item-content p {
    margin: 10px 0;
}

.cell-info-item-content strong {
    color: #8b4513;
    font-weight: 700;
}

/* Mobile Responsive for Tabs */
@media (max-width: 480px) {
    .cell-info-tabs {
        padding: 10px 16px;
        gap: 6px;
    }

    .cell-info-tab {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .cell-info-tab-content {
        padding: 12px 16px;
    }

    .cell-info-item {
        padding: 12px;
    }

    .cell-info-item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .cell-info-item-status {
        align-self: flex-start;
    }
}

/* ============================================
   Cung Tab Styles (KMAB only)
   ============================================ */

.cung-content-wrapper {
    padding: 20px;
    min-height: 300px;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

.loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-spinner p {
    color: #6b7280;
    font-size: 14px;
    margin: 0;
}

.cung-content-display {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.cung-section {
    background: #f9fafb;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e5e7eb;
}

.cung-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid #3b82f6;
}

.cung-content-text,
.cung-interpretation-text,
.cung-notes-text {
    color: #374151;
    font-size: 15px;
    line-height: 1.7;
}

.cung-content-text p,
.cung-interpretation-text p,
.cung-notes-text p {
    margin: 0 0 12px 0;
}

.cung-content-text p:last-child,
.cung-interpretation-text p:last-child,
.cung-notes-text p:last-child {
    margin-bottom: 0;
}

.cung-content-text h3,
.cung-interpretation-text h3,
.cung-notes-text h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #1f2937;
    margin: 16px 0 8px 0;
}

.cung-content-text ul,
.cung-interpretation-text ul,
.cung-notes-text ul {
    margin: 12px 0;
    padding-left: 24px;
}

.cung-content-text li,
.cung-interpretation-text li,
.cung-notes-text li {
    margin-bottom: 8px;
}

.no-content {
    color: #9ca3af;
    font-style: italic;
    text-align: center;
    padding: 20px;
    margin: 0;
}

.cung-error-display {
    padding: 40px 20px;
    text-align: center;
}

.cung-error-display .error-message {
    color: #dc2626;
    font-size: 15px;
    margin: 0;
    padding: 16px;
    background: #fee2e2;
    border-radius: 8px;
    border: 1px solid #fecaca;
}

/* Mobile responsive adjustments for Cung tab */
@media (max-width: 768px) {
    .cung-content-wrapper {
        padding: 16px;
    }

    .cung-section {
        padding: 16px;
    }

    .cung-section h3 {
        font-size: 1rem;
    }

    .cung-content-text,
    .cung-interpretation-text,
    .cung-notes-text {
        font-size: 14px;
    }
}