/* ===== CSS Variables ===== */
:root[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8faf9;
    --bg-tertiary: #f0f5f3;
    --bg-card: #ffffff;
    --text-primary: #1a1d1b;
    --text-secondary: #4a5249;
    --text-muted: #7a8479;
    --border: #dce5dc;
    --border-light: #e8ede8;
    --accent: #0d9668;
    --accent-hover: #0a7d56;
    --accent-light: #e6f7f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
    --hot-bg: #fef3e6;
    --hot-text: #b45309;
    --hot-border: #f59e0b;
    --iced-bg: #e6f2fe;
    --iced-text: #1d6fb5;
    --iced-border: #3b8bd4;
    --tea-bg: #ecfdf5;
    --tea-text: #047857;
    --tea-border: #10b981;
    --utility-bg: #f3f4f6;
    --utility-text: #6b7280;
    --utility-border: #9ca3af;
    --stat-total-bg: #f0f5f3;
    --stat-total-text: #0d9668;
    --stat-hot-bg: #fef3e6;
    --stat-hot-text: #b45309;
    --stat-iced-bg: #e6f2fe;
    --stat-iced-text: #1d6fb5;
    --nav-bg: rgba(255,255,255,0.85);
    --input-bg: #ffffff;
    --modal-overlay: rgba(0,0,0,0.4);
}

:root[data-theme="dark"] {
    --bg-primary: #0f1210;
    --bg-secondary: #171c19;
    --bg-tertiary: #1e2622;
    --bg-card: #1e2622;
    --text-primary: #e4e8e5;
    --text-secondary: #b0b8af;
    --text-muted: #7a8479;
    --border: #2e3a32;
    --border-light: #253029;
    --accent: #34d399;
    --accent-hover: #4eeab0;
    --accent-light: #0d3325;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --hot-bg: #3a2508;
    --hot-text: #fbbf24;
    --hot-border: #b45309;
    --iced-bg: #0a2540;
    --iced-text: #60a5fa;
    --iced-border: #1d6fb5;
    --tea-bg: #052e1b;
    --tea-text: #6ee7b7;
    --tea-border: #047857;
    --utility-bg: #272b2e;
    --utility-text: #9ca3af;
    --utility-border: #6b7280;
    --stat-total-bg: #0d3325;
    --stat-total-text: #34d399;
    --stat-hot-bg: #3a2508;
    --stat-hot-text: #fbbf24;
    --stat-iced-bg: #0a2540;
    --stat-iced-text: #60a5fa;
    --nav-bg: rgba(15,18,16,0.9);
    --input-bg: #171c19;
    --modal-overlay: rgba(0,0,0,0.7);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

/* ===== Navbar ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.brand-icon {
    font-size: 1.5rem;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-user {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-right: 0.25rem;
}

.logout-form {
    display: inline;
    margin: 0;
    padding: 0;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    transition: all 0.2s;
    white-space: nowrap;
    font-family: inherit;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

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

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

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

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    font-size: 1rem;
}

.btn-icon:hover {
    border-color: var(--accent);
}

[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* ===== Stats Bar ===== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border-radius: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-total {
    background: var(--stat-total-bg);
    color: var(--stat-total-text);
}

.stat-hot {
    background: var(--stat-hot-bg);
    color: var(--stat-hot-text);
}

.stat-iced {
    background: var(--stat-iced-bg);
    color: var(--stat-iced-text);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
    opacity: 0.85;
}

/* ===== Filters ===== */
.filters-section {
    margin-bottom: 1.25rem;
}

.search-box {
    margin-bottom: 0.75rem;
}

.input-field {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.input-field::placeholder {
    color: var(--text-muted);
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-select {
    flex: 1;
    min-width: 140px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a8479' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ===== Recipe Grid ===== */
.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.recipe-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.recipe-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.recipe-card.hidden {
    display: none;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 1rem 0.5rem;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
}

.card-body {
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem;
}

.card-detail {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.detail-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.card-footer {
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    border: 1px solid;
    flex-shrink: 0;
}

.badge-hot {
    background: var(--hot-bg);
    color: var(--hot-text);
    border-color: var(--hot-border);
}

.badge-iced {
    background: var(--iced-bg);
    color: var(--iced-text);
    border-color: var(--iced-border);
}

.badge-tea {
    background: var(--tea-bg);
    color: var(--tea-text);
    border-color: var(--tea-border);
}

.badge-utility {
    background: var(--utility-bg);
    color: var(--utility-text);
    border-color: var(--utility-border);
}

/* ===== No Results ===== */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-light);
    margin-top: auto;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .recipe-grid {
        grid-template-columns: 1fr;
    }

    .filter-row {
        flex-direction: column;
    }

    .filter-select {
        width: 100%;
        min-width: 0;
    }

    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-card {
        padding: 0.75rem 0.5rem;
    }

    .nav-user {
        display: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.75rem;
    }

    .card-body {
        grid-template-columns: 1fr;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Transitions for theme switch ===== */
.navbar,
.recipe-card,
.stat-card,
.filter-select,
.input-field,
.footer {
    transition: background 0.3s, border-color 0.3s, color 0.3s;
}

/* ===== Auth Pages ===== */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.auth-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

[data-theme="dark"] .auth-error {
    background: #3b1111;
    border-color: #7f1d1d;
    color: #fca5a5;
}

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

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.btn-full {
    width: 100%;
    padding: 0.625rem;
    margin-top: 0.5rem;
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--accent);
    font-weight: 500;
}

/* ===== Search Row (search + add button) ===== */
.search-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: stretch;
}

.search-row .search-box {
    flex: 1;
    margin-bottom: 0;
}

.btn-add {
    white-space: nowrap;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    border-radius: 8px;
    flex-shrink: 0;
}

/* ===== Edit Button ===== */
.btn-edit {
    font-size: 0.75rem;
}

/* ===== Delete Button ===== */
.btn-danger {
    background: #dc2626;
    color: #fff;
    border: none;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* ===== Alert Messages ===== */
.messages-container {
    margin-top: 1rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.alert-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

[data-theme="dark"] .alert-success {
    background: #052e1b;
    border-color: #047857;
    color: #6ee7b7;
}

/* ===== Recipe Form Page ===== */
.form-page {
    display: flex;
    justify-content: center;
    padding: 2rem 0;
}

/* ===== Recipe Detail Page ===== */
.detail-page {
    display: flex;
    justify-content: center;
    padding: 2rem 0;
}

.detail-card {
    width: 100%;
    max-width: 640px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.detail-header-left,
.detail-header-right {
    display: flex;
    gap: 0.5rem;
}

.detail-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.detail-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
}

.badge-lg {
    font-size: 0.8rem;
    padding: 0.3rem 0.8rem;
    flex-shrink: 0;
    margin-top: 0.2rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.detail-item-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.detail-item-value {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.detail-link-section {
    margin-bottom: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-light);
}

.btn-lg-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
}

.detail-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.detail-meta span + span {
    margin-left: 0.25rem;
}

/* ===== Card Title Link ===== */
.card-title-link {
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.card-title-link:hover {
    color: var(--accent);
}

/* ===== My Recipes Toggle ===== */
.btn-filter-toggle {
    white-space: nowrap;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .detail-card {
        padding: 1.25rem;
    }

    .detail-name {
        font-size: 1.25rem;
    }
}

.form-card {
    width: 100%;
    max-width: 640px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.form-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-light);
}

@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-card {
        padding: 1.25rem;
    }

    .search-row {
        flex-direction: column;
    }

    .btn-add {
        width: 100%;
    }
}
