/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    /* Color Palette */
    --bg-dark: #0b0b16;
    --bg-dark-secondary: #121226;
    --card-bg: rgba(22, 22, 45, 0.6);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-hover-border: rgba(0, 242, 254, 0.3);
    
    /* Neon Accent Colors */
    --accent-cyan: #00f2fe;
    --accent-blue: #4facfe;
    --accent-magenta: #f857a6;
    --accent-orange: #ff5858;
    --accent-green: #00ff87;
    --accent-yellow: #f8d347;
    
    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a0a0c0;
    --text-muted: #6b6b8b;
    
    /* Gradients */
    --grad-primary: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-blue) 100%);
    --grad-danger: linear-gradient(135deg, var(--accent-magenta) 0%, var(--accent-orange) 100%);
    --grad-success: linear-gradient(135deg, #00f260 0%, #0575e6 100%);
    --grad-warning: linear-gradient(135deg, var(--accent-yellow) 0%, #ff8c00 100%);
    --grad-card-glow: radial-gradient(circle at 50% 0%, rgba(0, 242, 254, 0.1) 0%, transparent 70%);

    /* Fonts & Transitions */
    --font-main: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --shadow-cyan-glow: 0 0 15px rgba(0, 242, 254, 0.3);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent !important;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 10% 20%, rgba(79, 172, 254, 0.05) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(248, 87, 166, 0.05) 0px, transparent 50%),
        radial-gradient(at 50% 50%, rgba(18, 18, 38, 1) 0px, var(--bg-dark) 100%);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ลบกรอบโฟกัสของเบราว์เซอร์สำหรับองค์ประกอบที่สามารถคลิกได้ทั้งหมด */
a:focus, 
button:focus, 
select:focus, 
input:focus,
textarea:focus,
[role="button"]:focus, 
.nav-item:focus,
.quick-chip:focus {
    outline: none !important;
}

/* ป้องกันการไฮไลท์และเคอร์เซอร์พิมพ์อักษรบนข้อความแสดงผลทั้งหมด */
body, 
div, 
span, 
p, 
h1, 
h2, 
h3, 
h4, 
h5, 
h6, 
label, 
.nav-item, 
.quick-chip {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    cursor: default;
}

/* ปุ่มกดและลิงก์ต่างๆ ให้แสดงเคอร์เซอร์รูปมือ และไม่สามารถคลุมตัวอักษรได้ */
a, 
button, 
select, 
.btn, 
.quick-chip:hover,
.btn-close-modal {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    cursor: pointer !important;
}

/* ช่องกรอกข้อมูล (Inputs/Textareas) ให้สามารถคลิกเลือกและพิมพ์ได้ตามปกติ */
input, 
textarea {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    cursor: text !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar Navigation */
.sidebar {
    width: 260px;
    background: rgba(14, 14, 30, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition-normal);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--grad-primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-cyan-glow);
}

.brand-icon i {
    font-size: 1.25rem;
    color: var(--bg-dark);
}

.brand-name {
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.5px;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex-grow: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.nav-item a i {
    font-size: 1.2rem;
}

.nav-item a:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active a {
    color: var(--bg-dark);
    background: var(--grad-primary);
    font-weight: 600;
    box-shadow: var(--shadow-cyan-glow);
}

.nav-item.active a i {
    color: var(--bg-dark);
}

.sidebar-footer {
    border-top: 1px solid var(--card-border);
    padding-top: 1.5rem;
    margin-top: auto;
}

.user-quick-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--accent-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-cyan);
    font-weight: 600;
}

