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

:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

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

/* Header */
.header {
    text-align: center;
    padding: 24px 0 16px;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* Camera Area */
.camera-area {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--surface);
    border-radius: 20px;
    overflow: hidden;
    margin: 16px 0;
    border: 2px dashed var(--surface-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.3s;
}

.camera-area:hover,
.camera-area:focus {
    border-color: var(--primary);
}

.camera-area.has-image {
    border: 2px solid var(--primary);
}

.camera-placeholder {
    text-align: center;
    color: var(--text-muted);
}

.camera-placeholder svg {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.camera-placeholder p {
    font-size: 0.95rem;
}

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

#fileInput {
    display: none;
}

/* Buttons */
.actions {
    display: flex;
    gap: 12px;
    margin: 16px 0;
}

.btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--surface-light);
}

.btn-secondary:hover {
    background: var(--surface-light);
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 40px 20px;
}

.loading.active {
    display: block;
}

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

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

.loading p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Results */
.result {
    display: none;
    background: var(--surface);
    border-radius: 20px;
    padding: 24px;
    margin-top: 16px;
    animation: fadeIn 0.4s ease;
}

.result.active {
    display: block;
}

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

.result h2 {
    color: var(--primary);
    font-size: 1.2rem;
    margin: 20px 0 8px;
}

.result h2:first-child {
    margin-top: 0;
}

.result p {
    line-height: 1.6;
    color: var(--text);
}

.result ul, .result ol {
    padding-left: 20px;
    margin: 8px 0;
}

.result li {
    line-height: 1.6;
    margin: 4px 0;
}

.result strong {
    color: var(--accent);
}

.result table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9rem;
}

.result th {
    background: var(--surface-light);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--primary);
}

.result td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--surface-light);
}

.result tr:last-child td {
    border-bottom: none;
}

/* History */
.history {
    margin-top: 32px;
}

.history h3 {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: var(--surface-light);
}

.history-item img {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    object-fit: cover;
}

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

.history-item .info .name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item .info .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.history-item .cals {
    font-weight: 700;
    color: var(--accent);
    font-size: 1rem;
    white-space: nowrap;
}

.empty-history {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: 0.9rem;
}

/* PWA install banner */
.install-banner {
    display: none;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 16px;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.install-banner.show {
    display: flex;
}

.install-banner p {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 500;
}

.install-banner .close-banner {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
}

/* Error */
.error {
    background: #7f1d1d;
    color: #fecaca;
    padding: 14px 16px;
    border-radius: 14px;
    margin-top: 12px;
    display: none;
    font-size: 0.9rem;
}

.error.active {
    display: block;
}

/* Login */
.login-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--surface);
    border-radius: 20px;
    padding: 40px 28px;
    text-align: center;
    width: 100%;
    max-width: 360px;
}

.login-box h1 {
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.login-box p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.login-box input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid var(--surface-light);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

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

.login-error {
    color: #f87171 !important;
    margin-top: 12px !important;
    font-size: 0.85rem !important;
}

@media (max-width: 360px) {
    .header h1 { font-size: 1.5rem; }
    .result { padding: 16px; }
}
