/* Weekly Plan Calendar - Responsive Design */

:root {
    --plan-primary: #6366F1;
    --plan-primary-light: #eef2ff;
    --plan-border: #e5e7eb;
    --plan-text: #1f2937;
    --plan-text-muted: #6b7280;
    --plan-bg: #ffffff;
    --plan-radius: 10px;
    --plan-gap: 0.5rem;
}

/* Prevent horizontal overflow */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
}

main.page-main {
    overflow-x: hidden;
}

/* Calendar Container */
#plan-calendar {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 2rem 1.5rem;
}

/* Header with title and actions */
#plan-calendar > .flex.items-center.justify-between {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--plan-border);
}

#plan-calendar h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--plan-text);
    margin: 0;
}

#plan-calendar .flex.items-center.gap-2 {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

#plan-calendar .btn-sm {
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    white-space: nowrap;
}

/* Grid Container */
#plan-grid {
    display: grid;
    gap: 0.75rem;
    width: 100%;
}

/* Day Card */
.plan-day {
    background: var(--plan-bg);
    border: 2px solid var(--plan-border);
    border-radius: var(--plan-radius);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
    overflow: hidden;
}

.plan-day__header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--plan-primary-light);
    gap: 0.35rem;
}

.plan-day__name {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--plan-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plan-day__date {
    font-size: 0.95rem;
    color: var(--plan-text-muted);
    white-space: nowrap;
}

.plan-day__slots {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Meal Slot Base */
.plan-slot {
    border-radius: 8px;
    padding: 0.9rem;
    min-width: 0;
    overflow: hidden;
}

/* Slot Type Badge */
.plan-slot__type {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--plan-primary);
    background: var(--plan-primary-light);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    line-height: 1;
}

/* Past Meal */
.plan-slot--past {
    background: #f9fafb;
    border: 2px dashed #d1d5db;
    opacity: 0.6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.plan-slot__past-label {
    font-size: 0.7rem;
    color: #9ca3af;
    font-style: italic;
}

/* Empty Slot */
.plan-slot--empty {
    background: #fafbfc;
    border: 2px dashed #d1d5db;
    color: #9ca3af;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
}

/* Pending/Loading Slot */
.plan-slot--pending {
    background: #fafbff;
    border: 2px solid var(--plan-primary-light);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.plan-slot__skeleton {
    height: 2rem;
    background: linear-gradient(90deg, #f3f4f6 0%, #eef2ff 50%, #f3f4f6 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Ready Slot */
.plan-slot--ready {
    background: var(--plan-bg);
    border: 2px solid var(--plan-primary-light);
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.plan-slot__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
}

.plan-slot__lock {
    width: 0.8rem;
    height: 0.8rem;
    color: var(--plan-primary);
    stroke: currentColor;
    flex-shrink: 0;
}

.plan-slot__name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--plan-text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    hyphens: auto;
}

.plan-slot__meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--plan-text-muted);
}

.plan-slot__meta span {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

/* Action Buttons */
.plan-slot__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--plan-border);
}

.plan-slot__btn {
    flex: 1 1 auto;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: #f9fafb;
    border: 1px solid var(--plan-border);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--plan-text);
}

.plan-slot__btn svg {
    width: 100%;
    height: 100%;
    padding: 0.25rem;
    box-sizing: border-box;
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    color: var(--plan-text);
}

.plan-slot__btn:hover {
    background: var(--plan-primary);
    border-color: var(--plan-primary);
    transform: scale(1.05);
    color: white;
}

.plan-slot__btn:hover svg {
    color: white;
}

.plan-slot__btn--active {
    background: var(--plan-primary-light);
    border-color: var(--plan-primary);
    color: var(--plan-primary);
}

.plan-slot__btn--active svg {
    color: var(--plan-primary);
}

/* Button Danger */
.btn-danger {
    background: #ef4444 !important;
    color: white !important;
    border: 2px solid #ef4444 !important;
}

.btn-danger:hover {
    background: #dc2626 !important;
    border-color: #dc2626 !important;
}

/* ============================================
   MOBILE FIRST (up to 639px)
   Phones Portrait
   ============================================ */