.user-info-text {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-weight-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    margin-left: 260px;
    padding: 2.5rem;
    min-height: 100vh;
    transition: var(--transition-normal);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.page-title p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.date-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ==========================================================================
   UI COMPONENTS & PATTERNS
   ========================================================================== */

/* Glassmorphic Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 1.75rem;
    box-shadow: var(--shadow-premium);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--grad-card-glow);
    pointer-events: none;
    opacity: 0.5;
}

.card:hover {
    border-color: var(--card-hover-border);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title i {
    color: var(--accent-cyan);
}

/* Buttons */
.btn {
    font-family: var(--font-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-primary {
    background: var(--grad-primary);
    color: var(--bg-dark);
    box-shadow: var(--shadow-cyan-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(0, 242, 254, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: var(--grad-danger);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(248, 87, 166, 0.4);
}

.btn-icon-only {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    padding: 0;
}

/* Inputs & Forms */
.form-group {
    margin-bottom: 1.25rem;
}

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

.form-control {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    color: white;
    font-family: var(--font-main);
    font-size: 0.95rem;
    transition: var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: var(--shadow-cyan-glow);
}

.form-control:disabled {
    background: rgba(255, 255, 255, 0.02) !important;
    border-color: rgba(255, 255, 255, 0.05) !important;
    color: rgba(255, 255, 255, 0.35) !important;
    cursor: not-allowed !important;
    opacity: 0.6;
    box-shadow: none !important;
}

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

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a0a0c0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2em;
    padding-right: 2.5rem;
}

select.form-control option {
    background: var(--bg-dark-secondary);
    color: white;
}

/* Tabs & Sections Navigation */
.app-section {
    display: none;
    animation: slideUp 0.5s ease forwards;
}

.app-section.active {
    display: block;
}

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

/* ==========================================================================
   DASHBOARD SPECIFIC
   ========================================================================== */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.main-dashboard-column {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Calorie Circle Card */
.calorie-circle-container {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 1rem 0;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.progress-ring-wrapper {
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-ring {
    transform: rotate(-90deg);
}

.progress-ring-circle-bg {
    fill: transparent;
    stroke: rgba(255, 255, 255, 0.04);
}

.progress-ring-circle {
    fill: transparent;
    stroke: url(#cyanGrad);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.6s ease;
}

.progress-ring-text {
    position: absolute;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.progress-number {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1.1;
}

.progress-unit {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 0.25rem;
}

.progress-status {
    font-size: 0.85rem;
    color: var(--accent-green);
    margin-top: 0.25rem;
    font-weight: 500;
}

.calorie-stats-box {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 180px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.stat-icon.intake {
    background: rgba(79, 172, 254, 0.15);
    color: var(--accent-cyan);
}

.stat-icon.burn {
    background: rgba(248, 87, 166, 0.15);
    color: var(--accent-magenta);
}

.stat-icon.target {
    background: rgba(248, 211, 71, 0.15);
    color: var(--accent-yellow);
}

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

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.stat-card-icon {
    width: 50px;
    height: 50px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-card-icon.weight {
    background: rgba(0, 255, 135, 0.15);
    color: var(--accent-green);
}

.stat-card-icon.deficit {
    background: rgba(0, 242, 254, 0.15);
    color: var(--accent-cyan);
}

.stat-card-icon.active {
    background: rgba(255, 88, 88, 0.15);
    color: var(--accent-orange);
}

.stat-card-info {
    display: flex;
    flex-direction: column;
}

.stat-card-number {
    font-size: 1.4rem;
    font-weight: 700;
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Mission Summary Card */
.mission-progress-box {
    margin-top: 0.5rem;
}

.progress-bar-container {
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    margin: 0.75rem 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--grad-primary);
    border-radius: 6px;
    width: 0%;
    transition: width 0.8s ease;
    box-shadow: 0 0 8px rgba(0, 242, 254, 0.5);
}

.mission-goals-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Nutrition breakdown */
.nutrition-bars {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nutri-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nutri-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

.nutri-label {
    font-weight: 500;
}

.nutri-val {
    color: var(--text-secondary);
}

.nutri-bar-bg {
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.nutri-bar-fill {
    height: 100%;
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
}

.nutri-bar-fill.carb { background: var(--accent-blue); }
.nutri-bar-fill.protein { background: var(--accent-green); }
.nutri-bar-fill.fat { background: var(--accent-magenta); }

/* Quick Action Panel */
.quick-action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ==========================================================================
   DIARY (FOOD & EXERCISE) SPECIFIC
   ========================================================================== */
.diary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.diary-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.75rem;
}

.diary-section-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
}

.meal-block {
    margin-bottom: 1.5rem;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 15px;
    padding: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

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

.meal-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent-cyan);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.meal-calories {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    padding: 0.6rem 0.85rem;
    transition: var(--transition-fast);
}

.log-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.05);
}

.item-info {
    display: flex;
    flex-direction: column;
}

.item-name {
    font-size: 0.9rem;
    font-weight: 500;
}

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

.item-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.item-calories {
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-delete-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0.25rem;
    border-radius: 6px;
    transition: var(--transition-fast);
}

.btn-delete-item:hover {
    color: var(--accent-magenta);
    background: rgba(248, 87, 166, 0.15);
}

/* Quick Add Panel styles */
.quick-add-section {
    margin-top: 1rem;
}

.quick-add-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.quick-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.quick-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.quick-chip:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--accent-cyan);
}

/* Empty State */
.empty-state {
    padding: 1.5rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* ==========================================================================
   MISSION CONFIGURATION SPECIFIC
   ========================================================================== */
.mission-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.calculation-preview-card {
    background: radial-gradient(circle at 100% 0%, rgba(0, 242, 254, 0.15) 0%, transparent 60%), var(--card-bg);
}

.calc-box {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.calc-row:last-child {
    border-bottom: none;
}

.calc-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.calc-value {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--accent-cyan);
}

.calc-val-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: normal;
}

.mission-impact-box {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(0, 255, 135, 0.05);
    border-left: 4px solid var(--accent-green);
    border-radius: 0 12px 12px 0;
}

.mission-impact-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--accent-green);
    margin-bottom: 0.25rem;
}

.mission-impact-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ==========================================================================
   HISTORY & PROGRESS SPECIFIC
   ========================================================================== */
.history-grid {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chart-wrapper {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1rem;
    position: relative;
    height: 300px;
    width: 100%;
}

canvas#progressChart {
    width: 100%;
    height: 100%;
}

.history-list-box {
    max-height: 400px;
    overflow-y: auto;
}

.history-day-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    transition: var(--transition-fast);
}

.history-day-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

.day-info {
    display: flex;
    flex-direction: column;
}

.day-date {
    font-weight: 600;
    font-size: 0.95rem;
}

.day-weight-val {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.day-stats {
    display: flex;
    gap: 1.5rem;
}

.day-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.day-stat-val {
    font-size: 0.95rem;
    font-weight: 600;
}

.day-stat-val.deficit-plus {
    color: var(--accent-green);
}

.day-stat-val.deficit-minus {
    color: var(--accent-magenta);
}

.day-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ==========================================================================
   ACHIEVEMENTS SPECIFIC
   ========================================================================== */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}

.achievement-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
    transition: var(--transition-normal);
    opacity: 0.5;
    filter: grayscale(80%);
}

.achievement-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 30%, rgba(248, 211, 71, 0.15) 0%, transparent 60%);
    opacity: 0;
    transition: var(--transition-normal);
}

.achievement-card.unlocked {
    opacity: 1;
    filter: grayscale(0%);
    border-color: rgba(248, 211, 71, 0.3);
    box-shadow: 0 10px 25px -10px rgba(248, 211, 71, 0.2);
}

.achievement-card.unlocked::before {
    opacity: 1;
}

.achievement-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin-bottom: 1.25rem;
    color: var(--text-muted);
    transition: var(--transition-normal);
    position: relative;
    z-index: 2;
}

