/* CSS Variables for consistent theming */
:root {
    --primary-color: #7868E6;
    --secondary-color: #B8B5FF;
    --accent-color: #FFB4B4;
    --background-light: #EDEEF7;
    --background-lighter: #E4FBFF;
    --text-dark: #2D3748;
    --text-light: #718096;
    --white: #FFFFFF;
    --success: #48BB78;
    --warning: #ED8936;
    --danger: #F56565;
    --border-color: #E2E8F0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
    --transition: all 0.3s ease;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Paper Texture Background */
body {
    background-color: var(--background-light);
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(120, 104, 230, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(184, 181, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(255, 180, 180, 0.1) 0%, transparent 50%);
    background-attachment: fixed;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.1) 2px,
            rgba(255, 255, 255, 0.1) 4px
        );
    pointer-events: none;
    z-index: -1;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    padding: 1rem 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header__title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header__icon {
    font-size: 1.8rem;
}

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

.nav-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    color: var(--white);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

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

/* Main Content */
.main {
    flex: 1;
    padding: 2rem 0;
}

.section {
    display: none;
    animation: fadeIn 0.5s ease-in-out;
}

.section.active {
    display: block;
}

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

.section__header {
    text-align: center;
    margin-bottom: 2rem;
}

.section__title {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.section__subtitle {
    color: var(--text-light);
    font-size: 1.1rem;
}

/* Pain Form */
.pain-form {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 600px;
    margin: 0 auto;
    border: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1.5rem;
}

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

.form-label__text {
    font-size: 1rem;
}

.form-label__required {
    color: var(--danger);
    margin-left: 0.25rem;
}

/* Pain Scale */
.pain-scale {
    background: var(--background-light);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
}

.pain-scale__visual {
    margin-bottom: 1rem;
}

.pain-scale__bar {
    height: 20px;
    background: linear-gradient(to right, var(--success), var(--warning), var(--danger));
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

.pain-scale__fill {
    height: 100%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    transition: var(--transition);
    width: 0%;
}

.pain-scale__labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.pain-scale__slider {
    width: 100%;
    height: 40px;
    background: transparent;
    outline: none;
    margin: 1rem 0;
    cursor: pointer;
    -webkit-appearance: none;
}

.pain-scale__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.pain-scale__slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.pain-scale__slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow);
}

.pain-scale__value {
    text-align: center;
    background: var(--white);
    padding: 0.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.pain-scale__value span:first-child {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.pain-scale__description {
    display: block;
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* Body Diagram */
.body-diagram {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    text-align: center;
}

.body-diagram__container {
    max-width: 300px;
    margin: 0 auto 1rem;
}

.body-diagram__svg {
    width: 100%;
    height: auto;
    cursor: pointer;
}

.body-part {
    cursor: pointer;
    transition: var(--transition);
}

.body-part:hover {
    fill: rgba(120, 104, 230, 0.2);
    stroke: var(--primary-color);
    stroke-width: 2;
}

.body-part.selected {
    fill: var(--secondary-color);
    stroke: var(--primary-color);
    stroke-width: 3;
}

.body-diagram__selected {
    background: var(--background-light);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
}

.body-diagram__label {
    font-weight: 600;
    color: var(--text-dark);
}

.body-diagram__area {
    color: var(--primary-color);
    font-weight: 600;
}

/* Form Inputs */
.form-input,
.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);
    font-family: inherit;
}

.form-input:focus,
.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-counter {
    text-align: right;
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 0.25rem;
}

/* Medication Input */
.medication-input {
    position: relative;
}

.medication-suggestions {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-top: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.medication-suggestion {
    display: block;
    width: 100%;
    padding: 0.75rem;
    border: none;
    background: var(--white);
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

.medication-suggestion:hover {
    background: var(--background-light);
}

.medication-suggestion:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn--primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
}

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

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

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

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

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

.btn__icon {
    font-size: 1.1rem;
}

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

/* History Section */
.history-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--white);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

.history-filters {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.chart-container {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    position: relative;
}

.chart-container canvas {
    max-width: 100%;
    height: auto;
}

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

.history-item {
    background: var(--white);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
    transition: var(--transition);
}

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

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

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

.history-item__pain {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

.history-item__body {
    display: grid;
    gap: 0.5rem;
}

.history-item__location {
    font-weight: 600;
    color: var(--text-dark);
}

.history-item__medication {
    color: var(--text-light);
    font-style: italic;
}

.history-item__notes {
    color: var(--text-dark);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.history-empty {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}

.history-empty__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.history-empty__title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
}

/* Settings Section */
.settings-content {
    max-width: 600px;
    margin: 0 auto;
}

.settings-group {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.settings-group__title {
    font-size: 1.3rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--background-light);
}

.settings-item {
    margin-bottom: 1.5rem;
}

.settings-item:last-child {
    margin-bottom: 0;
}

.settings-label {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    font-weight: 500;
}

.settings-checkbox {
    display: none;
}

.settings-checkbox__custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    position: relative;
    transition: var(--transition);
    flex-shrink: 0;
}

.settings-checkbox:checked + .settings-checkbox__custom {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.settings-checkbox:checked + .settings-checkbox__custom::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--white);
    font-size: 12px;
    font-weight: bold;
}

.settings-text {
    flex: 1;
    color: var(--text-dark);
}

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

.footer__text {
    font-size: 0.9rem;
    opacity: 0.8;
}

.footer__link {
    color: var(--secondary-color);
    text-decoration: none;
    transition: var(--transition);
}

.footer__link:hover {
    color: var(--white);
    text-decoration: underline;
}

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

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

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

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

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    max-width: 300px;
    animation: slideIn 0.3s ease-out;
    position: relative;
    overflow: hidden;
}

.toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary-color);
}

.toast--success::before {
    background: var(--success);
}

.toast--warning::before {
    background: var(--warning);
}

.toast--error::before {
    background: var(--danger);
}

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

.toast__icon {
    font-size: 1.2rem;
}

.toast__message {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-dark);
}

.toast__close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-light);
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 0.5rem;
    }
    
    .header__title {
        font-size: 1.3rem;
    }
    
    .nav-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }
    
    .section__title {
        font-size: 1.8rem;
    }
    
    .pain-form {
        padding: 1.5rem;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .history-controls {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .history-filters {
        justify-content: center;
    }
    
    .chart-container {
        padding: 1rem;
    }
    
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }
    
    .toast {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.5rem 0;
    }
    
    .header__nav {
        justify-content: center;
    }
    
    .main {
        padding: 1rem 0;
    }
    
    .section__title {
        font-size: 1.5rem;
    }
    
    .pain-form {
        padding: 1rem;
    }
    
    .settings-group {
        padding: 1.5rem;
    }
    
    .history-item {
        padding: 1rem;
    }
    
    .history-item__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-light: #000000;
        --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    }
    
    .btn {
        border-width: 3px;
    }
    
    .form-input,
    .form-select,
    .form-textarea {
        border-width: 3px;
    }
}

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

/* Print styles */
@media print {
    .header,
    .footer,
    .btn,
    .loading-overlay,
    .toast-container {
        display: none !important;
    }
    
    .main {
        padding: 0;
    }
    
    .section {
        display: block !important;
        page-break-inside: avoid;
    }
    
    .history-item {
        border: 1px solid #000;
        margin-bottom: 1rem;
        page-break-inside: avoid;
    }
}
