/* ===== FoodLog Mobile-First Stylesheet ===== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a1a;
    line-height: 1.5;
}

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

/* ===== Header ===== */
header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 {
    font-size: 2em;
    margin-bottom: 4px;
    color: #1a1a1a;
}

.subtitle {
    color: #495057;
    font-size: 0.95em;
    font-weight: 500;
}

.back-link {
    display: inline-block;
    margin-top: 8px;
    color: #0066cc;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 550;
}

.logout-link {
    position: absolute !important;
    top: 16px !important;
    right: 16px !important;
    color: #0066cc !important;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 550;
}

/* ===== Totals ===== */
.totals {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.totals h2 {
    font-size: 1.2em;
    margin-bottom: 12px;
    color: #1a1a1a;
}

.totals-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.total-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #e9ecef;
    border-radius: 8px;
    padding: 10px 6px;
}

.total-label {
    font-size: 0.8em;
    color: #495057;
    margin-bottom: 4px;
    font-weight: 600;
}

.total-value {
    font-size: 1.15em;
    font-weight: 700;
    color: #1a1a1a;
}

/* ===== Form ===== */
.form-section {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.form-section h2 {
    font-size: 1.2em;
    margin-bottom: 16px;
    color: #1a1a1a;
}

.food-form .form-group {
    margin-bottom: 16px;
}

.food-form label {
    display: block;
    font-size: 0.9em;
    color: #495057;
    margin-bottom: 6px;
    font-weight: 600;
}

.food-form input,
.food-form select {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.05em;
    border: 2px solid #ced4da;
    border-radius: 10px;
    background: #ffffff;
    color: #212529;
}

.food-form input:focus,
.food-form select:focus {
    outline: none;
    border-color: #0066cc;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-row .form-group.half {
    flex: 1;
}

/* ===== Buttons ===== */
.btn-primary {
    width: 100%;
    padding: 16px;
    font-size: 1.15em;
    font-weight: 700;
    color: #fff;
    background: #28a745;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, transform 0.05s;
    margin-top: 4px;
}

.btn-primary:hover {
    background: #218838;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    padding: 12px 20px;
    font-size: 0.95em;
    font-weight: 600;
    color: #0066cc;
    background: #e7f1ff;
    border: 2px solid #0066cc;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #d2e3ff;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    font-size: 0.95em;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

.btn-barcode {
    background: #6f42c1;
    color: #fff;
}

.btn-barcode:hover {
    background: #5a32a3;
}

.btn-dashboard {
    background: #fd7e14;
    color: #fff;
}

.btn-dashboard:hover {
    background: #e06a0d;
}

.btn-quick {
    width: 100%;
    padding: 12px;
    font-size: 0.9em;
    font-weight: 600;
    color: #0066cc;
    background: #fff;
    border: 2px solid #0066cc;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-quick:hover {
    background: #e7f1ff;
}

/* ===== Macro Preview ===== */
.preview {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.preview h3 {
    font-size: 1.05em;
    margin-bottom: 10px;
    color: #1a1a1a;
}

.macro-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.macro-preview span {
    background: #e9ecef;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85em;
    font-weight: 600;
    color: #212529;
}

.macro-cal {
    background: #0066cc;
    color: #fff;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 8px;
}

.macro-error {
    color: #dc3545;
    font-weight: 600;
}

/* ===== Entries ===== */
.entries {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.entries h2 {
    font-size: 1.2em;
    margin-bottom: 12px;
    color: #1a1a1a;
}

.entry-card {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
    border-left: 4px solid #0066cc;
}

.entry-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 0.9em;
}

.entry-meal {
    font-weight: 700;
    color: #0066cc;
    font-size: 1em;
}

.entry-time {
    color: #495057;
    font-weight: 600;
}

.entry-what {
    font-size: 1em;
    color: #212529;
    font-weight: 500;
}

.entry-detail {
    font-size: 0.85em;
    color: #6c757d;
    margin-top: 4px;
}

.empty {
    text-align: center;
    color: #6c757d;
    padding: 20px;
    font-style: italic;
    font-weight: 500;
}

/* ===== Quick Meal ===== */
.quick-meal {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.quick-meal p {
    font-size: 0.9em;
    color: #495057;
    margin-bottom: 10px;
    font-weight: 500;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.barcode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

/* ===== Footer ===== */
footer {
    text-align: center;
    color: #6c757d;
    font-size: 0.8em;
    padding: 16px;
    font-weight: 500;
}

/* ===== Dashboard ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 18px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.stat-value {
    font-size: 1.8em;
    font-weight: 700;
    color: #1a1a1a;
}

.stat-label {
    font-size: 0.85em;
    color: #495057;
    margin-top: 4px;
    font-weight: 600;
}

.weight-form {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.weight-form h2 {
    font-size: 1.2em;
    margin-bottom: 12px;
    color: #1a1a1a;
}

.weight-form .form-row {
    gap: 8px;
}

.weight-form input {
    padding: 14px 16px;
    font-size: 1.05em;
    text-align: center;
    border: 2px solid #ced4da;
    border-radius: 10px;
    background: #ffffff;
    color: #212529;
}

.weight-form input:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.chart-container {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
}

.chart-container h3 {
    font-size: 1.1em;
    margin-bottom: 12px;
    color: #1a1a1a;
    text-align: center;
}

/* ===== Chart ===== */
.simple-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 160px;
    padding-top: 8px;
    border-bottom: 2px solid #dee2e6;
    overflow: hidden;
}

.bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    min-width: 20px;
    height: 100%;
}

.bar-fill {
    width: 100%;
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    max-height: 100%;
    transition: height 0.3s ease;
}

.bar-cal { background: linear-gradient(to top, #0066cc, #66b2ff); }
.bar-protein { background: linear-gradient(to top, #28a745, #66c266); }
.bar-weight { background: linear-gradient(to top, #fd7e14, #ffb366); }

.bar-label {
    font-size: 0.6em;
    color: #6c757d;
    margin-top: 4px;
    transform: rotate(-45deg) origin top left;
    white-space: nowrap;
    font-weight: 600;
}

/* ===== History List ===== */
.history-list {
    list-style: none;
}

.history-item {
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-item:last-child {
    border-bottom: none;
}

.history-what {
    font-size: 0.95em;
    color: #212529;
    font-weight: 500;
}

.history-time {
    font-size: 0.8em;
    color: #6c757d;
    background: #e9ecef;
    padding: 2px 8px;
    border-radius: 12px;
}

/* ===== Scanner Overlay ===== */
.scanner-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

#barcodeScanner {
    width: 100%;
    height: 300px;
    border: 2px dashed #0066cc;
    border-radius: 12px;
    background: #000;
    display: none;
}

.scanner-result {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
}

.scanner-result.found {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.scanner-result.not-found {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .totals-grid {
        grid-template-columns: 2fr 1fr;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .quick-grid {
        grid-template-columns: 1fr;
    }

    .barcode-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Food Row (structured form) ===== */
.food-row {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}

.food-row:last-child {
    margin-bottom: 0;
}

.food-select,
.unit-select,
.amount-input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.05em;
    border: 2px solid #ced4da;
    border-radius: 10px;
    background: #ffffff;
    color: #212529;
    font-family: inherit;
}

.food-select:focus,
.unit-select:focus,
.amount-input:focus {
    outline: none;
    border-color: #0066cc;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.15);
}

.food-select {
    flex: 2;
}

.btn-barcode-scan {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    font-size: 1.3em;
    border: 2px solid #6f42c1;
    border-radius: 10px;
    background: #fff;
    color: #6f42c1;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-barcode-scan:hover {
    background: #e7e0f3;
}

.scanner-result {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    margin-top: 8px;
}

.scanner-result.found {
    background: #d4edda;
    color: #155724;
}

.scanner-result.not-found {
    background: #f8d7da;
    color: #721c24;
}

.hint {
    display: block;
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 4px;
}

/* ===== Dark mode overrides for new elements ===== */
@media (prefers-color-scheme: dark) {
    .food-row {
        background: #2a2a2a;
        border-color: #333;
    }

    .food-select,
    .unit-select,
    .amount-input {
        background: #2d2d2d;
        border-color: #444;
        color: #e9ecef;
    }

    .food-select:focus,
    .unit-select:focus,
    .amount-input:focus {
        background: #2d2d2d;
        border-color: #0066cc;
    }

    .btn-barcode-scan {
        background: #2d2d2d;
        border-color: #6f42c1;
        color: #d1b3f0;
    }

    .btn-barcode-scan:hover {
        background: #3a3a3a;
    }
}
@media (prefers-color-scheme: dark) {
    body {
        background: #121212;
        color: #e9ecef;
    }

    .totals, .form-section, .entries, .quick-meal, .stat-card,
    .chart-container, .weight-form {
        background: #1e1e1e;
        color: #e9ecef;
    }

    .total-item, .entry-card {
        background: #2d2d2d;
    }

    .macro-preview span, .btn-quick, .bar-label {
        background: #2d2d2d;
        color: #e9ecef;
    }

    .macro-preview span {
        color: #e9ecef;
    }

    .form-section input, .form-section select {
        background: #2d2d2d;
        border-color: #444;
        color: #e9ecef;
    }

    .btn-quick {
        border-color: #0066cc;
        color: #66b2ff;
    }

    .btn-quick:hover {
        background: #0d2847;
    }

    .bar-label {
        color: #a9a9a9;
    }

    /* Gray text that was invisible in dark mode — make it visible */
    .subtitle, .total-label, .entry-time, .entry-detail, .empty, .footer,
    .history-what, .bar-label, .hint {
        color: #b8b8b8;
    }

    /* Backgrounds that were light-colored on dark page */
    .total-item {
        background: #2d2d2d;
    }

    .entry-card {
        background: #2d2d2d;
    }

    /* Keep macro-cal blue button visible in dark mode */
    .macro-cal {
        background: #0066cc;
        color: #fff;
    }

    /* Darken muted backgrounds */
    .macro-preview span {
        background: #2d2d2d;
    }

    .history-time {
        background: #2d2d2d;
        color: #b8b8b8;
    }

    .history-item {
        border-bottom-color: #333;
    }
}
