/* ------------------------------------------------------------------------------- */
/* Base for native HTML5 <dialog> Elements                                         */
/* ------------------------------------------------------------------------------- */

dialog.ter_kal_ui_dialog {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 13px;
    border-radius: 1rem;
    border: 1px solid rgba(0, 0, 0, 0.4);
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.5), 0 0 40px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    overflow: hidden;
    width: 100%;
    max-width: 800px;
    padding: 0;
    background: #f8f9fa;
    color: #333;
}

dialog.ter_kal_ui_dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

/* Force flex layout only when open to maintain native showModal behavior */
dialog.ter_kal_ui_dialog[open] {
    display: flex;
    flex-direction: column;
}

dialog.ter_kal_ui_dialog:focus,
dialog.ter_kal_ui_dialog:focus-visible {
    outline: none;
}

/* ------------------------------------------------------------------------------- */
/* Header */
.ter_kal_dialog_header {
    background: #007bff;
    color: #fff;
    border: 0px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1rem;
    flex-shrink: 0; /* Prevents header from collapsing when dialog is small */
}

.ter_kal_dialog_header .ter_kal_dialog_title {
    font-weight: 700;
    font-size: 1.6rem;
    line-height: 1.6rem;
    margin: 0;
    color: #ffffff;
    /* Enforce white text for header title */
    flex-grow: 1;
    display: flex;
    align-items: center;
}

.ter_kal_dialog_header .ter_kal_dialog_close {
    background: rgba(0, 0, 0, 0.2);
    border: 0px solid #fff;
    color: #fff;
    line-height: 1.6rem;
    opacity: 0.75;
    border-radius: 0.5rem;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ter_kal_dialog_header .ter_kal_dialog_close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.3);
}

.ter_kal_dialog_header .ter_kal_dialog_close:focus {
    outline: none;
}

