/* ============================================================
   NutriControl - Stylesheet
   ============================================================ */

/* Variables */
:root {
    --green:       #4CAF50;
    --green-light: #81C784;
    --green-dark:  #388E3C;
    --orange:      #FF9800;
    --orange-light:#FFB74D;
    --blue:        #2196F3;
    --blue-light:  #64B5F6;
    --red:         #F44336;
    --purple:      #9C27B0;
    --yellow:      #FFC107;

    --bg:          #F0F7F0;
    --card-bg:     #FFFFFF;
    --sidebar-bg:  #1B5E20;
    --sidebar-text:#C8E6C9;
    --sidebar-active:#4CAF50;
    --text-main:   #212121;
    --text-muted:  #757575;
    --border:      #E0E0E0;
    --shadow:      0 2px 12px rgba(0,0,0,.08);
    --shadow-hover:0 6px 20px rgba(0,0,0,.13);
    --radius:      12px;
    --radius-sm:   8px;
    --transition:  .2s ease;

    --sidebar-width: 240px;
    --topbar-height: 64px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text-main); min-height: 100vh; }
a { text-decoration: none; color: inherit; }
img { max-width: 100%; }
ul { list-style: none; }

/* ============================================================
   Layout
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    z-index: 200;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 24px 20px 20px;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand i { color: var(--green-light); font-size: 1.5rem; }

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255,255,255,.35);
    padding: 16px 8px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: .92rem;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
}
.nav-item i { width: 20px; text-align: center; font-size: 1rem; }
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item--danger { color: #EF9A9A; }
.nav-item--danger:hover { background: rgba(244,67,54,.15); color: var(--red); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
}
.sidebar-user__avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--green);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .95rem;
    flex-shrink: 0;
}
.sidebar-user__info { overflow: hidden; }
.sidebar-user__name {
    display: block;
    color: #fff;
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user__role { display: block; color: rgba(255,255,255,.5); font-size: .75rem; }

/* Main wrapper */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top bar */
.top-bar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.menu-toggle {
    display: none;
    background: none; border: none; cursor: pointer;
    font-size: 1.2rem; color: var(--text-main);
    padding: 8px;
}
.page-title { font-size: 1.15rem; font-weight: 700; flex: 1; }
.top-bar__date { color: var(--text-muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }

/* Main content */
.main-content { padding: 24px; flex: 1; }

/* Overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 199;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.card--compact { padding: 16px; }
.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.card__title { font-size: 1rem; font-weight: 700; }
.card__subtitle { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }

/* Stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-hover); }
.stat-card__icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
}
.stat-card__icon--green  { background: #E8F5E9; color: var(--green); }
.stat-card__icon--orange { background: #FFF3E0; color: var(--orange); }
.stat-card__icon--blue   { background: #E3F2FD; color: var(--blue); }
.stat-card__icon--purple { background: #F3E5F5; color: var(--purple); }
.stat-card__icon--red    { background: #FFEBEE; color: var(--red); }

.stat-card__value { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.stat-card__label { font-size: .8rem; color: var(--text-muted); }
.stat-card__progress { margin-top: 4px; }

/* Progress bar */
.progress-bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-bar__fill { height: 100%; border-radius: 99px; transition: width .4s ease; }
.progress-bar__fill--green  { background: var(--green); }
.progress-bar__fill--orange { background: var(--orange); }
.progress-bar__fill--blue   { background: var(--blue); }
.progress-bar__fill--purple { background: var(--purple); }
.progress-bar__fill--red    { background: var(--red); }

/* ============================================================
   Grid helpers
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-main);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: #fff;
    color: var(--text-main);
}
.form-control:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: filter var(--transition), transform var(--transition);
}
.btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--primary   { background: var(--green); color: #fff; }
.btn--secondary { background: var(--orange); color: #fff; }
.btn--blue      { background: var(--blue); color: #fff; }
.btn--danger    { background: var(--red); color: #fff; }
.btn--ghost     { background: transparent; color: var(--green); border: 1.5px solid var(--green); }
.btn--sm        { padding: 6px 14px; font-size: .82rem; }
.btn--full      { width: 100%; justify-content: center; }

/* ============================================================
   Tables
   ============================================================ */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: #F5F5F5;
    padding: 10px 14px;
    text-align: left;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .9rem; }
