/* Variables for theming */
:root {
    --color-canvas-light: #ffffff;
    --color-canvas-dark: #1f2937;
    /* gray-900 */
    --color-grid-light: #e5e7eb;
    /* gray-200 */
    --color-grid-dark: #374151;
    /* gray-700 */
    --color-component-light: #000000;
    --color-component-dark: #d1d5db;
    /* gray-300 */
    --color-terminal-label-light: #333333;
    --color-terminal-label-dark: #cccccc;
    --color-overlay-green: #10b981;
    /* green-500 */
    --color-overlay-blue: #3b82f6;
    /* blue-500 */

    /* palette colours – light mode */
    --color-menu-bg: #e5e7eb;
    /* gray-200 */
    --color-menu-border: #d1d5db;
    /* gray-300 */
    --color-menu-header: #d1d5db;
    /* gray-300 */
    --color-menu-icon-bg: #ffffff;
    --color-menu-icon-border: #d1d5db;
    --color-menu-icon-hover-bg: #dbeafe;
    /* blue-100 */
    --color-menu-icon-hover-border: #93c5fd;
    /* blue-300 */
    --color-menu-text: #111827;
    /* gray-900 */
    --color-menu-header-text: #111827;
    /* gray-900 */
    --color-toolbar-bg: #2563eb;
    --color-toolbar-text: #ffffff;
    --color-toolbar-button-bg: #3b82f6;
    --color-toolbar-button-hover-bg: #60a5fa;
    --color-toolbar-button-active-bg: #1e40af;
    --color-toolbar-button-text: #ffffff;
    --color-toolbar-select-bg: #1d4ed8;
    --color-toolbar-select-text: #ffffff;
    --color-secondary-toolbar-bg: #e5e7eb;
    --color-secondary-toolbar-border: #d1d5db;
    --color-secondary-button-bg: #d1d5db;
    --color-secondary-button-hover-bg: #9ca3af;
    --color-secondary-button-active-bg: #2563eb;
    --color-secondary-button-text: #374151;
    --color-secondary-button-active-text: #ffffff;
    --color-filter-bar-bg: #d1d5db;
    --color-filter-bar-border: #d1d5db;
    --color-filter-button-bg: #9ca3af;
    --color-filter-button-hover-bg: #9ca3af;
    --color-filter-button-active-bg: #2563eb;
    --color-filter-button-text: #374151;
    --color-filter-button-active-text: #ffffff;
}

.theme-dark {
    --color-canvas: var(--color-canvas-dark);
    --color-grid: var(--color-grid-dark);
    --color-component: var(--color-component-dark);
    --color-terminal-label: var(--color-terminal-label-dark);

    /* palette colours – dark mode */
    --color-menu-bg: #111827;
    /* gray-900 */
    --color-menu-border: #374151;
    /* gray-700 */
    --color-menu-header: #1f2937;
    /* gray-800 */
    --color-menu-icon-bg: #1f2937;
    --color-menu-icon-border: #4b5563;
    /* gray-600 */
    --color-menu-icon-hover-bg: #1e3a8a;
    /* blue-800 */
    --color-menu-icon-hover-border: #3b82f6;
    /* blue-500 */
    --color-menu-text: #f9fafb;
    /* gray-50 */
    --color-menu-header-text: #f9fafb;
    /* gray-50 */
}

/* Theme Classes */
.theme-light {
    --color-canvas: var(--color-canvas-light);
    --color-grid: var(--color-grid-light);
    --color-component: var(--color-component-light);
    --color-terminal-label: var(--color-terminal-label-light);
}

.theme-dark {
    --color-canvas: var(--color-canvas-dark);
    --color-grid: var(--color-grid-dark);
    --color-component: var(--color-component-dark);
}

/* Apply theme variables to the canvas */
#canvas-container {
    background-color: var(--color-canvas);
}

#main-toolbar {
    background-color: var(--color-toolbar-bg);
    color: var(--color-toolbar-text);
}

/* Style for grid elements (dots, lines). JS will set their color. */
.grid-dot {
    fill: var(--color-grid);
}

.grid-line {
    stroke: var(--color-grid);
    stroke-width: 1;
}

/* Component SVG Styles */
.component-svg * {
    /* Target all paths, lines, etc inside a component */
    stroke: var(--color-component);
    vector-effect: non-scaling-stroke;
    /* Prevents strokes from getting thicker on zoom */
}

/* Additional SVG styling for components in the editor */
.component-svg path,
.component-svg line,
.component-svg rect,
.component-svg polyline,
.component-svg circle {
    stroke: var(--color-component);
    fill: none;
    /* Remove vector-effect: non-scaling-stroke to allow scaling */
}

