/* ================================================================
   Meal Planner — Stylesheet
   Clean, card-based layout with soft shadows and warm neutrals
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&display=swap');

/* ── CSS Variables ──────────────────────────────────────────── */
:root {
    --bg:           #f5f3ef;
    --bg-card:      #ffffff;
    --bg-sidebar:   #faf9f7;
    --text:         #2c2826;
    --text-muted:   #8a8380;
    --text-light:   #b0aaa6;
    --accent:       #d4763c;
    --accent-hover: #c06830;
    --accent-light: #fdf0e8;
    --green:        #5a9a6e;
    --green-light:  #eef6f0;
    --red:          #c95454;
    --red-light:    #fdeaea;
    --border:       #e8e4df;
    --shadow-sm:    0 1px 3px rgba(44,40,38,0.06);
    --shadow-md:    0 4px 16px rgba(44,40,38,0.08);
    --shadow-lg:    0 8px 32px rgba(44,40,38,0.10);
    --radius:       12px;
    --radius-sm:    8px;
    --radius-xs:    6px;
    --font-body:    'DM Sans', sans-serif;
    --font-display: 'Fraunces', serif;
    --transition:   0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ── App Header ─────────────────────────────────────────────── */
.app-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.app-header h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.app-header h1 span.icon {
    font-size: 1.3rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* ── Navigation Tabs ────────────────────────────────────────── */
.nav-tabs {
    display: none; /* shown on mobile */
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    gap: 0;
    overflow-x: auto;
}

.nav-tabs button {
    background: none;
    border: none;
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: var(--transition);
}

.nav-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ── Main Layout ────────────────────────────────────────────── */
.app-layout {
    display: grid;
    grid-template-columns: 340px 1fr 360px;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 60px);
}

/* ── Panels / Cards ─────────────────────────────────────────── */
.panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 90px);
}

.panel-header {
    padding: 1.1rem 1.25rem 0.9rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.panel-header h2 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.panel-body {
    padding: 1rem 1.25rem;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.panel-body::-webkit-scrollbar {
    width: 5px;
}

.panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.panel-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.panel-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-sidebar);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-xs);
    font-family: var(--font-body);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 0.35rem 0.6rem;
}

.btn-ghost:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-danger {
    background: var(--red-light);
    color: var(--red);
}

.btn-danger:hover {
    background: var(--red);
    color: #fff;
}

.btn-success {
    background: var(--green);
    color: #fff;
}

.btn-success:hover {
    background: #4e8a60;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
}

.btn-block {
    width: 100%;
}

/* ── Form Elements ──────────────────────────────────────────── */
input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-family: var(--font-body);
    font-size: 0.87rem;
    color: var(--text);
    background: #fff;
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-light);
}

textarea {
    resize: vertical;
    min-height: 60px;
}

label {
    display: block;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group {
    margin-bottom: 0.85rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 80px 80px;
    gap: 0.5rem;
    align-items: end;
}

/* ── Search Input ───────────────────────────────────────────── */
.search-wrap {
    position: relative;
    margin-bottom: 0.85rem;
}

.search-wrap input {
    padding-left: 2.2rem;
}

.search-wrap .search-icon {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 0.9rem;
    pointer-events: none;
}

/* ── Recipe List ────────────────────────────────────────────── */
.recipe-item {
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.6rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.recipe-item:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.recipe-item.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.recipe-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.15rem;
}

.recipe-item-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.recipe-item-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.2rem;
    opacity: 0;
    transition: var(--transition);
}

.recipe-item:hover .recipe-item-actions {
    opacity: 1;
}

.recipe-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: var(--bg);
    border-radius: 20px;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Recipe Editor (Modal-like overlay within panel) ─────── */
.recipe-editor {
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.85rem;
    border: 1px solid var(--border);
}

.recipe-editor-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.85rem;
}

.ingredient-row {
    display: grid;
    grid-template-columns: 1fr 70px 70px 32px;
    gap: 0.4rem;
    align-items: center;
    margin-bottom: 0.4rem;
}

.ingredient-row .btn-remove {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--red-light);
    color: var(--red);
    border: none;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.ingredient-row .btn-remove:hover {
    background: var(--red);
    color: #fff;
}

