/* CSS Custom Properties */
:root {
    --primary-color: #7868E6;
    --secondary-color: #B8B5FF;
    --accent-color: #FFB4B4;
    --background-light: #EDEEF7;
    --background-accent: #E4FBFF;
    --text-dark: #2c3e50;
    --text-light: #6c757d;
    --white: #ffffff;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --border-color: #e9ecef;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.3s ease;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text-dark);
    background: linear-gradient(135deg, var(--background-light) 0%, var(--background-accent) 100%);
    background-attachment: fixed;
    min-height: 100vh;
    position: relative;
}

/* Paper Texture Effect */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.15) 1px, transparent 0);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: -1;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 20px;
}

.header__title {
    font-size: 1.5rem;
    color: var(--primary-color);
    font-weight: 700;
}

.nav__list {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav__link {
    text-decoration: none;
    color: var(--text-dark);
    font-weight: 500;
    transition: var(--transition);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
}

.nav__link:hover,
.nav__link--active {
    background: var(--secondary-color);
    color: var(--white);
}

/* Main Content */
.main {
    padding: 2rem 0;
    min-height: calc(100vh - 120px);
}

/* Sections */
.section__title {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
    position: relative;
}

.section__title::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: var(--accent-color);
    border-radius: 2px;
}

/* Welcome Section */
.welcome {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem;
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.welcome__title {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.welcome__description {
    font-size: 1.1rem;
    color: var(--text-light);
    max-width: 600px;
    margin: 0 auto;
}

/* Body Diagram */
.body-diagram {
    margin-bottom: 3rem;
}

.diagram-container {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
    align-items: start;
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.body-canvas {
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: crosshair;
    transition: var(--transition);
    max-width: 100%;
    height: auto;
}

.body-canvas:hover {
    border-color: var(--primary-color);
}

.diagram-legend {
    min-width: 200px;
}

.legend__title {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.legend__items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend__item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend__color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

.legend__color--mild {
    background: #90EE90;
}

.legend__color--moderate {
    background: #FFD700;
}

.legend__color--severe {
    background: var(--accent-color);
}

/* Forms */
.swelling-form {
    margin-bottom: 3rem;
}

.form {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.form__group {
    margin-bottom: 1.5rem;
}

.form__label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-dark);
}

.form__select,
.form__textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

.form__select:focus,
.form__textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(120, 104, 230, 0.1);
}

.form__textarea {
    resize: vertical;
    min-height: 100px;
}

.form__error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: none;
}

.form__error.show {
    display: block;
}

/* Intensity Slider */
.intensity-slider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.form__range {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    outline: none;
}

.form__range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.form__range::-webkit-slider-thumb:hover {
    background: var(--secondary-color);
    transform: scale(1.1);
}

.form__range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.intensity-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.intensity-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.intensity-label {
    font-size: 0.875rem;
    color: var(--text-light);
}

.intensity-scale {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-light);
}

/* Checkbox Group */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.checkbox-label:hover {
    background: var(--background-light);
}

.form__checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.checkbox-text {
    font-size: 0.9rem;
}

/* Character Count */
.character-count {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    min-width: 120px;
}

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

.btn--primary:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn--secondary {
    background: var(--border-color);
    color: var(--text-dark);
}

.btn--secondary:hover {
    background: var(--text-light);
    color: var(--white);
}

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

.btn--danger:hover {
    background: #c82333;
    transform: translateY(-2px);
}

.form__actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 2rem;
}

/* History Section */
.history {
    margin-bottom: 3rem;
}

.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.history-list {
    display: grid;
    gap: 1rem;
}

.history-item {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

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

.history-item__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.history-item__title {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.history-item__date {
    font-size: 0.9rem;
    color: var(--text-light);
}

.history-item__intensity {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.intensity-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--white);
}

.intensity-badge--mild {
    background: #28a745;
}

.intensity-badge--moderate {
    background: #ffc107;
    color: var(--text-dark);
}

.intensity-badge--severe {
    background: var(--danger);
}

.history-item__content {
    display: grid;
    gap: 1rem;
}

.history-item__triggers {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.trigger-tag {
    background: var(--background-light);
    color: var(--primary-color);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.history-item__notes {
    font-style: italic;
    color: var(--text-light);
    padding: 1rem;
    background: var(--background-light);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
}

.history-item__actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.btn--small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    min-width: auto;
}

/* Statistics */
.statistics {
    margin-bottom: 3rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.stat-card__title {
    font-size: 1rem;
    color: var(--text-light);
    margin-bottom: 1rem;
}

.stat-card__value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Footer */
.footer {
    background: var(--primary-color);
    color: var(--white);
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}

.footer__text {
    font-size: 0.9rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: 1rem;
    color: var(--text-dark);
    font-weight: 600;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.empty-state__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state__title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-state__description {
    font-size: 1rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header .container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav__list {
        gap: 1rem;
    }
    
    .welcome__title {
        font-size: 2rem;
    }
    
    .section__title {
        font-size: 1.5rem;
    }
    
    .diagram-container {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .form__actions {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        max-width: 300px;
    }
    
    .history-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .history-item__header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .checkbox-group {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .welcome {
        padding: 1rem;
    }
    
    .form {
        padding: 1rem;
    }
    
    .intensity-slider {
        flex-direction: column;
        align-items: stretch;
    }
    
    .intensity-display {
        min-width: auto;
        margin-bottom: 1rem;
    }
    
    .stat-card {
        padding: 1.5rem;
    }
    
    .stat-card__value {
        font-size: 2rem;
    }
}

/* Print Styles */
@media print {
    .header,
    .footer,
    .form,
    .history-controls,
    .loading-overlay {
        display: none;
    }
    
    .body-canvas {
        max-width: 100%;
        height: auto;
    }
    
    .history-item {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus Styles */
button:focus,
input:focus,
select:focus,
textarea:focus,
.nav__link:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000080;
        --secondary-color: #000040;
        --text-dark: #000000;
        --border-color: #000000;
    }
}
