/* =============================================
   Kalender Hijriah — Base Styles
   Author: Mico Kelana (kelanasolution.com)
   v1.0.0
   ============================================= */

:root {
    --kh-primary: #2d6a4f;
    --kh-accent: #40916c;
    --kh-light: #d8f3dc;
    --kh-bg: #ffffff;
    --kh-surface: #f8fffe;
    --kh-border: #e0f0e8;
    --kh-text: #1b1b1b;
    --kh-text-muted: #888;
    --kh-today-bg: rgba(45,106,79,0.1);
    --kh-shadow: 0 4px 24px rgba(0,0,0,0.08);
    --kh-radius: 14px;
    --kh-radius-sm: 8px;
    --kh-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.kh-wrapper {
    font-family: var(--kh-font);
    box-sizing: border-box;
}
.kh-wrapper *, .kh-wrapper *::before, .kh-wrapper *::after {
    box-sizing: border-box;
}

/* ============ Calendar Shell ============ */
.kh-calendar {
    background: var(--kh-bg);
    border-radius: var(--kh-radius);
    box-shadow: var(--kh-shadow);
    overflow: hidden;
    max-width: 1100px;
    margin: 0 auto;
}

.kh-calendar-inner {
    display: flex;
}

/* ============ Main Calendar Panel ============ */
.kh-cal-main {
    flex: 1;
    padding: 36px 36px 36px 36px;
    min-width: 0;
}

.kh-cal-header {
    text-align: center;
    margin-bottom: 24px;
}

.kh-cal-title {
    font-size: 2.2em;
    font-weight: 800;
    color: var(--kh-text);
    margin: 0 0 4px;
    letter-spacing: -0.5px;
}

.kh-cal-hijri-range {
    color: var(--kh-text-muted);
    font-size: 0.85em;
    margin: 0;
}

/* ============ Controls ============ */
.kh-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.kh-control-select {
    appearance: none;
    background: var(--kh-surface);
    border: 2px solid var(--kh-border);
    border-radius: 50px;
    padding: 7px 34px 7px 14px;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--kh-text);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.15s;
}
.kh-control-select:focus {
    outline: none;
    border-color: var(--kh-accent);
    box-shadow: 0 0 0 3px rgba(64,145,108,0.15);
}

/* ============ Month / Hijri Labels ============ */
.kh-month-label {
    text-align: center;
    font-size: 1.4em;
    font-weight: 700;
    color: var(--kh-text);
    margin-bottom: 4px;
}

.kh-hijri-label {
    text-align: center;
    font-size: 0.85em;
    color: var(--kh-text-muted);
    margin-bottom: 18px;
}

/* ============ Grid ============ */
.kh-grid-wrap {
    background: var(--kh-surface);
    border-radius: var(--kh-radius-sm);
    border: 1px solid var(--kh-border);
    overflow: hidden;
}

.kh-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid var(--kh-border);
}

.kh-weekday {
    text-align: center;
    padding: 10px 2px;
    font-size: 0.62em;
    font-weight: 800;
    color: var(--kh-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
}

.kh-days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}

/* ---- Single Day Cell ---- */
.kh-day {
    position: relative;
    text-align: center;
    padding: 8px 4px 6px;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid var(--kh-border);
    border-right: 1px solid var(--kh-border);
    transition: background 0.12s;
    user-select: none;
}
.kh-day:nth-child(7n) { border-right: none; }

.kh-day.kh-empty {
    opacity: 0.25;
    cursor: default;
    background: transparent !important;
}

.kh-day.kh-today {
    background: var(--kh-today-bg);
}

.kh-day.kh-clickable {
    cursor: pointer;
}
.kh-day.kh-clickable:hover {
    background: var(--kh-light);
    z-index: 1;
}

/* Gregorian number */
.kh-day-greg {
    font-size: 1em;
    font-weight: 600;
    color: var(--kh-text);
    min-width: 30px;
    height: 30px;
    line-height: 30px;
    border-radius: 50%;
    transition: background 0.12s, color 0.12s;
}

.kh-day.kh-today .kh-day-greg {
    background: var(--kh-primary);
    color: #fff;
    font-weight: 700;
}

.kh-day.kh-holiday .kh-day-greg {
    color: var(--kh-accent);
}

/* Hijri number — always shown */
.kh-day-hijri {
    font-size: 0.72em;
    color: var(--kh-text-muted);
    line-height: 1.3;
    margin-top: 1px;
}

.kh-day.kh-today .kh-day-hijri {
    color: var(--kh-accent);
}

/* ---- Holiday Dots ---- */
.kh-day-dots {
    display: flex;
    gap: 3px;
    margin-top: 4px;
    justify-content: center;
}

.kh-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.kh-dot-islam    { background: var(--kh-accent); }
.kh-dot-national { background: #e63946; }

/* ============ Loading ============ */
.kh-loading-grid {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--kh-text-muted);
    font-size: 0.85em;
}

.kh-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--kh-border);
    border-top-color: var(--kh-primary);
    border-radius: 50%;
    animation: kh-spin 0.7s linear infinite;
    display: inline-block;
}

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

/* ============ Sidebar ============ */
.kh-sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--kh-surface);
    border-left: 1px solid var(--kh-border);
    padding: 24px 16px;
    overflow-y: auto;
    max-height: 700px;
}

.kh-sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--kh-border);
}

