    .widget-container {
        width: 100%;
        max-width: 80rem;
        background-color: #ffffff;
        border-radius: 1rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        padding: 1.5rem;
        display: flex;
        flex-direction: column;
        position: relative;
        margin: 0 /* Ensures it stays centered */
    }

    /* --- Mobile Adjustments --- */
    @media (max-width: 640px) {
        body {
            padding: 0.5rem;
        }
        .widget-container {
            padding: 0.75rem;
        }
    }

    #chart-main {
        width: 100%;
        flex-grow: 1; /* Tells the chart to eat up all remaining empty space */
        min-height: 400px; /* A safety fallback so the chart never gets squished flat */
    }

    @media (max-height: 500px) and (orientation: landscape) {
        #chart-main {
            height: 85vh;
        }
    }

    /* Adjust chart height when the chart container is fullscreen */
    #chart-container:fullscreen #chart-main,
    .pseudo-fullscreen #chart-main {
        height: 80vh; /* Leave room for legend and layout */
    }

    @media (max-width: 640px) and (orientation: portrait) {
        #chart-container:fullscreen #chart-main,
        .pseudo-fullscreen #chart-main {
            height: 65vh;
        }
    }

    .header-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1rem;
    }
    .title-container {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-grow: 1;
        min-width: 0; /* Allows container to shrink if needed */
    }
    #chart-title {
        font-size: 1.5rem;
        font-weight: bold;
        text-align: center;
        border: none;
        width: 100%; /* Use full available width */
        min-width: 0; /* Prevents input from forcing container width */
        background-color: transparent;
        padding: 0.25rem;
        flex-grow: 1;
    }
    #chart-title:focus {
        outline: none;
        box-shadow: 0 2px 0 0 #3b82f6;
    }
    #chart-title:disabled {
        color: #111827;
        background-color: transparent;
    }
    #edit-title-btn {
        border: none;
        background: none;
        cursor: pointer;
        font-size: 1.2rem;
        opacity: 0.5;
        transition: opacity 0.2s;
        margin-left: 8px;
        flex-shrink: 0; /* Prevents icon from squishing */
    }
    #edit-title-btn:hover { opacity: 1; }
    .chart-subtitle {
        text-align: center;
        font-size: 0.9rem;
        color: #6b7280;
        margin-top: 0.25rem;
        margin-bottom: 0.5rem;
    }

    /* --- Description Section --- */
    .description-container {
        display: flex;
        align-items: flex-start; /* Align to top in case of multiple lines */
        justify-content: flex-start;
        width: 100%;
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
        padding: 0;
        box-sizing: border-box;
    }
    #description {
        font-family: inherit; /* Textareas default to monospace, this overrides it */
        font-size: 0.85rem;
        color: #6b7280;
        text-align: left;
        border: none;
        width: 100%;
        background-color: transparent;
        padding: 0.25rem;
        flex-grow: 1;
        resize: none; /* Prevents the user from dragging the corner */
        overflow: hidden; /* Hides scrollbars */
        line-height: 1.4; /* Ensures consistent row height */
    }
    #description:focus {
        outline: none;
        box-shadow: 0 2px 0 0 #3b82f6;
    }
    #description:disabled {
        color: #4b5563;
        background-color: transparent;
    }
    #description::placeholder {
        color: #9ca3af;
        font-style: italic;
    }
    #edit-description-btn {
        border: none;
        background: none;
        cursor: pointer;
        font-size: 1rem;
        opacity: 0.5;
        transition: opacity 0.2s;
        margin-left: 8px;
        margin-top: 4px; /* Align icon with the first line of text */
        flex-shrink: 0;
    }
    #edit-description-btn:hover { opacity: 1; }

    /* --- Controls Section --- */
    .controls-container {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    .control-group {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }
    .control-group.disabled {
        color: #9ca3af;
        cursor: not-allowed;
    }

    @media (min-width: 640px) {
        .control-group {
            margin-top: 0;
            margin-left: 1rem;
        }
    }

    /* --- Buttons and Inputs --- */
    .control-btn, .settings-input {
        padding: 0.25rem 0.75rem;
        font-size: 0.875rem;
        font-weight: 500;
        border-radius: 0.375rem;
        border: 1px solid #d1d5db;
        background-color: #f9fafb;
        color: #1f2937;
        transition: background-color 0.2s, color 0.2s;
        cursor: pointer;
    }
    .control-btn:hover { background-color: #f3f4f6; }
    .control-btn.active {
        background-color: #3b82f6;
        color: #ffffff;
        border-color: #3b82f6;
    }
    /* Visual state for unsaved changes on the Save Chart button */
    .control-btn.btn-dirty {
        background-color: #3b82f6;
        color: #ffffff;
        border-color: #3b82f6;
    }
    .control-btn:disabled { opacity: 0.5; cursor: not-allowed; }

    .settings-input:focus {
        outline: 2px solid transparent;
        outline-offset: 2px;
        box-shadow: 0 0 0 2px #3b82f6;
    }

    /* --- Custom Legend & Settings --- */
    #custom-legend {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: flex-start;
        gap: 0.5rem 1rem;
        padding: 0.5rem;
        padding-right: 3.5rem;
        box-sizing: border-box;
    }
    .legend-item-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        transition: background-color 0.2s;
        border-radius: 0.5rem;
    }
    .legend-item {
        display: flex;
        align-items: center;
        padding: 0.25rem;
        border-radius: 0.375rem;
        user-select: none;
        -webkit-user-select: none;
    }
    .legend-color-swatch {
        width: 12px;
        height: 12px;
        margin-right: 8px;
        border-radius: 2px;
        flex-shrink: 0;
    }
    .legend-name-toggle { font-weight: 500; cursor: pointer; }
    .legend-name-toggle.deselected {
        color: #9ca3af;
        text-decoration: line-through;
    }
    .legend-name-toggle.disabled-toggle {
        cursor: default;
        pointer-events: none;
    }
    .settings-btn, .close-settings-btn {
        border: none;
        background: none;
        padding: 0 0 0 8px;
        font-size: 1.5em;
        line-height: 1;
        cursor: pointer;
        opacity: 0.6;
        transition: opacity 0.2s;
        vertical-align: middle;
    }
    .settings-btn { color: #6b7280; }
    .close-settings-btn { color: #9ca3af; font-size: 1.2em; padding: 0 0 0 12px; }
    .settings-btn:hover, .close-settings-btn:hover { opacity: 1; }
    
    .series-settings-panel {
        display: none;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem;
        margin-top: 0.25rem;
        background-color: #f9fafb;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        position: relative;
    }
    .series-settings-panel.active {
        display: flex;
    }
    .settings-group {
        display: flex;
        flex-direction: column;
    }
    .line-specific-settings {
        display: contents;
    }
    .settings-group label {
        font-size: 0.75rem;
        color: #6b7280;
        margin-bottom: 0.125rem;
    }
    input[type="color"] {
        -webkit-appearance: none;
        width: 32px;
        height: 32px;
        border: none;
        padding: 0;
        background: none;
    }
    input[type="color"]::-webkit-color-swatch-wrapper {
        padding: 0;
    }
    input[type="color"]::-webkit-color-swatch {
        border: 1px solid #d1d5db;
        border-radius: 0.375rem;
    }

    /* --- Drag and Drop Styles --- */
    .legend-item[draggable="true"] {
        cursor: grab;
        touch-action: none;
    }
    .legend-item-wrapper.dragging {
        opacity: 0.4;
    }
    .legend-item-wrapper.drag-over {
        background-color: #eef2ff;
        border-radius: 0.5rem;
    }
    .legend-ghost {
        position: absolute;
        pointer-events: none;
        z-index: 1001;
        opacity: 0.8;
        background-color: #e0e7ff;
        border-radius: 0.5rem;
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    }

    /* --- Zoom Bar Label --- */
    .zoom-bar-label {
        text-align: center;
        font-size: 0.8rem;
        color: #6b7280;
        margin-top: 0.5rem;
    }
    
    /* --- Fullscreen Position --- */
    #fullscreen-btn, #exit-fullscreen-btn {
        position: absolute;
        top: 0.5rem;
        right: 0.5rem;
        z-index: 50;
        padding: 0.5rem;
        line-height: 1;
    }
    
    /* --- Fullscreen Fallback (Safari/iOS) --- */
    .pseudo-fullscreen {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 9999 !important;
        background: #ffffff !important;
        padding: 1rem !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    #chart-container:fullscreen { 
        background-color: #ffffff; 
        padding: 1.5rem;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }
    
    /* --- Loading Overlay --- */
    #loading-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(255, 255, 255, 0.8);
        z-index: 1000;
        display: none;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border-radius: 1rem;
    }
    .spinner {
        border: 5px solid #f3f3f3;
        border-top: 5px solid #3b82f6;
        border-radius: 50%;
        width: 50px;
        height: 50px;
        animation: spin 1s linear infinite;
        margin-bottom: 1rem;
    }
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