.achievement-card.unlocked .achievement-icon {
    background: linear-gradient(135deg, #fce38a 0%, #f38181 100%);
    color: var(--bg-dark);
    box-shadow: 0 0 15px rgba(243, 129, 129, 0.4);
    border: none;
}

.achievement-info {
    position: relative;
    z-index: 2;
}

.achievement-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.achievement-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.achievement-date {
    font-size: 0.7rem;
    color: var(--accent-yellow);
    margin-top: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   MODAL WINDOWS
   ========================================================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 10, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-container {
    background: var(--bg-dark-secondary);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    width: 100%;
    max-width: 480px;
    padding: 2rem;
    position: relative;
    z-index: 1001;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.8);
    animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

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

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
}

.btn-close-modal {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: var(--transition-fast);
}

.btn-close-modal:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

/* ==========================================================================
   AUTH LAYOUT SPECIFIC
   ========================================================================== */
.auth-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1.5rem;
}

.auth-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 10% 20%, rgba(79, 172, 254, 0.08) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(248, 87, 166, 0.08) 0px, transparent 50%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem !important;
    background: rgba(22, 22, 45, 0.75) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8) !important;
    position: relative;
    z-index: 2001;
    animation: authFadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

/* ==========================================================================
   RESPONSIVE DESIGN (MEDIA QUERIES)
   ========================================================================== */

