:root {
    --primary: #0f766e;
    --period-bg: #fee2e2;
    --period-text: #991b1b;
    --med-bg: #dbeafe;
    /* Blue-100 */
    --med-text: #1e40af;
    /* Blue-800 */
    --hajj-bg: #dcfce7;
    --hajj-text: #166534;
    --overlap-text: #701a75;
    --border: #e5e7eb;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    display: flex;
    height: 100vh;
    background-color: #f8fafc;
    overflow: hidden;
}



/* Custom Tooltip */
.tooltip-icon {
    cursor: help;
    position: relative;
    margin-left: 4px;
    border-bottom: 1px dotted #666;
}

.tooltip-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: pre-wrap;
    /* Allow wrapping */
    width: max-content;
    max-width: 250px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 100;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tooltip-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    body {
        flex-direction: column !important;
        height: auto !important;
        overflow-y: auto !important;
    }

    .sidebar {
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 16px;
        overflow-y: visible !important;
        flex: none !important;
        /* Don't try to flex grow/shrink */
    }

    .main-view {
        width: 100% !important;
        height: auto !important;
        overflow-y: visible !important;
        padding: 4px;
        /* Minimal padding */
        display: block !important;
    }

    .month-card {
        width: 100%;
        margin-bottom: 24px;
        break-inside: avoid;
        padding: 4px;
        /* Reduce card padding */
    }

    .calendar-grid {
        gap: 1px;
        /* Tighter grid */
    }

    .day {
        font-size: 0.75rem;
        /* Smaller font */
        height: auto;
        /* Let height adapt */
        aspect-ratio: auto;
        /* Remove strict square if needed, or keep it but smaller */
        padding: 4px 0;
    }

    .day span {
        font-size: 0.85rem;
        /* Date number */
    }

    .hijri-date {
        font-size: 0.6rem;
    }

    .std-hijri {
        font-size: 0.55rem;
    }

    .input-group {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .history-row {
        flex-wrap: wrap;
    }
}

.sidebar {
    width: 380px;
    background: white;
    border-right: 1px solid var(--border);
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
}

.subtitle {
    font-size: 0.8rem;
    color: #64748b;
    margin: 0;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    margin-top: 4px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

input,
select {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.button-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-calc {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.btn-sample {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
}

.stats-panel {
    background: #f1f5f9;
    padding: 16px;
    border-radius: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    font-size: 0.85rem;
}

.stat-box span {
    color: #64748b;
    display: block;
}

.main-view {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.empty-state {
    grid-column: 1/-1;
    text-align: center;
    color: #94a3b8;
    padding-top: 100px;
}

.month-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.month-title {
    text-align: center;
    font-weight: 800;
    margin-bottom: 12px;
    font-size: 1.1rem;
}

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

.day-name {
    font-weight: 700;
    color: #94a3b8;
    font-size: 0.7rem;
    text-align: center;
    padding-bottom: 8px;
}

.day {
    aspect-ratio: 1;
    border-top: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 0.95rem;
}

.hijri-date {
    font-size: 0.6rem;
    color: #b45309;
    font-weight: 600;
    margin-top: 0;
}

.hijri-label {
    font-size: 0.55rem;
    color: white;
    background: #d97706;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 800;
    position: absolute;
    bottom: 4px;
}

.is-hajj {
    background: var(--hajj-bg);
    color: var(--hajj-text);
    font-weight: bold;
}

.is-period {
    background: var(--period-bg);
    color: var(--period-text);
}

.is-medication {
    background: var(--med-bg);
    color: var(--med-text);
    border: 1px dashed #93c5fd;
}

.is-conflict {
    background: linear-gradient(135deg, var(--period-bg) 50%, var(--hajj-bg) 50%);
    border: 2px solid #ef4444;
    /* Red border to highlight risk */
    font-weight: bold;
}

.legend {
    font-size: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Cross-Check Style */
.std-hijri {
    font-size: 0.5rem;
    color: #888;
    margin-top: 1px;
    border-top: 1px solid #eee;
    line-height: 1;
}

.cycle-info {
    font-weight: bold;
    color: #4CAF50;
    margin-top: 10px;
}

/* Tabs */
.tab-container {
    display: flex;
    background: #f0f0f0;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 8px;
    gap: 4px;
}

.tab-container input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tab-label {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
}

.tab-container input[type="radio"]:checked+.tab-label {
    background: white;
    color: #4CAF50;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none;
}

.box {
    width: 12px;
    height: 12px;
    border: 1px solid #ddd;
    border-radius: 2px;
    flex-shrink: 0;
}

/* History Input Styling */
.history-row {
    display: flex;
    gap: 1px;
    margin-bottom: 1px;
}

#extra-cycles {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#extra-cycles.hidden {
    display: none;
}

.history-date {
    flex: 2;
}

.history-dur {
    flex: 1;
    min-width: 60px;
    text-align: center;
}

/* Calendar History Marker */
.is-history {
    background: #e2e8f0;
    /* Slate-200 */
    color: #475569;
    font-style: italic;
}

.credits {
    margin-top: auto;
    font-size: 0.7rem;
    color: #94a3b8;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    line-height: 1.4;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}