.ter_kal_dialog_header .ter_kal_dialog_title .dashicons {
    font-size: 2.2rem;
    width: 2.2rem;
    height: 2.2rem;
    margin-right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ------------------------------------------------------------------------------- */
/* Body / Content */
.ter_kal_dialog_content {
    width: 100%;
    background: #f8f9fa;
    padding: 1rem;
    /* Let flex handle the height automatically instead of fixed vh */
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    box-sizing: border-box;
}

.ter_kal_ui_dialog hr {
    margin: 0.5rem 0;
    border: 0;
    border-top: 1px solid #dee2e6;
}

.ter_kal_dialog_content .event-detail-item {
    margin-bottom: 0.3rem;
}

.ter_kal_dialog_content .event-title {
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.ter_kal_dialog_content .event-time,
.ter_kal_dialog_content .event-details-html {
    font-size: 1rem;
    line-height: 1.5;
    color: #333;
}

.ter_kal_dialog_content .event-subdetail-item {
    font-size: 0.85em;
    color: #555;
    margin-bottom: 0.2rem;
}

/* ------------------------------------------------------------------------------- */
/* Footer / Buttons */
.ter_kal_dialog_footer {
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    padding: 0.6rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem; /* Tightened gap slightly */
    flex-shrink: 0; /* Prevents footer from collapsing when dialog is small */
}

.ter_kal_dialog_footer button,
.ter_kal_dialog_footer [class*="tk_btn"] {
    flex: 0 1 auto; /* Do NOT stretch to prevent giant single buttons on the last row */
    border: 1px solid transparent;
    padding: 0.3rem 0.6rem; /* Smaller padding to fit more per row */
    border-radius: 4px;
    background-color: #ffffff;
    font-size: 0.8rem;
    font-weight: 500;
    color: #333;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* Enlarge icons/emojis inside all footer buttons evenly */
.ter_kal_dialog_footer button .dashicons,
.ter_kal_dialog_footer [class*="tk_btn"] .dashicons,
.ter_kal_dialog_footer button i,
.ter_kal_dialog_footer .tk-emoji {
    font-size: 1rem;
    line-height: 1rem;
    height: 1rem;
    margin-right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

.ter_kal_dialog_footer button:hover,
.ter_kal_dialog_footer button:focus,
.ter_kal_dialog_footer .tk_btn:hover {
    background-color: #f8f9fa;
    border-color: #cdd4dc;
}

/* Button Variants */
.ter_kal_dialog_footer .tk_btn_export {
    background-color: #4361ee;
    color: #ffffff;
    border: 1px solid #4361ee; /* matching border color */
}

.ter_kal_dialog_footer .tk_btn_export:hover {
    background-color: #4895ef;
    border-color: #4895ef;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.25);
}

.ter_kal_dialog_footer .tk_btn_share {
    background-color: #17a2b8;
    color: #ffffff;
    border: 1px solid #17a2b8; /* matching border color */
}

.ter_kal_dialog_footer .tk_btn_share:hover {
    background-color: #20c997;
    border-color: #20c997;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(23, 162, 184, 0.25);
}

.ter_kal_dialog_footer .tk_btn_primary {
    background-color: #e2e8f0; /* light gray-blue */
    color: #334155;
    border: 1px solid #cbd5e1;
    box-shadow: none;
}

.ter_kal_dialog_footer .tk_btn_primary:hover {
    background-color: #cbd5e1; /* darker on hover */
    color: #0f172a;
    border-color: #94a3b8;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.ter_kal_dialog_footer .tk_btn_cancel {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    box-shadow: none;
}

.ter_kal_dialog_footer .tk_btn_cancel:hover {
    background-color: #64748b; 
    color: #ffffff; 
    border-color: #64748b;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(100, 116, 139, 0.25);
}

.ter_kal_dialog_footer .tk_btn_separator {
    display: none;
    /* Hide separators since we wrap now */
}

/* Location Button (Google Maps) */
.ter_kal_dialog_content [id^="event-location_link-"] .bootstrap_button {
    width: 98%;
    display: block;
    margin-top: 1rem;
    padding: 3px;
    border-radius: 4px;
    border: 1px solid #bbcad8 !important;
    background-color: #ffffff !important;
    color: #7b8793 !important;
    text-shadow: none !important;
    background-image: none !important;
    box-shadow: none !important;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    text-align: center;
}

.ter_kal_dialog_content [id^="event-location_link-"] .bootstrap_button:hover {
    background-color: #7b8793 !important;
    color: #ffffff !important;
    border-color: #7b8793 !important;
    transform: none;
    box-shadow: none !important;
}


/* Mobile responsive (Tablets & Large Phones) */
@media screen and (max-width: 768px) {
    dialog.ter_kal_ui_dialog {
        width: 98%;
        max-height: 95vh; /* Allow slightly more height on small screens */
        margin: auto;
    }

    .ter_kal_dialog_header .ter_kal_dialog_title {
        font-size: 1.4rem;
        line-height: 1.4rem;
    }
    .ter_kal_dialog_header .ter_kal_dialog_title .dashicons {
        font-size: 1.8rem;
        width: 1.8rem;
        height: 1.8rem;
    }

    .ter_kal_dialog_content [id^="event-location_link-"] .bootstrap_button {
        font-size: 0.9rem;
        padding: 4px;
    }

    .ter_kal_dialog_content .event-title {
        font-size: 1.2rem;
    }

    .ter_kal_dialog_content .event-time,
    .ter_kal_dialog_content .event-details-html {
        font-size: 0.9rem;
    }

    .ter_kal_dialog_footer {
        justify-content: center;
        padding: 0.5rem;
    }

    .ter_kal_dialog_footer button,
    .ter_kal_dialog_footer [class*="tk_btn"] {
        flex: 1 1 auto; /* stretch buttons slightly to fill edge to edge on mobile */
        text-align: center;
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }

    .ter_kal_dialog_footer button .dashicons,
    .ter_kal_dialog_footer [class*="tk_btn"] .dashicons,
    .ter_kal_dialog_footer button i,
    .ter_kal_dialog_footer .tk-emoji {
        font-size: 0.9rem;
        line-height: 0.9rem;
        height: 0.9rem;
    }
}

/* Small Phones */
@media screen and (max-width: 480px) {
    .ter_kal_dialog_header {
        padding: 0.5rem 0.75rem;
    }

    .ter_kal_dialog_header .ter_kal_dialog_title {
        font-size: 1.2rem;
        line-height: 1.2rem;
    }
    .ter_kal_dialog_header .ter_kal_dialog_title .dashicons {
        font-size: 1.5rem;
        width: 1.5rem;
        height: 1.5rem;
        margin-right: 8px;
    }

    .ter_kal_dialog_content [id^="event-location_link-"] .bootstrap_button {
        font-size: 0.8rem;
        padding: 5px;
    }

    .ter_kal_dialog_content .event-title {
        font-size: 1.1rem;
    }

    .ter_kal_dialog_content .event-time,
    .ter_kal_dialog_content .event-details-html {
        font-size: 0.85rem;
    }

    .ter_kal_dialog_footer button,
    .ter_kal_dialog_footer [class*="tk_btn"] {
        font-size: 0.7rem;
        padding: 0.25rem 0.4rem;
    }

    .ter_kal_dialog_footer button .dashicons,
    .ter_kal_dialog_footer [class*="tk_btn"] .dashicons,
    .ter_kal_dialog_footer button i,
    .ter_kal_dialog_footer .tk-emoji {
        font-size: 0.8rem;
        line-height: 0.8rem;
        height: 0.8rem;
        margin-right: 4px;
    }
}