/**
 * Widget Styles
 *
 * Embeddable calculator widgets with CSS variable theming.
 * Colors can be customized via query parameters:
 * - primary: Primary button/accent color
 * - bg: Background color
 * - text: Text color
 */

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    border: none;
    outline: none;
    background: transparent;
}

.widget-body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--widget-text);
    background-color: var(--widget-bg);
}

.widget-container {
    padding: 16px;
    max-width: 100%;
}

/* Widget Header */
.widget-header {
    text-align: center;
    margin-bottom: 16px;
}

.widget-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--widget-text);
    margin-bottom: 4px;
}

/* Mode Toggle */
.widget-mode-toggle {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
}

.widget-mode-btn {
    padding: 6px 16px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    color: var(--widget-text);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.widget-mode-btn:hover {
    background: #e8e8e8;
}

.widget-mode-btn.active {
    background: var(--widget-primary);
    color: #fff;
    border-color: var(--widget-primary);
}

/* Form Styles */
.widget-form {
}

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

.widget-label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--widget-text);
}

.widget-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.widget-input-wrapper {
    position: relative;
    flex: 1;
}

.widget-input-wrapper.wide {
    flex: 1;
    width: 100%;
}

.widget-input {
    width: 100%;
    padding: 8px 40px 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: var(--widget-text);
    background: #fff;
}

.widget-input:focus {
    outline: none;
    border-color: var(--widget-primary);
    box-shadow: 0 0 0 2px rgba(66, 139, 202, 0.2);
}

.widget-input::placeholder {
    color: #aaa;
    opacity: 1;
}

.widget-select::placeholder {
    color: #aaa;
    opacity: 1;
}

.widget-unit {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: #888;
    pointer-events: none;
}

.widget-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    color: var(--widget-text);
    background: #fff;
    cursor: pointer;
}

.widget-select:focus {
    outline: none;
    border-color: var(--widget-primary);
}

/* Gender Toggle */
.widget-gender-toggle {
    display: flex;
    gap: 8px;
}

.widget-gender-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    color: var(--widget-text);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.widget-gender-btn:hover {
    background: #e8e8e8;
}

.widget-gender-btn.active {
    background: var(--widget-primary);
    color: #fff;
    border-color: var(--widget-primary);
}

/* Checkbox */
.widget-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--widget-text);
}

.widget-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--widget-primary);
}

/* Submit Button */
.widget-submit {
    width: 100%;
    padding: 12px 20px;
    background: var(--widget-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
    margin-top: 16px;
}

.widget-submit:hover {
    opacity: 0.9;
}

.widget-submit:active {
    opacity: 0.8;
}

/* Results */
.widget-results {
    display: none;
    margin-top: 16px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.widget-results.visible {
    display: block;
}

.widget-result-main {
    text-align: center;
    margin-bottom: 12px;
}

.widget-result-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--widget-primary);
    line-height: 1.2;
}

.widget-result-label {
    font-size: 13px;
    color: #666;
    margin-top: 4px;
}

.widget-result-category {
    text-align: center;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 500;
    margin-bottom: 12px;
}

.widget-result-category.green {
    background: #d4edda;
    color: #155724;
}

.widget-result-category.yellow {
    background: #fff3cd;
    color: #856404;
}

.widget-result-category.orange {
    background: #ffe5d0;
    color: #8a4000;
}

.widget-result-category.red {
    background: #f8d7da;
    color: #721c24;
}

/* Detailed Results Table */
.widget-details {
    margin-top: 12px;
}

.widget-details-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.widget-details-table th,
.widget-details-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.widget-details-table th {
    font-weight: 500;
    color: #666;
    background: #f1f3f5;
}

.widget-details-table td:last-child {
    font-weight: 500;
}

.widget-details-table tr.current {
    background: rgba(66, 139, 202, 0.1);
    font-weight: 600;
}

.widget-details-table tr.current td {
    border-color: var(--widget-primary);
}

/* Errors */
.widget-errors {
    background: #f8d7da;
    color: #721c24;
    padding: 10px 12px;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 13px;
}

.widget-errors ul {
    margin: 0;
    padding-left: 20px;
}

/* Warning (e.g., unrealistic weight loss goal) */
.widget-result-warning {
    margin-top: 16px;
    padding: 12px 14px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    border-radius: 4px;
    color: #856404;
    font-size: 13px;
    line-height: 1.4;
}

/* Field-level errors */
.widget-form-group.has-error .widget-label {
    color: #dc3545;
}

