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

:root {
    --primary: #4CAF50;
    --primary-dark: #388E3C;
    --secondary: #607D8B;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #212121;
    --text-light: #757575;
    --protein: #FF7043;
    --fat: #FFA726;
    --carbs: #42A5F5;
    --shadow: 0 2px 12px rgba(0,0,0,0.1);
    --radius: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 32px;
}

header {
    text-align: center;
    padding: 24px 0 16px;
}

header h1 {
    font-size: 28px;
    font-weight: 700;
}

.subtitle {
    color: var(--text-light);
    font-size: 14px;
    margin-top: 4px;
}

.section {
    margin-bottom: 16px;
}

/* Home screen */
.home-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 40px 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.home-emoji {
    font-size: 64px;
    margin-bottom: 12px;
}

.home-text {
    color: var(--text-light);
    font-size: 16px;
    margin-bottom: 24px;
}

.home-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.home-buttons .btn {
    justify-content: center;
}

/* Camera */
#camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    box-shadow: var(--shadow);
}

#camera {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Preview */
#preview-container {
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    box-shadow: var(--shadow);
}

#preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Controls */
.controls {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

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

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border: 2px solid #e0e0e0;
}

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

.btn-icon {
    font-size: 18px;
}

/* Loader */
.loader {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #e0e0e0;
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader p {
    color: var(--text-light);
    font-size: 16px;
}

/* Result card */
.result-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.result-header h2 {
    font-size: 20px;
    flex: 1;
    margin-right: 12px;
}

.total-calories {
    text-align: right;
    flex-shrink: 0;
}

.kcal-number {
    font-size: 36px;
    font-weight: 800;
    color: var(--primary);
    display: block;
    line-height: 1;
}

.kcal-label {
    font-size: 14px;
    color: var(--text-light);
}

/* Macros */
.macros {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
}

.macro {
    text-align: center;
}

.macro-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-weight: 700;
    font-size: 15px;
    color: white;
}

.macro-circle.protein { background: var(--protein); }
.macro-circle.fat { background: var(--fat); }
.macro-circle.carbs { background: var(--carbs); }

.macro-label {
    font-size: 13px;
    color: var(--text-light);
}

/* Food details */
.food-details {
    padding-top: 16px;
    border-top: 1px solid #eee;
}

.food-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
}

.food-item-name {
    color: var(--text);
}

.food-item-cal {
    color: var(--text-light);
    font-weight: 600;
}

/* Daily summary */
.daily-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

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

.daily-header h3 {
    font-size: 18px;
}

.daily-date {
    font-size: 13px;
    color: var(--text-light);
}

.daily-total {
    text-align: center;
    margin-bottom: 12px;
}

.daily-kcal-number {
    font-size: 48px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.daily-kcal-label {
    font-size: 16px;
    color: var(--text-light);
    margin-left: 4px;
}

.daily-macros {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-light);
}

.daily-macro {
    display: flex;
    align-items: center;
    gap: 6px;
}

.daily-macro strong {
    color: var(--text);
}

.daily-macro-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.protein-dot { background: var(--protein); }
.fat-dot { background: var(--fat); }
.carbs-dot { background: var(--carbs); }

.daily-bar-container {
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 4px;
}

.daily-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #66BB6A);
    border-radius: 4px;
    transition: width 0.5s ease;
    max-width: 100%;
}

.daily-bar.over-goal {
    background: linear-gradient(90deg, #FF7043, #EF5350);
}

.daily-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-light);
}

.daily-goal-clickable {
    cursor: pointer;
    border-bottom: 1px dashed var(--text-light);
    transition: color 0.2s;
}

.daily-goal-clickable:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* History */
.history-title {
    font-size: 18px;
    margin-bottom: 12px;
    padding-top: 8px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.history-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 12px;
    color: var(--text-light);
}

.history-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    gap: 4px;
}

.history-kcal {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}

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

.history-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

.history-btn:hover {
    background: #f0f0f0;
}

.history-btn-delete:hover {
    background: #ffebee;
}

/* Edit modal */
.edit-modal-content {
    max-height: 80vh;
    overflow-y: auto;
}

.edit-modal-content .manual-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.edit-modal-content .manual-input:focus {
    border-color: var(--primary);
}

.edit-modal-content .manual-row {
    display: flex;
    gap: 10px;
}

.edit-modal-content .manual-field {
    flex: 1;
}

.edit-modal-content .manual-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 4px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 400px;
}

.modal-content h2 {
    margin-bottom: 12px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.hint {
    margin-bottom: 16px !important;
}

.hint a {
    color: var(--primary);
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.modal-content input:focus {
    border-color: var(--primary);
}

.select-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.model-select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    background: white;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23757575' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    transition: border-color 0.2s;
}

.model-select:focus {
    border-color: var(--primary);
}

/* Provider tabs */
.provider-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
}

.provider-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}

.provider-tab.active {
    background: var(--primary);
    color: white;
}

.provider-tab:not(.active):hover {
    background: #f0f0f0;
}

.provider-settings {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Settings divider & goal */
.settings-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 16px 0;
}

.goal-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.goal-input-row .manual-input {
    flex: 1;
    margin-bottom: 0;
}

.goal-unit {
    font-size: 15px;
    color: var(--text-light);
    font-weight: 600;
    white-space: nowrap;
}

/* Settings button */
.settings-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--card);
    box-shadow: var(--shadow);
    font-size: 20px;
    cursor: pointer;
    z-index: 50;
}

/* Manual input */
.manual-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.manual-title {
    font-size: 20px;
    margin-bottom: 16px;
}

.manual-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.manual-input:focus {
    border-color: var(--primary);
}

.manual-row {
    display: flex;
    gap: 10px;
}

.manual-field {
    flex: 1;
}

.manual-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 4px;
}

.manual-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 16px;
}

.btn-text {
    background: none;
    color: var(--primary);
    border: none;
    font-size: 14px;
    padding: 8px 0;
}

.btn-text:hover {
    text-decoration: underline;
}

.btn-ai-help {
    width: 100%;
    margin-top: 8px;
    justify-content: center;
    font-size: 14px;
    color: var(--secondary);
}

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

/* Error message */
.error-msg {
    background: #ffebee;
    color: #c62828;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    margin-top: 12px;
}

.error-msg p {
    margin-bottom: 8px;
}

.btn-error-manual {
    background: white;
    border: 1px solid #c62828;
    color: #c62828;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-error-manual:hover {
    background: #c62828;
    color: white;
}

/* Responsive */
@media (min-width: 600px) {
    .app {
        padding: 24px;
    }
}
