/* Celia Design System
   A warm, professional health/wellness design language
   ================================================== */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Primary Colors */
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-light: #d1fae5;
    --primary-bg: #ecfdf5;

    /* Secondary/Accent (warm orange) */
    --accent: #fb923c;
    --accent-hover: #f97316;
    --accent-light: #fed7aa;
    --accent-bg: #fff7ed;

    /* Semantic Colors */
    --safe: #10b981;
    --safe-bg: #ecfdf5;
    --safe-border: #a7f3d0;
    --unsafe: #ef4444;
    --unsafe-bg: #fef2f2;
    --unsafe-border: #fecaca;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --investigate: #f59e0b;
    --investigate-bg: #fffbeb;
    --investigate-border: #fde68a;

    /* Neutral Colors */
    --neutral: #6b7280;
    --neutral-bg: #f9fafb;
    --neutral-border: #e5e7eb;

    /* Backgrounds */
    --bg: #ffffff;
    --bg-page: #fafaf9;
    --bg-secondary: #f5f5f4;
    --bg-card: #ffffff;

    /* Text */
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    /* Borders */
    --border: #e5e7eb;
    --border-light: #f3f4f6;

    /* Spacing Scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 48px;

    /* Border Radius */
    --radius: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Bottom Nav */
    --bottom-nav-height: 64px;
}

html {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(to bottom, #fff1f2, #fef3c7);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    letter-spacing: -0.01em;
    line-height: 1.3;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    background: var(--bg);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.tagline {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Main Content */
main {
    padding: var(--space-xl) var(--space-xl) calc(var(--bottom-nav-height) + var(--space-3xl));
    max-width: 520px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: var(--space-xl);
    box-shadow: var(--shadow);
}

/* Upload Area */
#upload-area {
    position: relative;
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: var(--space-3xl) var(--space-xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

#upload-area:hover,
#upload-area:focus-within {
    border-color: var(--primary);
    background: var(--primary-bg);
}

#upload-area:active {
    transform: scale(0.99);
}

.upload-icon {
    color: var(--text-muted);
    margin-bottom: var(--space-md);
}

.upload-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 14px;
    color: var(--text-muted);
}

#file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

/* Preview */
#preview-section {
    margin-top: var(--space-lg);
}

#preview-image {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

.preview-actions {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-md);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    min-height: 48px;
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    flex: 1;
}

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

.btn-primary {
    background: #10b981;
    color: white;
}

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

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

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--text-muted);
}

.btn-full {
    width: 100%;
    margin-top: var(--space-xl);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading States */
#loading-section {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
}

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

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

.loading-text {
    font-weight: 600;
    font-size: 18px;
    color: var(--text);
    margin-bottom: 6px;
}

.loading-hint {
    font-size: 14px;
    color: var(--text-muted);
}

/* Results Card */
#verdict-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: var(--space-xl);
    text-align: center;
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-lg);
}

#verdict-badge {
    display: inline-block;
    padding: 8px 24px;
    border-radius: var(--radius-full);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
}

#verdict-badge.safe {
    background: var(--safe-bg);
    color: var(--safe);
}

#verdict-badge.unsafe {
    background: var(--unsafe-bg);
    color: var(--unsafe);
}

#verdict-badge.investigate {
    background: var(--warning-bg);
    color: var(--warning);
}

#product-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-sm);
}

#verdict-summary {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
}

#confidence-badge {
    display: inline-block;
    margin-top: var(--space-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

/* Details Accordion */
#details-accordion {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.detail-group {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.detail-group summary {
    padding: var(--space-lg);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    list-style: none;
    user-select: none;
    min-height: 56px;
    transition: background var(--transition-fast);
}

.detail-group summary:hover {
    background: var(--bg-secondary);
}

.detail-group summary::-webkit-details-marker {
    display: none;
}

.detail-group summary::after {
    content: '';
    margin-left: auto;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform var(--transition);
}

.detail-group[open] summary::after {
    transform: rotate(45deg);
}

.detail-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.detail-group.danger .detail-icon {
    background: var(--unsafe-bg);
    color: var(--unsafe);
}

.detail-group.warning .detail-icon {
    background: var(--warning-bg);
    color: var(--warning);
}

.detail-group.safe .detail-icon {
    background: var(--safe-bg);
    color: var(--safe);
}

.detail-group.neutral .detail-icon {
    background: var(--neutral-bg);
    color: var(--neutral);
}

.detail-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 10px;
    border-radius: var(--radius-full);
}

