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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #d97706;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: 80px;
    -webkit-text-size-adjust: 100%;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    font-size: 0.85rem;
    background: rgba(255,255,255,0.2);
    padding: 2px 10px;
    border-radius: 20px;
}

.btn-link {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: underline;
}

.inline-form { display: inline; }

/* Content */
.content {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* Bottom nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    min-height: 56px;
    justify-content: center;
}

.nav-item.active {
    color: var(--primary);
    font-weight: 600;
}

.nav-icon {
    font-size: 1.3rem;
    margin-bottom: 2px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 48px;
}

.btn-block { width: 100%; }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text);
}
.btn-secondary:hover { background: #cbd5e1; }
.btn-secondary:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

/* Forms */
.input-field {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--card-bg);
    min-height: 48px;
}

.input-field:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
    border-color: var(--primary);
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
}

/* Login */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20vh;
}

.login-title {
    font-size: 2rem;
    font-weight: 800;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-form {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: var(--card-bg);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}

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

/* Image cards */
.image-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.image-card {
    position: relative;
}

.image-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 12px;
    background: var(--card-bg);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 120px;
    text-align: center;
    transition: border-color 0.2s;
}

.image-label:hover {
    border-color: var(--primary);
}

.image-label.has-image {
    border-style: solid;
    border-color: var(--success);
    padding: 4px;
}

.image-icon {
    font-size: 2rem;
    margin-bottom: 4px;
}

.file-input {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    opacity: 0;
}

.image-preview {
    width: 100%;
    border-radius: 8px;
    object-fit: cover;
    max-height: 150px;
}

/* Status messages */
.status-message {
    padding: 12px;
    border-radius: var(--radius);
    margin: 12px 0;
    font-size: 0.9rem;
    text-align: center;
}

.status-loading {
    background: #eff6ff;
    color: var(--primary);
}

.status-error {
    background: #fef2f2;
    color: var(--error);
}

/* Entry form */
.entry-form {
    margin-top: 16px;
}

/* Success card */
.success-card {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
    text-align: center;
}

.success-card h3 {
    color: var(--success);
    margin-bottom: 8px;
}

#successDetails {
    font-size: 0.9rem;
    margin-bottom: 12px;
}

/* Cards & Summaries */
.summary-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.summary-card h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-muted);
}

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

.stats-grid-small {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-weight: 700;
    font-size: 1.1rem;
}

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

/* Insights */
.insights-list {
    list-style: none;
    font-size: 0.9rem;
}

.insights-list li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.insights-list li:last-child {
    border-bottom: none;
}

/* History */
.year-group {
    margin-bottom: 24px;
}

.year-heading {
    font-size: 1.2rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--primary);
}

.month-card {
    display: block;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 8px;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.month-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

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

.month-name {
    font-weight: 700;
    font-size: 1.05rem;
}

.entry-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Month detail entries */
.entry-card {
    display: block;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 8px;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow);
}

.entry-date {
    font-weight: 700;
    margin-bottom: 4px;
}

.entry-details {
    display: flex;
    gap: 16px;
    font-size: 0.95rem;
}

.entry-meta {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Entry detail */
.detail-grid {
    display: flex;
    flex-direction: column;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.detail-label {
    color: var(--text-muted);
}

.detail-value {
    font-weight: 600;
}

/* Image gallery */
.image-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.gallery-item h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.gallery-image {
    width: 100%;
    border-radius: var(--radius);
    object-fit: contain;
    max-height: 300px;
    background: #f1f5f9;
}

/* Entry actions */
.entry-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-danger {
    background: var(--error);
    color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
    min-height: 36px;
}

/* Navigation */
.page-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.badge-manual_entry { color: var(--text-muted); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

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

/* OCR status badges */
.badge-auto_ok { color: var(--success); }
.badge-auto_low_confidence { color: var(--warning); }
.badge-manually_corrected { color: var(--primary); }
.badge-reviewed_warning { color: var(--warning); }

h2 { margin-bottom: 16px; }
