/* VISCERAL® - Design System v1.2 - Lighter & Refined */

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

:root {
    /* Colors - Lighter palette */
    --color-action: #DC2626;
    --color-safe: #22C55E;
    --color-warning: #F59E0B;
    --color-info: #3B82F6;
    --color-bg: #FAFAF9;
    --color-bg-card: #FFFFFF;
    --color-text: #18181B;
    --color-text-muted: #71717A;
    --color-text-light: #A1A1AA;
    --color-text-inverted: #FFFFFF;
    --color-border: #E4E4E7;
    --color-border-strong: #D4D4D8;

    /* Typography */
    --font-display: 'Archivo Black', sans-serif;
    --font-body: 'Inter', -apple-system, sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Effects - Lighter, softer */
    --border-thin: 1px solid var(--color-border);
    --border-card: 1px solid var(--color-border);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --transition-fast: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index */
    --z-modal: 100;
    --z-toast: 90;
    --z-trial-bar: 95;
    --z-nav: 80;

    /* Safe areas for iOS */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

/* Body - Clean, no texture */
body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(80px + var(--safe-bottom));
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

/* PWA Standalone - Hide iOS bars */
@media all and (display-mode: standalone) {

    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    .page-wrapper {
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Typography - Stronger headings with tighter spacing */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-display);
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: -0.03em;
    font-weight: 900;
}

.h1 {
    font-size: var(--text-3xl);
    letter-spacing: -0.04em;
}

.h2 {
    font-size: var(--text-2xl);
    letter-spacing: -0.03em;
}

.h3 {
    font-size: var(--text-xl);
    letter-spacing: -0.02em;
}

.h4 {
    font-size: var(--text-base);
    font-weight: 800;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: -0.01em;
}

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

.text-light {
    color: var(--color-text-light);
}

.text-action {
    color: var(--color-action);
}

.text-safe {
    color: var(--color-safe);
}

.text-warning {
    color: var(--color-warning);
}

.text-center {
    text-align: center;
}

.text-2xl {
    font-size: var(--text-2xl);
}

.text-3xl {
    font-size: var(--text-3xl);
}

.font-bold {
    font-weight: 700;
}

.text-xs {
    font-size: var(--text-xs);
}

.text-sm {
    font-size: var(--text-sm);
}

/* Layout */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space-4);
    padding-bottom: calc(var(--space-8) + 20px);
}

.page-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: calc(48px + var(--safe-top));
}

.page-wrapper.has-trial-bar {
    padding-top: calc(88px + var(--safe-top));
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.flex-1 {
    flex: 1;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.mb-1 {
    margin-bottom: var(--space-1);
}

.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-3 {
    margin-bottom: var(--space-3);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-6 {
    margin-bottom: var(--space-6);
}

.mt-2 {
    margin-top: var(--space-2);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mt-6 {
    margin-top: var(--space-6);
}

.p-4 {
    padding: var(--space-4);
}

/* Bento Grid - Uniform sizing */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

.card-full {
    grid-column: span 2;
}

/* Cards - Lighter, softer */
.card {
    background: var(--color-bg-card);
    border: var(--border-card);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-card);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card:active {
    transform: scale(0.99);
}

.card-action {
    background: var(--color-action);
    color: var(--color-text-inverted);
    border-color: transparent;
}

.card-safe {
    background: var(--color-safe);
    color: var(--color-text-inverted);
    border-color: transparent;
}

.card-warning {
    background: #FEF3C7;
    border-color: var(--color-warning);
}

.card-tip {
    background: #EFF6FF;
    border-color: var(--color-info);
}

/* Bento Cards - Uniform height */
.bento-grid .card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 140px;
    padding: var(--space-4);
}

/* Big Text Card (Insulin Mode) */
.big-text-card {
    text-align: center;
    padding: var(--space-4);
}

.big-text-card .mode-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: var(--space-1);
}

.big-text-card .mode-label {
    font-size: var(--text-lg);
    font-family: var(--font-display);
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

.big-text-card .mode-sublabel {
    font-size: var(--text-xs);
    opacity: 0.85;
    margin-top: var(--space-1);
}

/* Metabolic Score */
.metabolic-score {
    text-align: center;
}

.metabolic-score-ring {
    position: relative;
    margin: 0 auto var(--space-2);
    width: 70px;
    height: 70px;
}

.metabolic-score-ring svg {
    transform: rotate(-90deg);
}

.metabolic-score-ring .ring-bg {
    fill: none;
    stroke: #f4f4f5;
    stroke-width: 5;
}

.metabolic-score-ring .ring-fill {
    fill: none;
    stroke: var(--color-action);
    stroke-width: 5;
    stroke-linecap: round;
    transition: stroke-dashoffset var(--transition-smooth);
}

.metabolic-score-value {
    font-size: var(--text-xl);
    font-weight: 900;
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

.metabolic-score-label {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 700;
}

/* Stat Bar - Horizontal progress */
.stat-bar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.stat-bar-label {
    font-size: var(--text-sm);
    font-weight: 700;
    min-width: 70px;
    color: var(--color-text);
}

.stat-bar-track {
    flex: 1;
    height: 8px;
    background: #f4f4f5;
    border-radius: 100px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 100px;
    transition: width var(--transition-smooth);
    background: var(--color-text);
}

.stat-bar-fill.fill-safe {
    background: var(--color-safe);
}

.stat-bar-fill.fill-action {
    background: var(--color-action);
}

.stat-bar-fill.fill-warning {
    background: var(--color-warning);
}

.stat-bar-value {
    font-size: var(--text-sm);
    font-weight: 800;
    min-width: 45px;
    text-align: right;
    color: var(--color-text);
}

/* Progress Bar (simple) */
.progress-bar {
    width: 100%;
    height: 6px;
    background: #f4f4f5;
    border-radius: 100px;
    overflow: hidden;
    margin-top: var(--space-2);
}

.progress-bar-fill {
    height: 100%;
    border-radius: 100px;
    background: var(--color-safe);
    transition: width var(--transition-smooth);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 700;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 0.01em;
}

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

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

.btn-primary:hover {
    opacity: 0.9;
}

.btn-action {
    background: var(--color-action);
    color: var(--color-text-inverted);
}

.btn-action:hover {
    opacity: 0.9;
}

.btn-safe {
    background: var(--color-safe);
    color: var(--color-text-inverted);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--color-border-strong);
    color: var(--color-text);
}

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-base);
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
}

/* Quick Log Button */
.quick-log-btn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-4);
    background: var(--color-bg-card);
    border: var(--border-card);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.quick-log-btn:hover {
    background: var(--color-bg);
}

