:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --danger: #dc2626;
    --warning: #f59e0b;
    --success: #16a34a;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-900: #0f172a;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */
.app-bar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.app-bar h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.app-bar-actions { display: flex; gap: 10px; align-items: center; }
.app-bar-actions span { font-size: 0.85rem; opacity: 0.9; font-weight: 500; }

.nav-tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.nav-tab {
    padding: 14px 24px;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--gray-500);
    border-bottom: 2.5px solid transparent;
    white-space: nowrap;
    transition: all 0.2s ease;
    letter-spacing: 0.01em;
}

.nav-tab:hover { color: var(--gray-700); background: var(--gray-50); }
.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
    background: rgba(37, 99, 235, 0.04);
}

.container { max-width: 960px; margin: 0 auto; padding: 20px 16px; }

/* ===== Cards ===== */
.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    transition: box-shadow 0.2s ease;
}

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

.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 14px;
    color: var(--gray-500);
}

/* ===== Tiles ===== */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }

.tile {
    background: white;
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

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

.tile-value { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; }
.tile-label { font-size: 0.78rem; color: var(--gray-500); margin-top: 4px; font-weight: 500; }

.tile-blue .tile-value { color: var(--primary); }
.tile-blue::before { background: var(--primary); }
.tile-green .tile-value { color: var(--success); }
.tile-green::before { background: var(--success); }
.tile-red .tile-value { color: var(--danger); }
.tile-red::before { background: var(--danger); }
.tile-yellow .tile-value { color: var(--warning); }
.tile-yellow::before { background: var(--warning); }

/* ===== Search ===== */
.search-box {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
    background: var(--gray-50);
}

.search-box:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-box::placeholder { color: var(--gray-300); }

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    letter-spacing: 0.01em;
}

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

.btn-primary { background: var(--primary); color: white; box-shadow: 0 1px 3px rgba(37,99,235,0.3); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 8px rgba(37,99,235,0.3); transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: white; box-shadow: 0 1px 3px rgba(220,38,38,0.3); }
.btn-danger:hover { background: #b91c1c; box-shadow: 0 4px 8px rgba(220,38,38,0.3); transform: translateY(-1px); }
.btn-success { background: var(--success); color: white; box-shadow: 0 1px 3px rgba(22,163,74,0.3); }
.btn-success:hover { background: #15803d; box-shadow: 0 4px 8px rgba(22,163,74,0.3); transform: translateY(-1px); }
.btn-warning { background: var(--warning); color: white; box-shadow: 0 1px 3px rgba(245,158,11,0.3); }
.btn-warning:hover { background: #d97706; box-shadow: 0 4px 8px rgba(245,158,11,0.3); transform: translateY(-1px); }
.btn-outline { background: transparent; border: 2px solid var(--gray-200); color: var(--gray-700); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: rgba(37,99,235,0.04); }
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 16px 32px; font-size: 1.15rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-use-meal {
    background: linear-gradient(135deg, var(--success) 0%, #15803d 100%);
    color: white;
    padding: 22px 40px;
    font-size: 1.3rem;
    font-weight: 700;
    border-radius: var(--radius);
    width: 100%;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(22,163,74,0.3);
    letter-spacing: 0.01em;
}

.btn-use-meal:hover {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    box-shadow: 0 6px 20px rgba(22,163,74,0.35);
    transform: translateY(-2px);
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--gray-600);
    letter-spacing: 0.01em;
}
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s ease;
    background: var(--gray-50);
}
.form-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===== Meal counter ===== */
.meal-counter {
    text-align: center;
    padding: 28px 20px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.meal-counter-value { font-size: 2.8rem; font-weight: 800; letter-spacing: -0.02em; }
.meal-counter-label { font-size: 0.95rem; color: var(--gray-500); font-weight: 500; margin-top: 2px; }
.meal-counter.green { background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); border-color: #bbf7d0; }
.meal-counter.green .meal-counter-value { color: var(--success); }
.meal-counter.yellow { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); border-color: #fde68a; }
.meal-counter.yellow .meal-counter-value { color: var(--warning); }
.meal-counter.red { background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); border-color: #fecaca; }
.meal-counter.red .meal-counter-value { color: var(--danger); }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--gray-100); }
th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    font-weight: 700;
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}
tbody tr { cursor: pointer; transition: background 0.15s ease; }
tbody tr:hover { background: rgba(37, 99, 235, 0.03); }
tbody tr:nth-child(even) { background: var(--gray-50); }
tbody tr:nth-child(even):hover { background: rgba(37, 99, 235, 0.05); }

/* ===== Alert ===== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-weight: 500;
    font-size: 0.9rem;
}
.alert-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: white;
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0,0,0,0.05);
    animation: slideUp 0.25s ease;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

/* ===== Lists ===== */
.log-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
    transition: background 0.15s ease;
}

.log-item:last-child { border-bottom: none; }
.log-time { color: var(--gray-500); font-size: 0.8rem; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 0.73rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-use { background: #dbeafe; color: var(--primary); }
.badge-add { background: #d1fae5; color: var(--success); }
.badge-remove { background: #fee2e2; color: var(--danger); }

/* ===== Login ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 50%, #e0e7ff 100%);
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(37, 99, 235, 0.12), 0 0 0 1px rgba(37, 99, 235, 0.06);
    text-align: center;
    animation: slideUp 0.4s ease;
}

.login-card h1 {
    font-size: 1.6rem;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
    font-weight: 800;
    color: var(--gray-900);
}
.login-card p { color: var(--gray-500); margin-bottom: 28px; font-size: 0.95rem; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    min-width: 280px;
    max-width: 420px;
    text-align: center;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .container { padding: 14px 12px; }
    .card { padding: 16px; }
    .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .meal-counter-value { font-size: 2.2rem; }
    .btn-use-meal { padding: 18px; font-size: 1.1rem; }
    .login-card { padding: 32px 24px; }
    .modal { padding: 20px; }
    .nav-tab { padding: 12px 16px; }
}

/* ===== Stats ===== */
.stats-period-toggle {
    display: inline-flex;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--gray-200);
}

.stats-period-btn {
    padding: 8px 18px;
    border: none;
    background: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--gray-500);
    transition: all 0.2s ease;
}

.stats-period-btn:not(:last-child) {
    border-right: 1px solid var(--gray-200);
}

.stats-period-btn:hover { background: var(--gray-50); color: var(--gray-700); }
.stats-period-btn.active {
    background: var(--primary);
    color: white;
}

.stats-label {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--gray-700);
}

.split-bar {
    display: flex;
    height: 28px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--gray-100);
}

.split-bar-stat {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    transition: width 0.4s ease;
}

.split-bar-del {
    background: linear-gradient(135deg, var(--warning) 0%, #d97706 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    transition: width 0.4s ease;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.bar-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-600);
    min-width: 70px;
    flex-shrink: 0;
}

.bar-track {
    flex: 1;
    height: 22px;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--success) 0%, #15803d 100%);
    border-radius: 6px;
    transition: width 0.4s ease;
    min-width: 2px;
}

.bar-fill-accent {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
}

.bar-value {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--gray-700);
    min-width: 30px;
    text-align: right;
}

/* ===== Utility ===== */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--gray-500); }
.w-full { width: 100%; }
.hidden { display: none; }