@media (max-width: 639px) {
    #plan-calendar {
        padding: 0.5rem;
    }

    #plan-calendar > .flex.items-center.justify-between {
        flex-direction: column;
        align-items: stretch;
    }

    #plan-calendar h3 {
        text-align: center;
        font-size: 1.25rem;
    }

    #plan-calendar .flex.items-center.gap-2 {
        flex-direction: column;
        width: 100%;
    }

    #plan-calendar .btn-sm {
        width: 100%;
        justify-content: center;
    }

    #plan-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .plan-day {
        padding: 1rem;
    }

    .plan-day__header {
        padding-bottom: 0.75rem;
    }

    .plan-day__name {
        font-size: 1.1rem;
    }

    .plan-day__date {
        font-size: 0.85rem;
    }

    .plan-slot {
        padding: 0.875rem;
    }

    .plan-slot__type {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .plan-slot__name {
        font-size: 0.95rem;
        -webkit-line-clamp: 3;
    }

    .plan-slot__meta {
        font-size: 0.75rem;
    }

    .plan-slot__btn {
        min-width: 2.25rem;
        height: 2.25rem;
        font-size: 1rem;
    }
}

/* ============================================
   PHONE LANDSCAPE (640px - 767px)
   ============================================ */

@media (min-width: 640px) and (max-width: 767px) {
    #plan-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    .plan-day {
        padding: 0.875rem;
    }

    .plan-slot__name {
        font-size: 0.85rem;
    }

    .plan-slot__btn {
        min-width: 2rem;
        height: 2rem;
    }
}

/* ============================================
   TABLET PORTRAIT (768px - 1023px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1023px) {
    #plan-calendar {
        padding: 1.25rem;
    }

    #plan-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }

    .plan-day__name {
        font-size: 0.95rem;
    }

    .plan-slot__name {
        font-size: 0.85rem;
    }

    .plan-slot__btn {
        min-width: 1.875rem;
        height: 1.875rem;
    }
}

/* ============================================
   TABLET LANDSCAPE / SMALL LAPTOP (1024px - 1279px)
   ============================================ */

@media (min-width: 1024px) and (max-width: 1279px) {
    #plan-calendar {
        padding: 1.5rem;
        max-width: 1400px;
        margin: 0 auto;
    }

    #plan-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.625rem;
    }

    .plan-day {
        padding: 0.625rem;
    }

    .plan-day__name {
        font-size: 0.85rem;
    }

    .plan-day__date {
        font-size: 0.7rem;
    }

    .plan-slot {
        padding: 0.5rem;
    }

    .plan-slot__type {
        font-size: 0.6rem;
        padding: 0.15rem 0.35rem;
    }

    .plan-slot__name {
        font-size: 0.75rem;
    }

    .plan-slot__meta {
        font-size: 0.6rem;
    }

    .plan-slot__btn {
        min-width: 1.5rem;
        height: 1.5rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   LAPTOP (1280px - 1535px)
   Full 7-day view with horizontal scroll if needed
   ============================================ */

@media (min-width: 1280px) and (max-width: 1535px) {
    #plan-calendar {
        padding: 1.5rem;
        max-width: 100%;
    }

    #plan-grid {
        display: grid;
        grid-template-columns: repeat(7, minmax(140px, 1fr));
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--plan-primary) #f3f4f6;
        padding-bottom: 0.5rem;
    }

    #plan-grid::-webkit-scrollbar {
        height: 8px;
    }

    #plan-grid::-webkit-scrollbar-track {
        background: #f3f4f6;
        border-radius: 4px;
    }

    #plan-grid::-webkit-scrollbar-thumb {
        background: var(--plan-primary);
        border-radius: 4px;
    }

    .plan-day {
        min-width: 140px;
        padding: 0.5rem;
    }

    .plan-day__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        padding-bottom: 0.375rem;
    }

    .plan-day__name {
        font-size: 0.8rem;
    }

    .plan-day__date {
        font-size: 0.65rem;
    }

    .plan-slot {
        padding: 0.4rem;
    }

    .plan-slot__type {
        font-size: 0.55rem;
        padding: 0.125rem 0.3rem;
    }

    .plan-slot__name {
        font-size: 0.7rem;
        -webkit-line-clamp: 2;
    }

    .plan-slot__meta {
        font-size: 0.55rem;
        gap: 0.25rem;
    }

    .plan-slot__actions {
        gap: 0.2rem;
        padding-top: 0.25rem;
        margin-top: 0.2rem;
    }

    .plan-slot__btn {
        min-width: 1.375rem;
        height: 1.375rem;
        font-size: 0.7rem;
        border-radius: 4px;
    }
}

