:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-hover: #f0f1f5;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #e0e7ff;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface-hover: #252539;
    --text: #e4e4e7;
    --text-muted: #9ca3af;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-light: #312e81;
    --border: #2d2d44;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.hidden { display: none !important; }

/* AUTH */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
    color: var(--primary);
}

.auth-logo h1 {
    font-size: 24px;
    margin-top: 12px;
    color: var(--text);
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 4px;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 24px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-form input, .inline-form input, .modal input {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    transition: border 0.2s;
}

.auth-form input:focus, .inline-form input:focus, .modal input:focus {
    outline: none;
    border-color: var(--primary);
}

/* BUTTONS */
.btn-primary {
    padding: 12px 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

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

.btn-secondary {
    padding: 12px 24px;
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--surface-hover);
    color: var(--text);
}

/* NAVBAR */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
}

.nav-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

#user-info {
    font-size: 14px;
    color: var(--text-muted);
}

/* TAB BAR */
.tab-bar {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    position: sticky;
    top: 57px;
    z-index: 99;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    min-width: 80px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover { color: var(--primary); }

/* CONTENT */
.content {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.filter-buttons {
    display: flex;
    gap: 6px;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* INLINE FORM */
.inline-form {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.inline-form input {
    flex: 1;
    min-width: 120px;
}

.inline-form.multi input {
    flex: 1;
    min-width: 100px;
}

.qty-input { max-width: 80px; }

/* ITEM LIST */
.item-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    transition: all 0.2s;
}

.item-row:hover { box-shadow: var(--shadow-lg); }

.item-row.done .item-name {
    text-decoration: line-through;
    color: var(--text-muted);
}

.item-checkbox {
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.item-name {
    flex: 1;
    font-size: 15px;
}

.item-qty {
    color: var(--text-muted);
    font-size: 13px;
    background: var(--bg);
    padding: 2px 10px;
    border-radius: 12px;
}

.item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

.item-actions {
    display: flex;
    gap: 4px;
}

.btn-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-delete:hover {
    color: var(--danger);
    background: rgba(239,68,68,0.1);
}

.btn-cook {
    padding: 6px 14px;
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-cook:hover { background: #16a34a; }

/* PRODUCTS GRID */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 16px;
    transition: all 0.2s;
}

.product-card:hover { box-shadow: var(--shadow-lg); }

.product-card .product-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.product-card .product-category {
    display: inline-block;
    font-size: 12px;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 10px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.product-card .product-notes {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.product-card .product-actions {
    display: flex;
    gap: 8px;
}

.product-card .btn-add-to-list {
    flex: 1;
    padding: 8px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.product-card .btn-add-to-list:hover { background: var(--primary-hover); }

/* TOTAL DISPLAY */
.total-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    color: var(--text-muted);
}

.total-display strong {
    color: var(--primary);
    font-size: 20px;
}

/* EXPENSE ITEM */
.expense-amount {
    font-weight: 700;
    font-size: 16px;
    color: var(--danger);
}

.expense-category {
    font-size: 12px;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 10px;
    border-radius: 12px;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    margin-bottom: 20px;
    font-size: 20px;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

/* ERROR MSG */
.error-msg {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
    text-align: center;
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--surface);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* MEAL ITEM */
.meal-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meal-times {
    font-size: 12px;
    color: var(--text-muted);
}

.meal-last-cooked {
    font-size: 12px;
    color: var(--success);
    font-weight: 500;
}

/* MEMBERS */
.member-row {
    align-items: flex-start;
}

.member-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.member-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
}

.member-avatar-img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.avatar-upload-btn {
    position: absolute;
    bottom: -2px;
    right: -2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}

.avatar-upload-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.member-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.member-name {
    font-size: 15px;
    font-weight: 600;
}

.member-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.member-role {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.member-role.admin {
    background: var(--primary-light);
    color: var(--primary);
}

.member-role.member {
    background: var(--bg);
    color: var(--text-muted);
}

.btn-role {
    padding: 6px 14px;
    background: var(--surface-hover);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-role:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* TASKS */
.task-row {
    align-items: center;
    gap: 12px;
}

.task-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.task-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.task-title {
    font-size: 15px;
    font-weight: 500;
}

.task-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* SELECT INPUTS */
.select-input {
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

/* CHECKBOX LABEL */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.checkbox-label input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* DATE INPUT */
.date-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
}

/* BUTTON SMALL */
.btn-sm {
    padding: 6px 12px;
    font-size: 14px;
}

/* WEEK NAV */
.week-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

#week-label {
    font-size: 15px;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
}

/* MEAL CALENDAR */
.meal-calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}

.cal-day {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    min-height: 200px;
}

.cal-day.today {
    border-color: var(--primary);
    border-width: 2px;
}

.cal-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.cal-day-header strong {
    font-size: 13px;
}

.cal-day-header span {
    font-size: 12px;
    color: var(--text-muted);
}

.cal-meals {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cal-meal-item {
    padding: 6px 8px;
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    transition: opacity 0.2s;
}

.cal-meal-item:hover {
    opacity: 0.7;
}

.cal-meal-empty {
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px dashed var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.cal-meal-empty:hover {
    background: var(--surface-hover);
}

/* BUDGET */
.budget-summary {
    margin-bottom: 16px;
}

.budget-cards {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.budget-card {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.budget-card span {
    font-size: 12px;
    color: var(--text-muted);
}

.budget-card strong {
    font-size: 22px;
}

.budget-progress {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.budget-progress-bar {
    height: 100%;
    transition: width 0.3s;
    border-radius: 4px;
}

/* STATS GRID */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.stat-card h3 {
    font-size: 15px;
    margin-bottom: 16px;
}

.top-list, .audit-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.top-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-size: 14px;
}

.audit-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.audit-user {
    font-size: 13px;
    font-weight: 600;
}

.audit-action {
    font-size: 12px;
    color: var(--text-muted);
}

.audit-time {
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* DASHBOARD */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.dash-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.dash-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.dash-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.dash-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dash-info strong {
    font-size: 24px;
}

.dash-info span {
    font-size: 13px;
    color: var(--text-muted);
}

.dashboard-sections {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.dash-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.dash-panel h3 {
    font-size: 15px;
    margin-bottom: 12px;
}

/* GLOBAL SEARCH */
.global-search {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    width: 250px;
}

.search-results {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--surface-hover);
}

.search-result-type {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg);
}

/* TAB BADGES */
.tab-btn .badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.tab-btn {
    position: relative;
}

/* CONFIRM MODAL */
.modal-sm {
    max-width: 380px;
}

.btn-danger-confirm {
    background: var(--danger) !important;
}

/* ADVANCED TOAST */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 24px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 90vw;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.info {
    border-left: 4px solid var(--primary);
}

/* PRINT STYLES */
@media print {
    nav, .tab-bar, .filter-buttons, .inline-form, .section-header button, .modal-overlay, #global-search, .dash-card, .dashboard-sections, .stats-grid, .budget-summary, .budget-progress, .btn-delete, .btn-role, .item-actions {
        display: none !important;
    }
    .tab-section { display: none !important; }
    .tab-section.active { display: block !important; }
    body { background: #fff !important; color: #000 !important; }
    .item-list { list-style: none; padding: 0; }
    .item-row { border: 1px solid #ccc !important; padding: 8px 12px; border-radius: 4px; margin-bottom: 4px; }
}

/* RESPONSIVE */
@media (max-width: 600px) {
    .content { padding: 16px 12px 40px; }
    .auth-card { padding: 28px 20px; }
    .inline-form input { min-width: 100px; }
    .section-header h2 { font-size: 18px; }
    #user-info { display: none; }
    .tab-btn span { font-size: 11px; }
    .meal-calendar { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr; }
    .budget-cards { flex-direction: column; }
    .inline-form.multi { flex-direction: column; }
    .inline-form.multi input, .inline-form.multi select { width: 100%; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .dashboard-sections { grid-template-columns: 1fr; }
    .global-search { width: 100%; }
}