.kh-sidebar-header h3 {
    font-size: 1em;
    font-weight: 700;
    color: var(--kh-text);
    margin: 0;
}

.kh-holiday-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ---- Holiday List Item ---- */
.kh-holiday-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 8px;
    border-radius: 8px;
    background: var(--kh-bg);
    border: 1px solid var(--kh-border);
    transition: border-color 0.12s;
}
.kh-holiday-item:hover {
    border-color: var(--kh-accent);
}

.kh-holiday-badge {
    flex-shrink: 0;
    text-align: center;
    min-width: 40px;
}

.kh-holiday-month {
    font-size: 0.6em;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 4px;
    border-radius: 4px 4px 0 0;
    line-height: 1.4;
}

.kh-item-islam .kh-holiday-month {
    background: var(--kh-primary);
    color: #fff;
}

.kh-item-national .kh-holiday-month {
    background: #c1121f;
    color: #fff;
}

.kh-holiday-day {
    font-size: 1.3em;
    font-weight: 800;
    line-height: 1.2;
    padding: 2px 4px;
    border-radius: 0 0 4px 4px;
    width: 100%;
    text-align: center;
}

.kh-item-islam .kh-holiday-day {
    background: var(--kh-light);
    color: var(--kh-primary);
}

.kh-item-national .kh-holiday-day {
    background: #ffe8e8;
    color: #c1121f;
}

.kh-holiday-info {
    flex: 1;
    min-width: 0;
}

.kh-holiday-name {
    display: block;
    font-weight: 700;
    font-size: 0.8em;
    color: var(--kh-accent);
    line-height: 1.3;
    word-break: break-word;
}

.kh-item-national .kh-holiday-name {
    color: #c1121f;
}

.kh-holiday-hijri {
    display: block;
    font-size: 0.7em;
    color: var(--kh-text-muted);
    margin-top: 2px;
}

.kh-no-holidays {
    color: var(--kh-text-muted);
    font-size: 0.82em;
    text-align: center;
    padding: 24px 0;
}

/* ============ Minimal Nav Buttons ============ */
.kh-btn-icon {
    background: var(--kh-surface);
    border: 2px solid var(--kh-border);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kh-text);
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
    line-height: 1;
}
.kh-btn-icon:hover {
    background: var(--kh-light);
    border-color: var(--kh-accent);
}

/* ============ MODAL / POPUP ============ */
.kh-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.kh-modal-overlay.kh-modal-open {
    opacity: 1;
    visibility: visible;
}

.kh-modal-box {
    background: var(--kh-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 380px;
    overflow: hidden;
    transform: translateY(12px) scale(0.97);
    transition: transform 0.2s;
}

.kh-modal-overlay.kh-modal-open .kh-modal-box {
    transform: translateY(0) scale(1);
}

.kh-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--kh-primary, #2d6a4f);
    color: #fff;
}

.kh-modal-title {
    font-size: 1em;
    font-weight: 700;
    color: #fff;
}

.kh-modal-close {
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    color: #fff;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    line-height: 1;
}
.kh-modal-close:hover { background: rgba(255,255,255,0.35); }

.kh-modal-body {
    padding: 20px;
}

/* Hijri date in popup */
.kh-popup-hijri {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--kh-surface, #f8fffe);
    border: 1px solid var(--kh-border, #e0f0e8);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
}

.kh-popup-hijri-day {
    font-size: 2em;
    font-weight: 800;
    color: var(--kh-primary, #2d6a4f);
    line-height: 1;
}

.kh-popup-hijri-month {
    font-size: 0.9em;
    color: var(--kh-text, #1b1b1b);
    font-weight: 600;
    line-height: 1.3;
}

/* Holidays in popup */
.kh-popup-holidays {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kh-popup-hol {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    border-radius: 8px;
}

.kh-popup-hol-islam {
    background: var(--kh-light, #d8f3dc);
    border-left: 3px solid var(--kh-accent, #40916c);
}

.kh-popup-hol-national {
    background: #fff0f0;
    border-left: 3px solid #e63946;
}

.kh-popup-hol-badge {
    font-size: 0.68em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

.kh-popup-hol-islam .kh-popup-hol-badge { color: var(--kh-primary, #2d6a4f); }
.kh-popup-hol-national .kh-popup-hol-badge { color: #c1121f; }

.kh-popup-hol-name {
    font-size: 0.9em;
    font-weight: 700;
    line-height: 1.3;
}

.kh-popup-hol-islam .kh-popup-hol-name    { color: var(--kh-primary, #2d6a4f); }
.kh-popup-hol-national .kh-popup-hol-name { color: #c1121f; }

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .kh-calendar-inner { flex-direction: column; }
    .kh-sidebar {
        width: 100%;
        min-width: unset;
        border-left: none;
        border-top: 1px solid var(--kh-border);
        max-height: 360px;
    }
    .kh-cal-main { padding: 20px 14px; }
    .kh-cal-title { font-size: 1.6em; }
    .kh-day { min-height: 52px; padding: 6px 2px 4px; }
    .kh-day-greg { font-size: 0.9em; height: 26px; line-height: 26px; min-width: 26px; }
    .kh-day-hijri { font-size: 0.65em; }
}

@media (max-width: 420px) {
    .kh-day-hijri { display: none; }
    .kh-day { min-height: 40px; }
    .kh-weekday { font-size: 0.65em; padding: 8px 0; }
}