.editor-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ── Weekly Planner ─────────────────────────────────────────── */
.planner-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.6rem;
}

.day-column {
    min-width: 0;
}

.day-header {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.88rem;
    text-align: center;
    padding: 0.6rem 0.4rem;
    background: var(--bg);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border: 1px solid var(--border);
    border-bottom: 2px solid var(--accent);
}

.day-body {
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    padding: 0.5rem;
    min-height: 140px;
    background: var(--bg-sidebar);
}

.day-meal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 0.4rem 0.55rem;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    transition: var(--transition);
}

.day-meal:hover {
    box-shadow: var(--shadow-sm);
}

.day-meal-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.day-meal .btn-remove-meal {
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 50%;
    font-size: 0.85rem;
    flex-shrink: 0;
    transition: var(--transition);
}

.day-meal .btn-remove-meal:hover {
    background: var(--red-light);
    color: var(--red);
}

.day-add {
    margin-top: 0.35rem;
}

.day-add select {
    font-size: 0.78rem;
    padding: 0.35rem 0.5rem;
    background: var(--bg-card);
}

/* ── Planner Actions Bar ────────────────────────────────────── */
.planner-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ── Shopping List ──────────────────────────────────────────── */
.shopping-section-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

.shopping-section-title:first-child {
    margin-top: 0;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0ede9;
    transition: var(--transition);
}

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

.shopping-item.checked .shopping-item-text {
    text-decoration: line-through;
    color: var(--text-light);
}

.shopping-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--green);
    cursor: pointer;
    flex-shrink: 0;
}

.shopping-item-text {
    flex: 1;
    font-size: 0.87rem;
}

.shopping-item-qty {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

/* ── Snacks Section ─────────────────────────────────────────── */
.snack-input-row {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.snack-input-row input {
    flex: 1;
}

.snack-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    font-size: 0.87rem;
    border-bottom: 1px solid #f0ede9;
}

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

.snack-item-name {
    flex: 1;
}

.snack-item .btn-remove-snack {
    width: 22px;
    height: 22px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 50%;
    font-size: 0.85rem;
    transition: var(--transition);
}

.snack-item .btn-remove-snack:hover {
    background: var(--red-light);
    color: var(--red);
}

/* ── Empty States ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-light);
    font-size: 0.85rem;
}

.empty-state .empty-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

/* ── Toast Notifications ────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--text);
    color: #fff;
    padding: 0.7rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.2s forwards;
    max-width: 320px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(10px); }
}

/* ── Save indicator ─────────────────────────────────────────── */
.save-indicator {
    font-size: 0.78rem;
    color: var(--green);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.save-indicator.visible {
    opacity: 1;
}

/* ── Print Styles ───────────────────────────────────────────── */
@media print {
    .app-header, .nav-tabs, .panel:first-child, .panel:nth-child(2),
    .panel-footer, .btn, .snack-input-row, .day-add, select {
        display: none !important;
    }

    .app-layout {
        display: block !important;
        padding: 0;
    }

    .panel {
        box-shadow: none !important;
        border: none !important;
        max-height: none !important;
        break-inside: avoid;
    }

    .panel:last-child {
        display: block !important;
    }

    .shopping-item input[type="checkbox"] {
        -webkit-appearance: none;
        appearance: none;
        width: 14px;
        height: 14px;
        border: 1.5px solid #333;
        border-radius: 2px;
    }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .app-layout {
        grid-template-columns: 1fr;
        padding: 0.75rem;
    }

    .nav-tabs {
        display: flex;
    }

    .panel {
        max-height: none;
    }

    .panel.hidden-mobile {
        display: none;
    }

    .planner-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 0.75rem 1rem;
    }

    .app-header h1 {
        font-size: 1.2rem;
    }

    .planner-grid {
        grid-template-columns: 1fr;
    }

    .ingredient-row {
        grid-template-columns: 1fr 60px 60px 28px;
    }
}

/* ── Utility ────────────────────────────────────────────────── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ── Loading spinner ────────────────────────────────────────── */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
}

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

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