/* ============================================
   LARGE DESKTOP (1536px+)
   Comfortable 7-day view
   ============================================ */

@media (min-width: 1536px) {
    #plan-calendar {
        padding: 2rem;
        max-width: 1800px;
        margin: 0 auto;
    }

    #plan-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 0.75rem;
    }

    .plan-day {
        padding: 0.75rem;
    }

    .plan-day__header {
        flex-direction: row;
        align-items: baseline;
    }

    .plan-day__name {
        font-size: 0.9rem;
    }

    .plan-day__date {
        font-size: 0.75rem;
    }

    .plan-slot {
        padding: 0.625rem;
    }

    .plan-slot__type {
        font-size: 0.625rem;
    }

    .plan-slot__name {
        font-size: 0.8rem;
    }

    .plan-slot__meta {
        font-size: 0.65rem;
    }

    .plan-slot__btn {
        min-width: 1.625rem;
        height: 1.625rem;
        font-size: 0.8rem;
    }

    .plan-slot__btn:hover {
        transform: scale(1.1);
    }
}

/* ============================================
   ORIENTATION SPECIFIC ADJUSTMENTS
   ============================================ */

@media (orientation: landscape) and (max-height: 500px) {
    #plan-calendar > .flex.items-center.justify-between {
        flex-direction: row;
        padding-bottom: 0.75rem;
        margin-bottom: 0.75rem;
    }

    #plan-calendar h3 {
        font-size: 1.1rem;
    }

    #plan-calendar .btn-sm {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }

    .plan-day {
        padding: 0.5rem;
    }

    .plan-slot {
        padding: 0.375rem;
    }
}

/* ============================================
   ACCESSIBILITY & FOCUS STATES
   ============================================ */

.plan-slot__btn:focus {
    outline: 2px solid var(--plan-primary);
    outline-offset: 2px;
}

.plan-slot__btn:focus:not(:focus-visible) {
    outline: none;
}

.plan-slot__btn:focus-visible {
    outline: 2px solid var(--plan-primary);
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .plan-slot__skeleton {
        animation: none;
        background: #eef2ff;
    }

    .plan-slot__btn {
        transition: none;
    }
}

/* ============================================
   BOTTOM ACTIONS BAR
   ============================================ */

#plan-calendar > .settings-actions {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--plan-border);
    display: flex;
    justify-content: center;
}

/* Plan Header Layout */
.plan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--plan-border);
}

.plan-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Mobile Menu */
.plan-menu-mobile {
    position: relative;
    display: none;
}

.plan-menu-btn-mobile {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: #f9fafb;
    border: 2px solid var(--plan-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--plan-text);
}

.plan-menu-btn-mobile:hover {
    background: var(--plan-primary);
    border-color: var(--plan-primary);
    color: white;
    transform: scale(1.05);
}

.plan-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 2px solid var(--plan-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    margin-top: 0.5rem;
    min-width: 160px;
    display: block;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
}

.plan-menu-dropdown.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.plan-menu-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--plan-border);
    cursor: pointer;
    color: var(--plan-text);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease;
}

.plan-menu-item:last-child {
    border-bottom: none;
}

.plan-menu-item:hover {
    background: var(--plan-primary-light);
    color: var(--plan-primary);
}

.plan-menu-item--danger {
    color: #dc2626;
}

.plan-menu-item--danger:hover {
    background: #fee2e2;
    color: #dc2626;
}

.hidden-mobile {
    display: inline-block;
}

@media (min-width: 768px) {
    .plan-menu-mobile {
        display: none !important;
    }
    
    .hidden-mobile {
        display: inline-block !important;
    }
}

@media (max-width: 767px) {
    .plan-menu-mobile {
        display: block;
    }
    
    .hidden-mobile {
        display: none;
    }
}

@media (max-width: 639px) {
    #plan-calendar > .settings-actions {
        padding: 1rem 0 0;
    }

    #plan-calendar .settings-actions .btn-secondary {
        width: 100%;
    }
}