.widget-form-group.has-error .widget-input,
.widget-form-group.has-error .widget-select {
    border-color: #dc3545;
}

.widget-form-group.has-error .widget-input:focus,
.widget-form-group.has-error .widget-select:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
}

.widget-form-group.has-error .widget-gender-btn {
    border-color: #dc3545;
}

/* Footer */
.widget-footer {
    text-align: center;
    padding: 12px 16px 0;
    margin-top: 8px;
}

.widget-footer a {
    color: #999;
    font-size: 11px;
    text-decoration: none;
}

.widget-footer a:hover {
    color: var(--widget-primary);
    text-decoration: underline;
}

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

/* Conditional display based on mode */
.imperial-only,
.metric-only {
    display: none;
}

.mode-imperial .imperial-only {
    display: flex;
}

.mode-metric .metric-only {
    display: flex;
}

/* Simple mode hides details */
.widget-simple .widget-details {
    display: none;
}

/* Activity Level Select (for TDEE) */
.widget-activity-select {
    width: 100%;
}

/* Female-only fields (for Body Fat) */
.female-only {
    display: none;
}

.gender-female .female-only {
    display: block;
}

/* Responsive adjustments */
@media (max-width: 350px) {
    .widget-container {
        padding: 12px;
    }

    .widget-title {
        font-size: 16px;
    }

    .widget-result-value {
        font-size: 28px;
    }
}

/* =============================================================================
   STYLE THEMES
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Classic Theme (Default)
   Clean and professional, traditional form styling
   ----------------------------------------------------------------------------- */
.widget-style-classic .widget-container {
    /* Border is applied to iframe, not content */
}

.widget-style-classic .widget-input,
.widget-style-classic .widget-select {
    border-radius: 4px;
}

.widget-style-classic .widget-submit {
    border-radius: 4px;
}

.widget-style-classic .widget-results {
    border-radius: 6px;
}

/* -----------------------------------------------------------------------------
   Modern Theme
   Rounded corners, subtle shadows, contemporary feel
   ----------------------------------------------------------------------------- */
.widget-style-modern .widget-container {
    /* Border/shadow is applied to iframe, not content */
}

.widget-style-modern .widget-header {
    padding-bottom: 8px;
    border-bottom: 2px solid var(--widget-primary);
    margin-bottom: 20px;
}

.widget-style-modern .widget-title {
    font-weight: 700;
    letter-spacing: -0.5px;
}

.widget-style-modern .widget-mode-btn,
.widget-style-modern .widget-gender-btn {
    border-radius: 20px;
    border: 2px solid #e0e0e0;
    background: transparent;
    font-weight: 500;
}

.widget-style-modern .widget-mode-btn.active,
.widget-style-modern .widget-gender-btn.active {
    border-color: var(--widget-primary);
    background: var(--widget-primary);
}