.component-svg text {
    stroke: none;
    fill: var(--color-component);
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: bold;
    /* Text should not scale with zoom */
    vector-effect: non-scaling-stroke;
}

/* Component-specific base styles (will scale with zoom) */
/* Stroke widths are now defined in the SVG templates */

/* Special thinner elements */
/* Stroke widths are now defined in the SVG templates */

/* Text elements should not scale */
.battery-text,
.motor-text,
.dep-voltage-text {
    stroke: none;
    fill: var(--color-component);
    /* Prevent text from scaling with zoom */
    vector-effect: non-scaling-stroke;
}

.battery-text,
.motor-text {
    font-weight: bold;
}

.dep-voltage-text {
    font-weight: 400;
}

/* Ensure text elements in components have proper styling */
.component-svg text {
    stroke: none;
    fill: var(--color-component);
    font-family: Arial, sans-serif;
    font-size: 14px;
    font-weight: bold;
}

/* Tool Button Styles */
.tool-btn {
    border-radius: 0.25rem;
    background-color: var(--color-toolbar-button-bg);
    color: var(--color-toolbar-button-text);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.tool-btn:focus {
    outline: none;
    box-shadow: none;
}

.settings-btn-padding {
    padding: 0.25rem;
    aspect-ratio: 1.05 / 1;
}

.tool-btn-padding {
    padding: 0.25rem 0.75rem;
    min-width: 50px;
}

.tool-btn:hover {
    background-color: var(--color-toolbar-button-hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
    background-color: var(--color-toolbar-button-active-bg);
}

.toolbar-select {
    background-color: var(--color-toolbar-select-bg);
    color: var(--color-toolbar-select-text);
}

/* Secondary Toolbar Button Styles */
.secondary-btn {
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    background-color: var(--color-secondary-button-bg);
    color: var(--color-secondary-button-text);
    font-weight: 500;
    font-size: 0.875rem;
}

#secondary-toolbar {
    background-color: var(--color-secondary-toolbar-bg);
    border-color: var(--color-secondary-toolbar-border);
}

.secondary-btn:hover {
    background-color: var(--color-secondary-button-hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Component Icon Styles in Left Menu */
.component-icon {
    border: 1px solid #d1d5db;
    /* gray-300 */
    border-radius: 0.25rem;
    background-color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0.5rem;
    margin: 0.25rem;
    min-height: 60px;
}

.component-icon:hover {
    background-color: #dbeafe;
    /* blue-100 */
    border-color: #93c5fd;
    /* blue-300 */
    transform: scale(1.05);
    transition: all 0.1s ease;
}

.icon-preview {
    /* Preview SVGs in the menu */
    pointer-events: none;
    /* Prevent SVG from blocking clicks on the div */
}

.icon-preview * {
    stroke: black;
    /* Force previews to be black */
}

.diode {
    stroke-linecap: round;
    stroke-linejoin: round;
}

.diode-thin {
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Category Headers in Left Menu */
.category-header {
    background-color: #d1d5db;
    /* gray-300 */
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.menu-header {
    background-color: var(--color-menu-header, #d1d5db);
    color: var(--color-menu-header-text, #111827);
}

.component-search-row {
    background-color: var(--color-menu-bg);
    border-color: var(--color-menu-border);
    position: relative;
    z-index: 20;
}

.component-search-shell {
    align-items: center;
    background-color: var(--color-menu-icon-bg);
    border: 1px solid var(--color-menu-icon-border);
    border-radius: 0.5rem;
    display: flex;
    gap: 0.25rem;
    padding: 0.08rem 0.2rem 0.08rem 0.65rem;
}

.component-search-shell:focus-within {
    border-color: var(--color-menu-icon-hover-border);
    box-shadow: 0 0 0 1px var(--color-menu-icon-hover-border);
}

.component-search-input {
    appearance: none;
    background: transparent;
    border: 0;
    box-shadow: none;
    color: var(--color-menu-text);
    flex: 1;
    font-size: 0.875rem;
    min-width: 0;
    outline: none;
    padding: 0.24rem 0;
}

.component-search-input::placeholder {
    color: var(--color-menu-header-text);
    opacity: 0.7;
}

.component-search-input:focus,
.component-search-input:focus-visible {
    border: 0;
    box-shadow: none;
    outline: none;
}

.component-search-clear {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9999px;
    color: #4b5563;
    cursor: pointer;
    display: inline-flex;
    font-size: 1rem;
    height: 1.75rem;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 1.75rem;
}

.component-search-clear:hover,
.component-search-clear:focus-visible {
    background-color: transparent;
    border-color: transparent;
    color: #000000;
    outline: none;
}

/* Filter Button Styles */
.filter-btn {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.25rem;
    flex: 1;
    margin-right: 0.25rem;
    background-color: var(--color-filter-button-bg);
    color: var(--color-filter-button-text);
    display: flex;
    align-items: center;
    justify-content: center;
}

.filter-btn:last-child {
    margin-right: 0;
}

.filter-btn.active {
    background-color: var(--color-filter-button-active-bg);
    color: var(--color-filter-button-active-text);
}

.filter-btn:hover {
    background-color: var(--color-filter-button-hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Styles for the connection dots drawn during wiring */
.connection-dot {
    stroke-width: 0;
    /* Fill color is set dynamically by JS */
}

.connection-dot.green {
    fill: var(--color-overlay-green);
}

.connection-dot.blue {
    fill: var(--color-overlay-blue);
}

/* Style for the ghost component preview */
.ghost-component {
    opacity: 0.4;
    /* More transparent than dashed */
    pointer-events: none;
}

.ghost-component * {
    stroke-dasharray: none;
    /* Remove dashed lines */
    opacity: 0.7;
    /* Slightly transparent elements */
}

/* Style for selected components */
.component-selected {
    outline: 2px solid #3b82f6;
    /* blue-500 */
    outline-offset: 2px;
}

/* Style for labels */
.component-label {
    fill: var(--color-component);
    pointer-events: auto;
}

.component-value {
    fill: var(--color-component);
    pointer-events: auto;
}

/* Component menu theming */
#component-menu {
    background-color: var(--color-menu-bg);
    border-color: var(--color-menu-border);
}

#standard-filter {
    background-color: var(--color-filter-bar-bg);
    border-color: var(--color-filter-bar-border);
}

.category-header {
    background-color: var(--color-menu-header);
}

/* Palette text colours */
#component-menu .p-3.font-bold {
    color: var(--color-menu-header-text);
}

.category-header {
    color: var(--color-menu-header-text);
}

.component-icon {
    background-color: var(--color-menu-icon-bg);
    border-color: var(--color-menu-icon-border);
}

.component-icon:hover {
    background-color: var(--color-menu-icon-hover-bg);
    border-color: var(--color-menu-icon-hover-border);
}

/* Component list spacing */
.component-list {
    padding: 0.5rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.component-search-results {
    display: none;
}

/* Visual feedback for dragging components */
.component-dragging {
    opacity: 0.6;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Update the selection style */
.component-selected {
    outline: 2px solid #3b82f6;
    /* blue-500 */
    outline-offset: 2px;
}

/* Style for temporary wires */
[data-temp-wire] {
    pointer-events: none;
}

/* Styles for new rectangle and arrow paths */
.rectangle-path,
.arrow-path {
    stroke: var(--color-component);
    fill: none;
    vector-effect: non-scaling-stroke;
}

/* Temporary previews for rect/arrow */
[data-temp-rect],
[data-temp-arrow] {
    pointer-events: none;
}


/* Ensure the component menu can handle larger icons */
#component-menu {
    min-width: 12rem;
    /* Slightly wider to accommodate larger icons */
}

.component-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.icon-preview {
    width: 60px;
    height: 60px;
    display: block;
    margin: 0 auto;
}

/* Preserve the original component styling in icons */
.component-icon svg path,
.component-icon svg line,
.component-icon svg rect,
.component-icon svg circle,
.component-icon svg polyline,
.component-icon svg text {
    stroke: var(--color-component);
    fill: none;
    stroke-width: 2;
}

/* Specific styles that might be needed */
.component-icon svg .cap-plus {
    stroke-width: 1;
}

.component-icon svg .led-arrows {
    stroke-width: 1;
}

.component-icon svg .bulb-filament {
    stroke-width: 1;
}

.component-icon svg .motor-text {
    fill: var(--color-component);
    stroke: none;
    font-weight: bold;
}

.component-icon svg .battery-text {
    fill: var(--color-component);
    stroke: none;
    font-weight: bold;
}

.component-icon svg .dep-voltage-text {
    fill: var(--color-component);
    stroke: none;
    font-weight: 400;
}

.ghost-text {
    opacity: 0.6;
    font-size: 14px;
    fill: var(--color-component);
    stroke: var(--color-component);
    stroke-width: 0.5;
    stroke-dasharray: 3 3;
    paint-order: stroke;
}

.free-text-label {
    pointer-events: auto;
    cursor: move;
    fill: var(--color-component);
}

.free-text-label:hover {
    fill: #3b82f6;
}

.label-editor {
    position: absolute;
    z-index: 20;
    background: #ffffff;
    border: 1px solid #111827;
    padding: 8px;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    min-width: 200px;
}

.label-editor-input {
    width: 240px;
    min-height: 40px;
    font-size: 18px;
    color: #000000;
    background: #ffffff;
    border: 1px solid #111827;
    padding: 6px;
    resize: none;
    outline: none;
    font-family: Arial, sans-serif;
    font-weight: bold;
}

.label-editor-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
}

.label-editor-btn {
    background: #f3f4f6;
    border: 1px solid #111827;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 14px;
    cursor: pointer;
}

.label-editor-btn:hover {
    background: #e5e7eb;
}

.label-selected text {
    stroke: #3b82f6;
    stroke-width: 2;
    paint-order: stroke;
}

.label-selected {
    filter: drop-shadow(0 0 3px #3b82f6);
}

.secondary-btn.active {
    background-color: var(--color-secondary-button-active-bg);
    color: var(--color-secondary-button-active-text);
}

#math-mode-btn.active {
    background-color: #4b5563;
    color: white;
}

#led-toolbar {
    margin-left: 12px;
}

/* LED body fill toggling */
.state-off .led-body {
    fill: white;
}

.state-on .led-body {
    fill: #22c55e;
}

.scrollbar-hide {
    overflow-y: auto;

    /* hide scrollbar */
    -ms-overflow-style: none;
    scrollbar-width: none;

    /* remove reserved scrollbar space */
    scrollbar-gutter: auto;
}

.scrollbar-hide::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.palette-request-wrap {
    padding: 0.75rem;
    background-color: var(--color-menu-bg);
    border-top: 1px solid var(--color-menu-border);
}

.palette-request-btn {
    width: 100%;
    justify-content: center;
}

.feedback-modal-panel {
    background-color: #ffffff;
    color: #111827;
}

.theme-dark .feedback-modal-panel {
    background-color: #111827;
    color: #f9fafb;
}

.feedback-modal-subtitle {
    color: #6b7280;
}

.theme-dark .feedback-modal-subtitle {
    color: #9ca3af;
}

.feedback-modal-close {
    font-size: 2rem;
    line-height: 1;
    color: #6b7280;
}

.theme-dark .feedback-modal-close {
    color: #d1d5db;
}

.feedback-input {
    border: 1px solid #d1d5db;
    background-color: #ffffff;
    color: #111827;
}

.theme-dark .feedback-input {
    border-color: #4b5563;
    background-color: #1f2937;
    color: #f9fafb;
}

.feedback-input:focus {
    outline: 2px solid #60a5fa;
    outline-offset: 1px;
}

.feedback-star {
    font-size: 1.75rem;
    line-height: 1;
    color: #cbd5e1;
    transition: color 0.15s ease, transform 0.15s ease;
}

.feedback-star:hover,
.feedback-star:focus-visible {
    color: #f59e0b;
    transform: translateY(-1px);
    outline: none;
}

.feedback-star.active {
    color: #f59e0b;
}

.feedback-input.feedback-invalid {
    border-color: #ef4444;
    outline: 2px solid rgba(239, 68, 68, 0.25);
    outline-offset: 1px;
}

.feedback-submit-loading {
    opacity: 0.7;
    pointer-events: none;
}

.feedback-toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: min(calc(100vw - 2rem), 42rem);
}

.feedback-toast {
    pointer-events: auto;
    width: 100%;
    border: 2px solid;
    border-radius: 1rem;
    box-shadow: 0 16px 40px rgba(17, 24, 39, 0.18);
    padding: 0.95rem 1.1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    transform: translateY(-1.5rem);
    opacity: 0;
    transition: transform 0.28s ease, opacity 0.28s ease;
}

.feedback-toast.feedback-toast-visible {
    transform: translateY(0);
    opacity: 1;
}

.feedback-toast.feedback-toast-exit {
    transform: translateY(-1.5rem);
    opacity: 0;
}

.feedback-toast-success {
    border-color: #15803d;
    background: #f0fdf4;
    color: #14532d;
}

.feedback-toast-error {
    border-color: #b91c1c;
    background: #fef2f2;
    color: #7f1d1d;
}

.feedback-toast-message {
    flex: 1;
    font-size: 0.95rem;
    line-height: 1.45;
}

.feedback-toast-dismiss {
    appearance: none;
    border: 0;
    background: transparent;
    color: currentColor;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    opacity: 0.75;
}

.feedback-toast-dismiss:hover,
.feedback-toast-dismiss:focus-visible {
    opacity: 1;
    outline: none;
}