tbody tr:hover td { background: #FAFAFA; }
tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: .72rem;
    font-weight: 700;
}
.badge--green  { background: #E8F5E9; color: var(--green-dark); }
.badge--orange { background: #FFF3E0; color: #E65100; }
.badge--blue   { background: #E3F2FD; color: #1565C0; }
.badge--red    { background: #FFEBEE; color: #C62828; }
.badge--purple { background: #F3E5F5; color: #6A1B9A; }

/* ============================================================
   Alerts / Toasts
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert--success { background: #E8F5E9; color: var(--green-dark); border-left: 4px solid var(--green); }
.alert--error   { background: #FFEBEE; color: #C62828; border-left: 4px solid var(--red); }
.alert--info    { background: #E3F2FD; color: #1565C0; border-left: 4px solid var(--blue); }
.alert--warning { background: #FFF8E1; color: #F57F17; border-left: 4px solid var(--yellow); }

/* ============================================================
   Login page
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1B5E20 0%, #4CAF50 60%, #A5D6A7 100%);
    padding: 24px;
}
.login-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.login-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-logo i { font-size: 2.5rem; color: var(--green); }
.login-logo h1 { font-size: 1.6rem; font-weight: 800; margin-top: 8px; }
.login-logo p { color: var(--text-muted); font-size: .88rem; margin-top: 4px; }
.login-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.demo-credentials { background: #F1F8E9; border-radius: var(--radius-sm); padding: 12px 16px; font-size: .8rem; }
.demo-credentials strong { color: var(--green-dark); }
.demo-credentials p { margin-bottom: 4px; }

/* ============================================================
   Meal type pills
   ============================================================ */
.meal-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.meal-pill {
    padding: 6px 14px;
    border-radius: 99px;
    border: 1.5px solid var(--border);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    background: #fff;
    color: var(--text-muted);
}
.meal-pill:hover { border-color: var(--green); color: var(--green); }
.meal-pill.selected { background: var(--green); color: #fff; border-color: var(--green); }

/* ============================================================
   Food log list
   ============================================================ */
.meal-section { margin-bottom: 24px; }
.meal-section__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}
.meal-section__icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: .9rem;
}
.meal-section__title { font-weight: 700; font-size: .95rem; }
.meal-section__kcal  { margin-left: auto; font-size: .82rem; color: var(--text-muted); }

.food-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.food-item:hover { background: #F5F5F5; }
.food-item__icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    background: #E8F5E9;
    display: flex; align-items: center; justify-content: center;
    color: var(--green);
    font-size: .9rem;
    flex-shrink: 0;
}
.food-item__info { flex: 1; min-width: 0; }
.food-item__name { font-size: .9rem; font-weight: 600; }
.food-item__meta { font-size: .77rem; color: var(--text-muted); }
.food-item__kcal { font-size: .9rem; font-weight: 700; color: var(--orange); }
.food-item__delete { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; border-radius: 4px; }
.food-item__delete:hover { color: var(--red); background: #FFEBEE; }

/* ============================================================
   Nutrient macros row
   ============================================================ */
.macros-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}
.macro-card {
    text-align: center;
    padding: 16px 8px;
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow);
}
.macro-card__value { font-size: 1.4rem; font-weight: 800; }
.macro-card__label { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.macro-card__bar { margin-top: 8px; }

/* ============================================================
   Patient card
   ============================================================ */
.patients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.patient-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.patient-card:hover { box-shadow: var(--shadow-hover); }
.patient-card__avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--green), var(--blue));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; font-weight: 700;
}
.patient-card__name { font-weight: 700; font-size: 1rem; }
.patient-card__email { font-size: .8rem; color: var(--text-muted); }
.patient-card__actions { display: flex; gap: 8px; margin-top: 4px; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 28px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    max-height: 90vh;
    overflow-y: auto;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.modal__title { font-size: 1.1rem; font-weight: 700; }
.modal__close {
    background: none; border: none; cursor: pointer;
    font-size: 1.2rem; color: var(--text-muted);
    padding: 4px;
}
.modal__close:hover { color: var(--red); }

/* Search */
.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #F5F5F5;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 12px;
}
.search-box i { color: var(--text-muted); }
.search-box input { border: none; background: transparent; flex: 1; font-size: .95rem; outline: none; }

/* Food search results */
.food-results { max-height: 280px; overflow-y: auto; }
.food-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}
.food-result-item:hover { background: #F1F8E9; }
.food-result-item__name { font-size: .9rem; font-weight: 600; }
.food-result-item__kcal { font-size: .8rem; color: var(--text-muted); }
.food-result-item__badge { font-size: .72rem; }

/* Chart container */
.chart-container { position: relative; height: 240px; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open {
        display: block;
    }
    .main-wrapper {
        margin-left: 0;
    }
    .menu-toggle { display: flex; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .macros-row { grid-template-columns: repeat(2, 1fr); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .main-content { padding: 16px; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .macros-row { grid-template-columns: repeat(2, 1fr); }
    .login-card { padding: 28px 20px; }
}

/* ============================================================
   Utilities
   ============================================================ */
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex  { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .85rem; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: .9rem; }