.widget-style-modern .widget-input,
.widget-style-modern .widget-select {
    border-radius: 10px;
    border: 2px solid #e0e0e0;
    padding: 10px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.widget-style-modern .widget-input:focus,
.widget-style-modern .widget-select:focus {
    border-color: var(--widget-primary);
    box-shadow: 0 0 0 4px rgba(66, 139, 202, 0.1);
}

.widget-style-modern .widget-submit {
    border-radius: 10px;
    padding: 14px 24px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(66, 139, 202, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
}

.widget-style-modern .widget-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(66, 139, 202, 0.4);
}

.widget-style-modern .widget-results {
    border-radius: 12px;
    border: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.widget-style-modern .widget-result-category {
    border-radius: 20px;
    font-weight: 600;
}

.widget-style-modern .widget-details-table th {
    border-radius: 6px 6px 0 0;
}

.widget-style-modern .widget-footer {
    padding: 16px 16px 0;
}

/* -----------------------------------------------------------------------------
   Minimal Theme
   Very clean, lots of whitespace, simple lines
   ----------------------------------------------------------------------------- */
.widget-style-minimal .widget-container {
    /* Border is applied to iframe, not content */
    padding: 20px;
}

.widget-style-minimal .widget-header {
    margin-bottom: 24px;
}

.widget-style-minimal .widget-title {
    font-weight: 300;
    font-size: 22px;
    color: #333;
}

.widget-style-minimal .widget-mode-toggle {
    margin-bottom: 24px;
}

.widget-style-minimal .widget-mode-btn,
.widget-style-minimal .widget-gender-btn {
    border: none;
    background: none;
    color: #999;
    font-weight: 400;
    padding: 8px 16px;
    border-bottom: 2px solid transparent;
    border-radius: 0;
}

.widget-style-minimal .widget-mode-btn.active,
.widget-style-minimal .widget-gender-btn.active {
    color: var(--widget-primary);
    background: none;
    border-bottom-color: var(--widget-primary);
}

.widget-style-minimal .widget-form-group {
    margin-bottom: 20px;
}

.widget-style-minimal .widget-label {
    font-weight: 400;
    color: #666;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.widget-style-minimal .widget-input,
.widget-style-minimal .widget-select {
    border: none;
    border-bottom: 1px solid #ddd;
    border-radius: 0;
    padding: 10px 0;
    background: transparent;
}

.widget-style-minimal .widget-input:focus,
.widget-style-minimal .widget-select:focus {
    border-bottom-color: var(--widget-primary);
    box-shadow: none;
}

.widget-style-minimal .widget-submit {
    border-radius: 0;
    background: transparent;
    color: var(--widget-primary);
    border: 1px solid var(--widget-primary);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.widget-style-minimal .widget-submit:hover {
    background: var(--widget-primary);
    color: #fff;
}

.widget-style-minimal .widget-results {
    background: transparent;
    border: none;
    border-top: 1px solid #eee;
    border-radius: 0;
    padding: 20px 0;
}

.widget-style-minimal .widget-result-value {
    font-weight: 300;
    font-size: 48px;
}

.widget-style-minimal .widget-result-category {
    background: transparent;
    border: 1px solid currentColor;
    border-radius: 0;
}

.widget-style-minimal .widget-details-table th {
    background: transparent;
    border-bottom: 2px solid #eee;
}

/* -----------------------------------------------------------------------------
   Clinical Theme
   Medical/clinical feel, professional healthcare appearance
   ----------------------------------------------------------------------------- */
.widget-style-clinical .widget-body {
    background: var(--widget-bg);
}

.widget-style-clinical .widget-container {
    /* Border is applied to iframe, not content */
    background: var(--widget-bg);
}

.widget-style-clinical .widget-header {
    background: linear-gradient(to bottom, var(--widget-primary) 0%, color-mix(in srgb, var(--widget-primary) 70%, black) 100%);
    margin: -16px -16px 16px -16px;
    padding: 16px;
    border-radius: 8px 8px 0 0;
}

.widget-style-clinical .widget-title {
    color: #fff;
    font-weight: 600;
    margin-bottom: 0;
}

.widget-style-clinical .widget-mode-btn,
.widget-style-clinical .widget-gender-btn {
    border: 1px solid var(--widget-primary);
    color: var(--widget-primary);
    background: #fff;
    border-radius: 4px;
    font-weight: 500;
}

.widget-style-clinical .widget-mode-btn.active,
.widget-style-clinical .widget-gender-btn.active {
    background: var(--widget-primary);
    color: #fff;
    border-color: var(--widget-primary);
}

.widget-style-clinical .widget-label {
    color: var(--widget-primary);
    font-weight: 600;
}

.widget-style-clinical .widget-input,
.widget-style-clinical .widget-select {
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f8f8f8;
}

.widget-style-clinical .widget-input:focus,
.widget-style-clinical .widget-select:focus {
    border-color: var(--widget-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

.widget-style-clinical .widget-submit {
    background: linear-gradient(to bottom, var(--widget-primary) 0%, color-mix(in srgb, var(--widget-primary) 70%, black) 100%);
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.widget-style-clinical .widget-submit:hover {
    opacity: 0.9;
}

.widget-style-clinical .widget-results {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.widget-style-clinical .widget-result-value {
    color: var(--widget-primary);
}

.widget-style-clinical .widget-result-category {
    border-radius: 4px;
    font-weight: 600;
}

.widget-style-clinical .widget-details-table th {
    background: #f0f0f0;
    color: var(--widget-primary);
    font-weight: 600;
}

/* -----------------------------------------------------------------------------
   Glass Theme (Glass Morphism)
   Frosted glass effect with blur, modern and visually striking
   ----------------------------------------------------------------------------- */
.widget-style-glass {
    background: linear-gradient(135deg, var(--widget-primary) 0%, var(--widget-gradient-end) 100%);
    color: var(--widget-text);
}

/* Glass needs clip-path for backdrop-filter to respect rounded corners */
.widget-style-glass.widget-rounded {
    clip-path: inset(0 round 12px);
}

.widget-style-glass .widget-container {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 20px;
}

.widget-style-glass .widget-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.widget-style-glass .widget-title {
    color: var(--widget-text);
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.widget-style-glass .widget-mode-btn,
.widget-style-glass .widget-gender-btn {
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: var(--widget-text);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.widget-style-glass .widget-mode-btn:hover,
.widget-style-glass .widget-gender-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.widget-style-glass .widget-mode-btn.active,
.widget-style-glass .widget-gender-btn.active {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.5);
    color: var(--widget-text);
}

.widget-style-glass .widget-label {
    color: var(--widget-text);
    font-weight: 500;
    opacity: 0.9;
}

.widget-style-glass .widget-input,
.widget-style-glass .widget-select {
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: var(--widget-text);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.widget-style-glass .widget-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.widget-style-glass .widget-input:focus,
.widget-style-glass .widget-select:focus {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

.widget-style-glass .widget-unit {
    color: rgba(255, 255, 255, 0.7);
}

.widget-style-glass .widget-submit {
    background: rgba(255, 255, 255, 0.25);
    color: var(--widget-text);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-weight: 500;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: all 0.2s ease;
}

.widget-style-glass .widget-submit:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.5);
}

.widget-style-glass .widget-results {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.widget-style-glass .widget-result-value {
    color: var(--widget-text);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.widget-style-glass .widget-result-label {
    color: var(--widget-text);
    opacity: 0.8;
}

.widget-style-glass .widget-result-category {
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    color: var(--widget-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.widget-style-glass .widget-details-table {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.widget-style-glass .widget-details-table th {
    background: rgba(255, 255, 255, 0.15);
    color: var(--widget-text);
    border-color: rgba(255, 255, 255, 0.1);
}

.widget-style-glass .widget-details-table td {
    color: var(--widget-text);
    border-color: rgba(255, 255, 255, 0.1);
}

.widget-style-glass .widget-details-table tr.current {
    background: rgba(255, 255, 255, 0.2);
}

.widget-style-glass .widget-details-table tr.current td {
    border-color: rgba(255, 255, 255, 0.25);
}

.widget-style-glass .widget-footer a {
    color: var(--widget-text);
    opacity: 0.6;
}

.widget-style-glass .widget-footer a:hover {
    opacity: 1;
}

/* Glass theme error styling */
.widget-style-glass .widget-form-group.has-error .widget-label {
    color: #fff;
    background: rgba(255, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

.widget-style-glass .widget-form-group.has-error .widget-input,
.widget-style-glass .widget-form-group.has-error .widget-select {
    border: 1px solid rgba(255, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.2);
}

.widget-style-glass .widget-form-group.has-error .widget-gender-btn {
    border: 1px solid rgba(255, 0, 0, 0.3);
}

.widget-style-glass .widget-errors {
    background: rgba(255, 0, 0, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 0, 0, 0.3);
    border-radius: 8px;
}

/* Glass theme back button */
.widget-style-glass .widget-back-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--widget-text);
    border-radius: 8px;
}

.widget-style-glass .widget-back-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: var(--widget-text);
}

/* =============================================================================
   REPLACE MODE - Results replace form instead of appearing below
   ============================================================================= */

.widget-replace-mode .widget-form.hidden,
.widget-replace-mode .widget-mode-toggle.hidden {
    display: none;
}

.widget-replace-mode .widget-results {
    display: none;
}

.widget-replace-mode .widget-results.visible {
    display: block;
    margin-top: 0;
}

.widget-back-btn {
    display: block;
    width: 100%;
    padding: 8px 16px;
    margin-bottom: 16px;
    background: transparent;
    border: 1px solid var(--widget-primary);
    color: var(--widget-primary);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    text-align: left;
}

.widget-back-btn:hover {
    background: var(--widget-primary);
    color: #fff;
}

/* =============================================================================
   BORDER STYLES
   Note: Border styles are now applied to the iframe element itself,
   not to the widget content. See generator.php getBorderStyle() function.
   ============================================================================= */

/* =============================================================================
   BMI CHILD SPECIFIC STYLES
   ============================================================================= */

/* Age method toggle link */
.widget-age-toggle {
    font-size: 12px;
    color: var(--widget-primary);
    text-decoration: none;
    white-space: nowrap;
    margin-left: 8px;
}

.widget-age-toggle:hover {
    text-decoration: underline;
}

/* Fraction select for height/weight (children < 5) */
.widget-fraction-select {
    width: 60px !important;
    flex: 0 0 60px !important;
    padding: 8px 6px !important;
    text-align: center;
}
