:root {
            /* Light theme (default) */
            --primary-color: #1e40af;
            --primary-light: #3b82f6;
            --secondary-color: #0ea5e9;
            --accent-color: #f97316;
            --light-color: #f1f5f9;
            --success-color: #22c55e;
            --error-color: #ef4444;
            --text-color: #1e293b;
            --text-light: #64748b;
            --card-bg: #ffffff;
            --body-bg: #f8fafc;
            --border-color: #e2e8f0;
            --border-radius: 8px;
            --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
            --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
            --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
            --transition: all 0.3s ease;
            --table-header: #64748b;
            --header-text: white;
            --input-bg: #f8fafc;
            --table-row-even-background-color: #f1f5f9; /* Light gray for even rows */
            --table-row-hover-background-color: #e0f2fe; /* Light blue for hover */

            /* Button specific colors */
            --button-background-color: var(--primary-color);
            --button-text-color: var(--header-text);
            --button-hover-background-color: var(--primary-light);
        }

        [data-theme='dark'] {
            --primary-color: #1a365d; /* Darker blue in dark mode */
            --primary-light: #3b82f6;
            --secondary-color: #38bdf8;
            --accent-color: #fb923c;
            --light-color: #1e293b;
            --success-color: #4ade80;
            --error-color: #f87171;
            --text-color: #f1f5f9;
            --text-light: #cbd5e1;
            --card-bg: #1e293b;
            --body-bg: #0f172a;
            --border-color: #334155;
            --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
            --shadow: 0 4px 6px -1px rgba(0,0,0,0.2), 0 2px 4px -1px rgba(0,0,0,0.1);
            --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -2px rgba(0,0,0,0.2);
            --table-header: #334155;
            --header-text: #f1f5f9;
            --input-bg: #334155;
            --table-row-even-background-color-dark: #1e293b; /* Darker bg for even rows */
            --table-row-hover-background-color-dark: #334155; /* Slightly lighter dark for hover */

            /* Button specific colors for dark theme */
            --button-background-color: var(--primary-color); /* Stays same as root or can be adjusted */
            --button-text-color: var(--header-text); /* Stays same as root or can be adjusted */
            --button-hover-background-color: var(--primary-light); /* Stays same as root or can be adjusted */
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            font-size: 13px;
            line-height: 1.5;
            color: var(--text-color);
            background-color: var(--body-bg); /* Ensure body uses the variable */
            padding: 0;
            margin: 0;
            transition: background-color 0.3s ease, color 0.3s ease;
        }

        .page-wrapper {
            max-width: 1440px;
            margin: 0 auto;
            padding: 16px;
        }

        .header-container {
            background-color: var(--primary-color);
            color: var(--header-text);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            padding: 10px;
            margin-bottom: 16px;
            display: flex;
            /* justify-content: space-between; /* Original */
            align-items: center;
            gap: 15px; /* New for spacing with toggle */
        }

        .safety-list {
            /* flex: 1; /* Original */
            flex-grow: 1; /* New to allow toggle and machine name to take space */
        }

        .safety-list h3 {
            font-size: 15px;
            margin-bottom: 4px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .safety-list h3 svg {
            width: 16px;
            height: 16px;
            /* No !important needed if this is the only rule for this specific SVG */
        }

        .safety-list ul {
            list-style-type: none;
            padding: 0;
        }

        .safety-list ul li {
            margin-bottom: 1px;
            position: relative;
            padding-left: 18px;
            display: flex;
            align-items: center;
            line-height: 1.1;
            font-size: 12px;
        }

        .safety-list ul li:before {
            content: "✓";
            position: absolute;
            left: 0;
            color: var(--secondary-color);
            font-weight: bold;
        }
        
        /* New styles for theme toggle in header */
        .theme-toggle-header-wrapper {
            /* No specific flex properties needed if it's just holding the button */
        }

        .header-container .theme-toggle-btn {
            width: 36px; 
            height: 36px;
            background-color: rgba(255, 255, 255, 0.1); 
            color: var(--header-text);
            margin: 0; 
            padding: 0; 
            /* Inherits general .theme-toggle-btn styles for icon, hover etc. */
        }

        .header-container .theme-toggle-btn:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .header-container .theme-toggle-btn .theme-icon {
            width: 20px; 
            height: 20px;
            fill: var(--header-text);
        }
        /* End new styles for theme toggle in header */


        .machine-name {
            font-size: 22px;
            font-weight: 800;
            text-align: center; /* Original */
            /* flex: 0 0 200px; /* Original */
            color: white;
            line-height: 1.2;
            background-color: rgba(255, 255, 255, 0.1);
            padding: 12px; /* Original */
            border-radius: var(--border-radius);
            letter-spacing: -0.03em;
            /* margin-left: auto; /* Added to push to right if safety-list and toggle don't fill */
        }

        .machine-name.clickable {
            cursor: pointer;
            text-decoration: underline;
            text-decoration-style: dotted;
            transition: color 0.2s ease-in-out;
        }

        .machine-name.clickable:hover {
            color: var(--secondary-color);
        }

        .container {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 16px;
        }

        @media (max-width: 1024px) {
            .container {
                grid-template-columns: 1fr;
            }
        }

        .card {
            background-color: var(--card-bg);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
            /* overflow: hidden; */ /* Removed to allow tooltips to overflow */
            transition: var(--transition);
        }

        .card:hover {
            box-shadow: var(--shadow-lg);
        }

        .card-header {
            background-color: var(--primary-color);
            color: var(--header-text);
            padding: 8px 16px;
            font-weight: 600;
            font-size: 15px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .card-header svg {
            width: 16px;
            height: 16px;
        }

        .card-body {
            padding: 14px;
            position: relative;
        }

        .section-title {
            color: #333333;
            background-color: #fef9c3; /* Light yellow */
            padding: 4px 10px;
            margin-top: 0;
            margin-bottom: 8px;
            font-size: 14px;
            font-weight: 600;
            border-radius: 4px;
            border-bottom: 3px solid #ca8a04; /* Darker yellow */
        }

        .section-title:not(:first-of-type) {
            margin-top: 16px;
        }

        [data-theme='dark'] .section-title {
            color: #f1f5f9;
            background-color: #4d3800; /* Dark amber */
            border-bottom: 4px solid #eab308; /* Yellow */
        }

        .form-section {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 8px;
        }

        .form-group {
            margin-bottom: 8px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 3px;
            font-weight: 500;
            color: var(--text-color);
            font-size: 12px;
        }

        .input-wrapper {
            position: relative;
            display: flex;
            align-items: center;
        }

        .form-group input {
            width: 100%;
            padding: 6px 30px 6px 8px;
            font-size: 13px;
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius);
            transition: var(--transition);
            background-color: var(--input-bg);
            color: var(--text-color);
        }

        .form-group input:focus {
            outline: none;
            border-color: var(--primary-light);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
            background-color: white;
        }

        .form-group input.invalid {
            border-color: var(--error-color);
            background-color: rgba(239, 68, 68, 0.05);
        }

        .input-unit {
            position: absolute;
            right: 8px;
            color: var(--text-light);
            font-size: 12px;
            pointer-events: none;
        }

        .error {
            color: var(--error-color);
            font-size: 11px;
            margin-top: 1px;
            font-weight: 500;
        }

        /* Style for select dropdowns to match text inputs */
        select.input-field {
            width: 100%;
            padding: 6px 8px;
            font-size: 13px;
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius);
            transition: var(--transition);
            background-color: var(--input-bg);
            color: var(--text-color);
            -webkit-appearance: none; /* Removes default browser styling */
            -moz-appearance: none;
            appearance: none;
            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
            background-position: right 0.5rem center;
            background-repeat: no-repeat;
            background-size: 1.5em 1.5em;
            padding-right: 2.5rem; /* Make space for the arrow */
        }

        select.input-field:focus {
            outline: none;
            border-color: var(--primary-light);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
            background-color: white;
        }

        .info-icon-container {
            position: relative;
            display: inline-block;
        }

        .info-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 14px;
            height: 14px;
            background-color: var(--primary-light);
            color: white;
            border-radius: 50%;
            font-size: 10px;
            font-weight: bold;
            margin-left: 4px;
            cursor: pointer;
            transition: var(--transition);
        }

        .info-icon:hover {
            background-color: var(--primary-color);
            transform: scale(1.1);
        }

        .tooltip {
            visibility: hidden;
            width: 220px;
            background-color: #334155;
            color: white;
            text-align: left;
            border-radius: var(--border-radius);
            padding: 8px 10px;
            position: absolute;
            z-index: 999; /* Increased z-index */
            top: calc(100% + 5px);
            left: 0;
            opacity: 0;
            transition: opacity 0.3s, visibility 0.3s;
            box-shadow: var(--shadow);
            font-weight: normal;
            font-size: 11px;
            line-height: 1.4;
        }

        .tooltip:after {
            content: "";
            position: absolute;
            bottom: 100%;
            left: 20px;
            border-width: 6px;
            border-style: solid;
            border-color: transparent transparent #334155 transparent;
        }

        .info-icon-container:hover .tooltip {
            visibility: visible;
            opacity: 1;
        }

        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-top: 10px;
        }

        .checkbox-group input[type="checkbox"] {
            width: 18px;
            height: 18px;
            accent-color: var(--primary-color);
        }

        #bevel-table {
            width: 100%;
            border-collapse: collapse;
            margin: 16px 0;
            border-radius: var(--border-radius);
            overflow: hidden;
            box-shadow: var(--shadow-sm);
            font-size: 12px;
        }

        #bevel-table caption {
            font-weight: 600;
            text-align: center;
            margin-bottom: 6px;
            color: var(--text-color);
            font-size: 13px;
        }

        #bevel-table th,
        #bevel-table td {
            border: 1px solid var(--border-color);
            padding: 8px 4px;
            text-align: center;
        }

        #bevel-table th {
            background-color: var(--table-header);
            color: white;
            font-weight: 600;
            font-size: 11px;
            letter-spacing: 0.03em;
        }

        #bevel-table tr:nth-child(even) {
            background-color: var(--light-color);
        }

        #bevel-table tr:hover {
            background-color: var(--primary-color);
            color: var(--header-text);
        }

        #max-insert-speed {
            font-weight: 600;
            color: var(--error-color);
            margin-top: 10px;
            text-align: center;
            font-size: 13px;
        }

        .material-removal {
            background-color: var(--light-color);
            padding: 10px 14px;
            border-radius: var(--border-radius);
            margin-top: 14px;
            border-left: 4px solid var(--primary-color);
            font-size: 12px;
        }

        .material-removal strong {
            color: var(--primary-color);
            font-weight: 600;
            font-size: 13px;
        }

        /* Fix material removal text color in dark mode */
        [data-theme='dark'] .material-removal {
            background-color: #2d3748;
        }

        [data-theme='dark'] .material-removal strong {
            color: #f6e05e; /* Bright yellow for visibility */
        }

        .image-section {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        /* Image styling with dark mode improvements */
        .image-section img {
            width: 80%;
            max-width: 450px;
            height: auto;
            margin-bottom: 30px;
            transition: var(--transition);
        }

        .image-section img:hover {
            transform: scale(1.05);
        }

        /* SVG filter for dark mode */
        [data-theme='dark'] .image-section img {
            filter: invert(1) brightness(1.7);
        }

        .highlight-red {
            background-color: rgba(239, 68, 68, 0.1);
            color: var(--error-color);
            padding: 10px 12px;
            border-radius: var(--border-radius);
            border-left: 4px solid var(--error-color);
            margin: 14px 0;
            font-weight: 500;
            font-size: 12px;
        }

        .highlight-green {
            background-color: rgba(34, 197, 94, 0.1);
            color: var(--success-color);
            padding: 10px 12px;
            border-radius: var(--border-radius);
            border-left: 4px solid var(--success-color);
            margin: 14px 0;
            font-weight: 500;
            font-size: 12px;
        }

        .divider {
            border: 0;
            height: 1px;
            background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0));
            margin: 25px 0;
        }

        /* Theme toggle button styling */
        /* .theme-toggle-center class removed as button moved to header */

        .theme-toggle-btn { /* General styles for the button, now also used by header version */
            background: none;
            border: none;
            cursor: pointer;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: var(--primary-light);
            color: white;
            transition: all 0.3s ease;
        }

        .theme-toggle-btn:hover {
            transform: scale(1.1);
            background-color: var(--primary-color);
        }

        .theme-toggle-btn:focus {
            outline: none;
        }

        .theme-icon { /* General styles for icons inside the button */
            width: 24px;
            height: 24px;
            fill: white;
            transition: all 0.3s ease;
        }

        .dark-icon {
            display: none;
        }

        [data-theme='dark'] .light-icon {
            display: none;
        }

        [data-theme='dark'] .dark-icon {
            display: block;
        }

        /* Chip styling */
        .chip {
            display: inline-flex;
            align-items: center;
            border-radius: 12px;
            padding: 2px 8px;
            font-size: 12px;
            margin: 0 2px;
        }

        .chip-red {
            background-color: rgba(239, 68, 68, 0.1);
            color: var(--error-color);
            border: 1px solid var(--error-color);
        }

        .chip-gray {
            background-color: var(--light-color);
            color: var(--text-color);
            border: 1px solid var(--border-color);
        }

        [data-theme='dark'] .chip-gray {
            background-color: rgba(100, 116, 139, 0.2);
            border-color: var(--border-color);
        }

        .chip strong {
            font-weight: 600;
        }
        
        /* Style for the mode selector */
        .mode-selector {
            display: none; /* Hidden by default, shown only for CNC #1 */
            background-color: var(--light-color);
            padding: 10px 14px;
            border-radius: var(--border-radius);
            margin-bottom: 14px;
            border-left: 4px solid var(--secondary-color);
        }
        [data-theme='dark'] .mode-selector {
             background-color: #2d3748; /* Darker background in dark mode */
        }
        .mode-selector strong {
             margin-right: 10px;
        }
        .mode-selector label {
            margin-right: 15px;
            font-weight: 500;
            cursor: pointer;
        }
        .mode-selector input[type="radio"] {
            margin-right: 5px;
            accent-color: var(--primary-color);
            vertical-align: middle; /* Align radio with text */
        }

        /* Hide sections by default */
        #beveling-fields, #testing-fields, #material-removal-info, #bevel-table {
            display: none;
        }

        /* General Button Styling (moved from viewer.html inline) */
        .button, button {
            padding: 8px 15px;
            border: none;
            border-radius: 5px; /* Can use var(--border-radius) if consistent */
            background-color: var(--button-background-color);
            color: var(--button-text-color);
            cursor: pointer;
            font-size: 0.9rem;
            transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
            text-decoration: none; /* For anchor tags styled as buttons */
            display: inline-block; /* For anchor tags */
            font-weight: 500; /* Added for better appearance */
        }

        .button:hover, button:hover {
            background-color: var(--button-hover-background-color);
            /* Optional: change text color on hover if needed */
            /* color: var(--some-other-color-for-hover-text); */
        }

        /* Ensure visited links styled as buttons maintain their appearance */
        a.button:visited {
            color: var(--button-text-color);
            background-color: var(--button-background-color); /* Explicitly set background */
        }
        a.button:visited:hover {
            background-color: var(--button-hover-background-color); /* Ensure hover on visited is also correct */
        }

        /* --- Viewer Page Specific Styles --- */

        /* Table Styles (for viewer.html) */
        #history-table-container table { /* Target table within the container */
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            box-shadow: var(--shadow); /* Use existing shadow variable */
            background-color: var(--card-bg); /* Use card background */
            border-radius: var(--border-radius); /* Match card radius */
            overflow: hidden; /* Ensures radius applies to borders */
        }

        #history-table-container th,
        #history-table-container td {
            border: 1px solid var(--border-color);
            padding: 10px 12px;
            text-align: left;
            font-size: 0.9rem;
            color: var(--text-color); /* Ensure text color adapts */
        }

        #history-table-container th {
            background-color: var(--table-header); /* Use variable */
            color: var(--header-text); /* Use variable */
            font-weight: 600;
        }

        #history-table-container tr:nth-child(even) {
            background-color: var(--table-row-even-background-color, var(--light-color)); /* Use specific or fallback */
        }
         /* Define dark mode specific even row color if needed */
         [data-theme='dark'] #history-table-container tr:nth-child(even) {
             background-color: var(--table-row-even-background-color-dark, #1a202c); /* Example dark mode even row */
         }

        /* Remove hover effect */
        /*
        #history-table-container tr:hover {
            background-color: var(--table-row-hover-background-color);
            color: var(--header-text);
        }
        [data-theme='dark'] #history-table-container tr:hover {
             background-color: var(--table-row-hover-background-color-dark);
             color: var(--text-color);
         }
        */

        /* Modal Styles (for viewer.html) */
        .modal {
            display: none; /* Hidden by default */
            position: fixed; /* Stay in place */
            z-index: 1000; /* Sit on top */
            left: 0;
            top: 0;
            width: 100%; /* Full width */
            height: 100%; /* Full height */
            overflow: auto; /* Enable scroll if needed */
            background-color: rgba(0,0,0,0.6); /* Semi-transparent background */
        }
        [data-theme='dark'] .modal {
             background-color: rgba(200, 200, 200, 0.2); /* Lighter overlay for dark mode */
        }

        .modal-content {
            background-color: var(--card-bg); /* Use card background variable */
            color: var(--text-color); /* Use text color variable */
            margin: 10% auto; /* 10% from the top and centered */
            padding: 25px;
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius);
            width: 60%;
            max-width: 500px;
            box-shadow: var(--shadow-lg); /* Use shadow variable */
            position: relative;
        }

        .modal-header {
            padding-bottom: 10px;
            border-bottom: 1px solid var(--border-color);
            margin-bottom: 15px;
            font-size: 1.2em;
            font-weight: bold;
            color: var(--primary-color); /* Use primary color for header */
        }
         [data-theme='dark'] .modal-header {
             color: var(--secondary-color); /* Brighter color for dark mode header */
         }


        .modal-body {
             max-height: 60vh; /* Limit height and allow scrolling */
             overflow-y: auto;
        }

        .modal-body dl {
             margin: 0;
             padding: 0;
        }
         .modal-body dt {
             font-weight: bold;
             color: var(--text-light); /* Use text-light variable */
             margin-top: 8px;
             font-size: 0.9em;
         }
         .modal-body dd {
             margin-left: 15px;
             margin-bottom: 8px;
             font-size: 1em;
             word-wrap: break-word;
             color: var(--text-color); /* Ensure main text color */
         }

        .close-button {
            color: var(--text-light); /* Use text-light variable */
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 28px;
            font-weight: bold;
            line-height: 1;
            transition: color 0.2s ease;
        }
        .close-button:hover,
        .close-button:focus {
            color: var(--error-color); /* Use error color for hover */
            text-decoration: none;
            cursor: pointer;
        }

        /* New style for version info footer */
        .version-info-footer {
            font-size: 0.8rem; 
            color: var(--text-light); 
            text-align: center;
            padding: 0 0 10px 0; /* Removed top padding, kept bottom */
            margin-top: 0; /* Removed top margin */
            opacity: 0.7;
        }