/* Tablet (1024px) */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    
    .diary-grid {
        grid-template-columns: 1fr;
    }
    
    .mission-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile Devices (768px & below) */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 65px;
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        flex-direction: row;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--card-border);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
        border-radius: 16px 16px 0 0;
        overflow: hidden;
    }
    
    .brand, .sidebar-footer {
        display: none; /* Hide brand & user profile on bottom bar */
    }
    
    .nav-links {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        padding: 0 0.5rem;
        gap: 0;
    }
    
    .nav-item {
        flex: 1;
        text-align: center;
    }
    
    .nav-item a {
        flex-direction: column;
        gap: 0.2rem;
        padding: 0.5rem 0;
        border-radius: 0;
        font-size: 0.65rem;
        align-items: center;
        justify-content: center;
        height: 100%;
    }
    
    .nav-item a i {
        font-size: 1.25rem;
    }
    
    .nav-item.active a {
        background: transparent;
        color: var(--accent-cyan);
        box-shadow: none;
        font-weight: 500;
    }
    
    .nav-item.active a i {
        color: var(--accent-cyan);
    }
    
    .nav-item.active a::after {
        content: '';
        position: absolute;
        bottom: 2px;
        width: 20px;
        height: 3px;
        background: var(--accent-cyan);
        border-radius: 2px;
        box-shadow: var(--shadow-cyan-glow);
    }
    
    .main-content {
        margin-left: 0;
        padding: 1.5rem 1rem 5.5rem 1rem; /* Extra padding bottom for bottom nav */
    }
    
    .app-header {
        margin-bottom: 1.5rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .calorie-circle-container {
        flex-direction: column;
        align-items: center;
    }
    
    .progress-ring-wrapper {
        width: 170px;
        height: 170px;
    }
    
    .progress-number {
        font-size: 1.8rem;
    }
    
    .calorie-stats-box {
        width: 100%;
    }
    
    .quick-action-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   MOBILE & iOS OPTIMIZATIONS
   ========================================================================== */

/* ลบแสงสีเทาเมื่อสัมผัสปุ่มหรือลิงก์บน iOS */
* {
    -webkit-tap-highlight-color: transparent;
}

/* รองรับ Safe Area และพฤติกรรมการเลื่อนบน iOS */
html, body {
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    /* ปรับแต่งความสูงของเมนูด้านล่าง (Sidebar) ให้รองรับ iOS Home Indicator */
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom) !important;
        height: calc(65px + env(safe-area-inset-bottom)) !important;
    }
    
    /* ปรับความห่างขอบล่างของหน้าหลักเพื่อไม่ให้โดนเมนูด้านล่างทับ */
    .main-content {
        padding: 1.5rem 1rem calc(5.5rem + env(safe-area-inset-bottom)) 1rem !important;
    }
    
    /* บังคับช่องอินพุตให้ใช้ขนาดฟอนต์ 16px เสมอ เพื่อแก้ปัญหา iOS Auto-Zoom */
    .form-control, 
    select.form-control, 
    input[type="text"], 
    input[type="number"], 
    input[type="date"], 
    input[type="email"], 
    input[type="password"], 
    textarea {
        font-size: 16px !important;
    }
    
    /* ปรับปรุงประสิทธิภาพของ Modal บนหน้าจอมือถือเตี้ย */
    .modal {
        padding: 0.5rem;
    }
    .modal-container {
        padding: 1.5rem;
        max-height: calc(100vh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* เพิ่มปฏิกิริยาการชี้ให้เห็นว่าการ์ดน้ำหนักกดได้ */
    .stat-card.weight-card-interactive {
        cursor: pointer;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .stat-card.weight-card-interactive:active {
        transform: scale(0.97);
    }
}