.quick-log-btn:active {
    transform: scale(0.99);
}

.quick-log-btn.completed {
    background: var(--color-safe);
    border-color: transparent;
    color: var(--color-text-inverted);
}

.quick-log-btn.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Water Buttons */
.water-buttons {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

.water-btn {
    flex: 1;
    padding: var(--space-3);
    background: var(--color-bg);
    border: var(--border-card);
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.water-btn:hover {
    background: var(--color-info);
    color: var(--color-text-inverted);
    border-color: transparent;
}

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

/* Forms */
.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    font-weight: 600;
    font-size: var(--text-sm);
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.form-input {
    width: 100%;
    padding: var(--space-4);
    font-size: var(--text-base);
    font-family: var(--font-body);
    background: var(--color-bg-card);
    border: var(--border-card);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    color: var(--color-text);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-action);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.form-input::placeholder {
    color: var(--color-text-light);
}

/* Checklist */
.checklist {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    border: var(--border-thin);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.checklist-item:hover {
    background: #f4f4f5;
}

.checklist-item.checked {
    background: #DCFCE7;
    border-color: var(--color-safe);
}

.checklist-item.today {
    border-color: var(--color-action);
    border-width: 2px;
}

.checklist-checkbox {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    font-weight: 900;
    font-size: var(--text-xs);
    background: var(--color-bg-card);
}

.checklist-item.checked .checklist-checkbox {
    background: var(--color-safe);
    color: var(--color-text-inverted);
    border-color: var(--color-safe);
}

.checklist-label {
    flex: 1;
    font-weight: 600;
}

/* Streak Chain */
.streak-chain {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
}

.streak-link {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-border);
    border-radius: 50%;
    font-weight: 800;
    font-size: var(--text-xs);
    background: var(--color-bg);
    transition: all var(--transition-fast);
}

.streak-link.active {
    background: var(--color-safe);
    border-color: var(--color-safe);
    color: var(--color-text-inverted);
}

.streak-link.today {
    background: var(--color-action);
    border-color: var(--color-action);
    color: var(--color-text-inverted);
    transform: scale(1.1);
}

.streak-link.future {
    opacity: 0.4;
}

/* Trial Bar - Fixed at very top with safe area */
.trial-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--color-warning) 0%, #EA580C 100%);
    color: var(--color-text-inverted);
    padding: calc(var(--safe-top) + 8px) var(--space-4) 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--text-sm);
    font-weight: 700;
    z-index: var(--z-trial-bar);
}

.trial-bar a {
    background: var(--color-text-inverted);
    color: var(--color-text);
    padding: 6px 14px;
    border-radius: 100px;
    text-decoration: none;
    font-size: var(--text-xs);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    transition: all var(--transition-fast);
}

.trial-bar a:active {
    transform: scale(0.95);
}

/* Bottom Navigation - Above safe area */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    background: var(--color-bg-card);
    border-top: var(--border-thin);
    padding: var(--space-2) 0;
    padding-bottom: calc(var(--space-2) + var(--safe-bottom));
    z-index: var(--z-nav);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-2) var(--space-3);
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    transition: all var(--transition-fast);
}

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

.nav-item-icon {
    font-size: var(--text-lg);
}

/* Profile Avatar */
.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f4f4f5 0%, #e4e4e7 100%);
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-2xl);
    font-weight: 900;
    position: relative;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-edit {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 26px;
    height: 26px;
    background: var(--color-text);
    border: 2px solid var(--color-bg-card);
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Gamification Badge */
.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-top: var(--space-2);
}

.badge-bronze {
    background: linear-gradient(135deg, #D4A574 0%, #B8860B 100%);
    color: #fff;
}

.badge-silver {
    background: linear-gradient(135deg, #C0C0C0 0%, #A8A8A8 100%);
    color: #333;
}

.badge-gold {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: #333;
}

.badge-platinum {
    background: linear-gradient(135deg, #E5E4E2 0%, #BCC6CC 100%);
    color: #333;
}

.badge-diamond {
    background: linear-gradient(135deg, #B9F2FF 0%, #89CFF0 100%);
    color: #333;
}

/* Status Dots */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-ok {
    background: var(--color-safe);
}

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

/* Badge */
.badge-safe {
    display: inline-block;
    background: var(--color-safe);
    color: var(--color-text-inverted);
    padding: var(--space-1) var(--space-3);
    border-radius: 100px;
    font-size: var(--text-xs);
    font-weight: 800;
    text-transform: uppercase;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    z-index: var(--z-modal);
}

.modal.hidden {
    display: none;
}

.modal-content {
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Animations - Smoother */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

.animate-slideUp {
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.animate-fadeIn {
    animation: fadeIn 0.3s ease;
}

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

/* Scroll lock for dashboard */
.no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
}