.detail-group ul {
    padding: 0 var(--space-lg) var(--space-lg) 56px;
    list-style: none;
}

.detail-group li {
    font-size: 15px;
    color: var(--text-secondary);
    padding: 4px 0;
    position: relative;
}

.detail-group li::before {
    content: '\2022';
    position: absolute;
    left: -16px;
    color: var(--text-muted);
}

.detail-group p {
    padding: 0 var(--space-lg) var(--space-lg) 56px;
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* History Panel */
#history-view {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 200;
    overflow-y: auto;
    animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    background: var(--bg);
}

.history-header h2 {
    font-size: 20px;
    font-weight: 600;
}

#history-list {
    padding: var(--space-lg) var(--space-xl);
}

.history-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 72px;
}

.history-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.history-thumb {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-secondary);
}

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

.history-product {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.history-verdict {
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.history-verdict.safe {
    background: var(--safe-bg);
    color: var(--safe);
}

.history-verdict.unsafe {
    background: var(--unsafe-bg);
    color: var(--unsafe);
}

.history-verdict.investigate {
    background: var(--warning-bg);
    color: var(--warning);
}

.history-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.history-delete:hover {
    color: var(--unsafe);
    background: var(--unsafe-bg);
}

#history-empty {
    text-align: center;
    padding: var(--space-3xl) var(--space-xl);
    color: var(--text-muted);
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 1000;
}

.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text-muted);
    padding: var(--space-sm) var(--space-lg);
    transition: color var(--transition-fast);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    min-width: 64px;
    min-height: 48px;
}

.bottom-nav .nav-item:hover {
    color: var(--text-secondary);
}

.bottom-nav .nav-item.active {
    color: var(--primary);
}

.bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
    transition: transform var(--transition-fast);
}

.bottom-nav .nav-item:active svg {
    transform: scale(0.9);
}

.bottom-nav .nav-item span {
    font-size: 12px;
    font-weight: 500;
}

/* Account Modal */
.account-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.account-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.account-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-radius: 24px 24px 0 0;
    padding: var(--space-xl) var(--space-xl) calc(var(--space-xl) + env(safe-area-inset-bottom));
    z-index: 2001;
    transform: translateY(100%);
    transition: transform var(--transition-slow);
}

.account-modal-overlay.visible .account-modal {
    transform: translateY(0);
}

.account-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-xl);
}

.account-modal-header h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
}

.account-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-secondary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.account-modal-close:hover {
    background: var(--border);
    color: var(--text);
}

.account-modal-close svg {
    width: 20px;
    height: 20px;
}

.account-email {
    background: var(--bg-secondary);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
}

.account-email-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.account-email-value {
    font-size: 16px;
    color: var(--text);
    font-weight: 500;
}

.account-signout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    padding: var(--space-md);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.account-signout:hover {
    background: var(--bg-secondary);
    border-color: var(--text-muted);
}

.account-signin {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    padding: var(--space-md);
    background: #10b981;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.account-signin:hover {
    background: #059669;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-safe { color: var(--safe); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--unsafe); }
.text-muted { color: var(--text-muted); }

.bg-safe { background: var(--safe-bg); }
.bg-warning { background: var(--warning-bg); }
.bg-danger { background: var(--unsafe-bg); }

/* Score Ring Colors - used across pages */
.score-ring.high-risk {
    background: #ef4444;
    color: white;
    border: none;
}

.score-ring.moderate-risk {
    background: #f59e0b;
    color: white;
    border: none;
}

.score-ring.low-risk,
.score-ring.very-low-risk {
    background: #10b981;
    color: white;
    border: none;
}

/* Saved Score Cards - bordered style */
.saved-score.high-risk {
    border-color: var(--unsafe);
    color: var(--unsafe);
    background: var(--unsafe-bg);
}

.saved-score.moderate-risk {
    border-color: var(--warning);
    color: var(--warning);
    background: var(--warning-bg);
}

.saved-score.low-risk,
.saved-score.very-low-risk {
    border-color: var(--safe);
    color: var(--safe);
    background: var(--safe-bg);
}

/* Responsive */
@media (min-width: 640px) {
    main {
        padding: var(--space-2xl) var(--space-xl) calc(var(--bottom-nav-height) + var(--space-3xl));
    }

    #upload-area {
        padding: 64px var(--space-2xl);
    }
}

/* Optional text selection styling */
::selection {
    background: var(--primary-light);
    color: var(--text);
}

/* Focus states for accessibility */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
