/* General body and font styling */
:root {
    --brand-color: #4338ca;
    --brand-color-hover: #312e81;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --white: #fff;
    --red: #ef4444;
/* Cell fill colors for table preview */
.table-cell-fill-lightgray { background-color: #e5e7eb; }
.table-cell-fill-lightblue { background-color: #dbeafe; }
.table-cell-fill-lightgreen { background-color: #dcfce7; }
.table-cell-fill-lightyellow { background-color: #fef9c3; }
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* Prevent scrolling */
    display: grid;
    grid-template-rows: 1fr auto;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "main sidebar"
        "footer sidebar";
    height: 100vh;
    background-color: var(--gray-100);
}

#canvas-container {
    grid-area: main;
    position: relative;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #ebebeb;
    /* Add space around the paper */
    /*padding-bottom: 1rem;
    padding-left: 12rem;
    padding-right: 12rem;*/
    box-sizing: border-box;
    /* Ensure padding is included in size calculation */
}

/* Active tool button styling */
.active-tool {
    background-color: var(--brand-color) !important;
    color: var(--white) !important;
}

/* Full-screen canvas */
#myCanvas {
    background-color: rgb(255, 255, 255);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    border: 2px solid #cbd5e0;
    /* Added a subtle border */
    padding: 0.15rem;
    */
    /* REMOVED: Margin is now handled by container padding */
    touch-action: none;
    /* Prevent default touch actions like scroll/zoom */
}

/* Floating top menu */
#topBar {
    position: fixed;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background-color: rgba(13, 13, 13, 0.8);
    backdrop-filter: blur(8px);
}

/* Dropdown container */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    z-index: 1;
    border-radius: 0.5rem;
    padding: 0.5rem;
    margin-top: 0.5rem;
}

.dropdown-content button {
    width: 100%;
    margin-bottom: 0.25rem;
}

/* Dropup variant: opens above the trigger button (for bottom-bar buttons) */
.dropdown-content.dropup {
    bottom: 100%;
    top: auto;
    margin-top: 0;
    margin-bottom: 0.5rem;
    max-height: 40vh;
    overflow-y: auto;
}

/* Show All Dropdown: 7 columns x up to 2 rows with icons */
.show-all-dropdown {
    width: 1150px;
    padding: 0.5rem;
    margin-top: 0.5rem;
    max-height: 85vh;
    overflow-x: auto;
    overflow-y: auto;
}

.show-all-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.8rem;
}

.show-all-col {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: center;
    padding: 0 0.2rem;
}

.show-all-col:not(:last-child) {
    border-right: 1px solid #e5e7eb;
}

.show-all-tools-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.15rem;
    width: 100%;
}

.show-all-tools-row .show-all-tool {
    width: 100%;
    height: 24px;
    font-size: 0.6rem;
    padding: 0.05rem 0.1rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.show-all-tools-row .show-all-tool svg {
    width: 1rem;
    height: 1rem;
}

.show-all-tools-row .show-all-tool:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.show-all-tools-row .show-all-tool:active {
    background: #e5e7eb;
}

.show-all-header {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    padding-bottom: 0.15rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.15rem;
    text-align: center;
    line-height: 1.2;
    width: 100%;
}

.show-all-header svg {
    display: block;
    width: 0.85rem;
    height: 0.85rem;
    margin: 0 auto 0.1rem;
    color: #9ca3af;
}

/* Reduced column width for Dimension, Constraint, Modifiers */
.col-reduced {
    width: 150px;
    min-width: 150px;
    max-width: 150px;
}

.col-reduced .show-all-tools-row {
    grid-template-columns: repeat(4, 1fr);
}

/* Grid layout for tool dropdowns */
.dropdown-content.dropdown-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.25rem;
    padding: 0.25rem;
    width: auto;
    min-width: auto;
}

.dropdown-content.dropdown-grid button {
    width: 2.25rem;
    /* w-9 (36px) */
    height: 2.25rem;
    /* h-9 (36px) */
    margin-bottom: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ellipseTool span {
    display: inline-block;
    transform: scaleX(1.5);
}

/* Custom context menu styles for right-click actions */
#customContextMenu {
    position: absolute;
    background-color: var(--white);
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 0.5rem;
    z-index: 1000;
    display: none;
}

.context-menu-item {
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-800);
}

.context-menu-item:hover {
    background-color: var(--gray-100);
}

.context-menu-item.danger {
    color: var(--red);
}

.context-menu-item.danger:hover {
    background-color: #fee2e2;
}

/* Generic Modal Styling */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    background-color: var(--white);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: none;
    flex-direction: column;
    width: 280px;
}

/* Specific styling for Animation Modal to be wider and scrollable */
#animationModal {
    width: 550px !important;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-large {
    width: 600px;
    /* A wider width for larger modals */
}

/* Title Block modal: it holds a lot of controls, so let it scroll. */
#titleBlockModal {
    max-height: 88vh;
    max-width: 95vw;
    overflow-y: auto;
}

/* Column width / row height / cell editors inside the title block modal */
#titleBlockColWidthEditor input,
#titleBlockRowHeightEditor input,
#titleBlockCellEditor input,
#titleBlockCellEditor select {
    margin-bottom: 0;
    padding: 0.25rem 0.375rem;
    font-size: 0.75rem;
}

.tb-cell {
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    padding: 0.3rem;
    background-color: #ffffff;
    min-width: 0;
}

.tb-cell-covered {
    background-color: #f3f4f6;
}

.tb-cell-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    margin-bottom: 0.25rem;
}

.tb-cell-label {
    font-size: 0.625rem;
    font-weight: 600;
    color: #6b7280;
    white-space: nowrap;
}

.tb-cell-badge {
    font-size: 0.5625rem;
    font-weight: 600;
    color: #2563eb;
    background-color: #dbeafe;
    border-radius: 0.25rem;
    padding: 0 0.2rem;
}

.tb-merge-btn {
    width: 1.15rem;
    height: 1.15rem;
    line-height: 1;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    font-size: 0.6875rem;
    color: #4b5563;
    background-color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.tb-merge-btn:hover:not(:disabled) {
    background-color: #e5e7eb;
}

.tb-merge-btn.active {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.tb-merge-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tb-cell-mergednote {
    font-size: 0.625rem;
    color: #9ca3af;
    text-align: center;
    padding: 0.4rem 0;
}


.modal-content input,
.modal-content select {
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    width: 100%;
    margin-bottom: 1rem;
    font-size: 1rem;
    outline: none;
}

.input-field {
    padding: 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: 0.375rem;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.875rem;
    outline: none;
}


.modal-content label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.button-group {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

.modal-button {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 600;
    transition: background-color 200ms;
}

.modal-button.ok {
    background-color: var(--brand-color);
    color: var(--white);
    border: none;
}

.modal-button.ok:hover {
    background-color: var(--brand-color-hover);
}

.modal-button.cancel {
    background-color: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.modal-button.cancel:hover {
    background-color: var(--gray-200);
}

/* ------------------------------------------------------------------ */
/* Text tool modal: it holds a lot of controls, so keep it wide & flat */
/* ------------------------------------------------------------------ */
#textToolModal {
    width: 560px;
    max-width: 96vw;
    padding: 0.85rem 1rem 0.8rem;
}

#textToolModal h3 {
    margin-bottom: 0.55rem;
    font-size: 1.05rem;
    line-height: 1.2;
}

/* Replace the generic modal-content rhythm (1rem input margins + Tailwind's space-y-3)
   with a much tighter one so the panel never grows tall. */
#textToolModal .modal-content > * + * {
    margin-top: 0.45rem;
}

#textToolModal .modal-content label,
#textToolModal .tt-field-label {
    display: block;
    margin-bottom: 0.1rem;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.15;
    color: #4b5563;
}

/* The leader checkbox label must stay horizontal and compact (it carries Tailwind's flex helpers). */
#textToolModal .modal-content label.flex {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
}

/* The leader checkbox must keep its natural size: the generic `.modal-content input`
   rule sets `width: 100%`, which stretches the box across the row and pushes the label
   text far to the right. */
#textToolModal .modal-content label.flex > input[type="checkbox"] {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin: 0;
    padding: 0;
    border-radius: 0.25rem;
}

/* Cancel the Tailwind ml-2 on the leader label so the box and its text sit close together. */
#textToolModal .modal-content label.flex > span {
    margin-left: 0;
    font-size: 0.8rem;
}

/* Inline control groups (e.g. the Wrap checkbox + width input). */
#textToolModal .tt-inline {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
}

#textToolModal .tt-inline > input[type="checkbox"] {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    margin: 0;
    padding: 0;
    border-radius: 0.25rem;
}

#textToolModal .tt-inline > div,
#textToolModal .tt-inline > input[type="number"] {
    flex: 1 1 auto;
    min-width: 0;
}

#textToolModal .tt-inline > div > input[type="number"] {
    width: 100%;
}

/* Keep the leader sub-options as tight as the rest of the panel. */
#textToolModal #textLeaderOptions {
    gap: 0.45rem;
    margin-top: 0.35rem;
}

#textToolModal #textLeaderHint {
    margin-top: 0.3rem;
}

#textToolModal .modal-content input,
#textToolModal .modal-content select,
#textToolModal .modal-content textarea {
    margin-bottom: 0;
    padding: 0.28rem 0.42rem;
    font-size: 0.8rem;
    line-height: 1.25;
    border-radius: 0.3rem;
}

#textToolModal .modal-content textarea {
    margin-top: 0;
    min-height: 2.1rem;
    resize: vertical;
}

#textToolModal .modal-content input[type="color"] {
    height: 1.75rem;
    padding: 0.1rem;
}

/* The two compact option rows created in src/extra.js */
#textToolModal .tt-row {
    display: grid;
    gap: 0.45rem;
    align-items: end;
}

#textToolModal .tt-row-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

#textToolModal .tt-row-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

#textToolModal .tt-btn-group {
    display: flex;
    gap: 0.2rem;
}

#textToolModal .tt-btn-group button {
    flex: 1 1 auto;
    padding: 0.28rem 0.3rem;
    font-size: 0.8rem;
    line-height: 1.1;
}

#textToolModal .button-group {
    margin-top: 0.6rem;
}

#textToolModal .modal-button {
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
}

/* Shape Inspector Panel */
#shapeInspectorPanel {
    width: 300px;
    /* More compact width */
    z-index: 2000;
    cursor: move;
    padding: 0;
    /* Remove default modal padding to have more control */
}

#inspectorHeader {
    padding: 0.5rem 0.75rem;
    /* Compact padding */
    font-size: 0.875rem;
    /* Smaller font */
    background-color: var(--gray-100);
    border-top-left-radius: 0.75rem;
    border-top-right-radius: 0.75rem;
    font-weight: 600;
    border-bottom: 1px solid var(--gray-300);
}

#shapeInspectorPanel .modal-content {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* MODIFICATIONS FOR COMPACT PANELS */
.inspector-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#shapeInspectorPanel .modal-content label {
    margin-bottom: 0;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-700);
}

#shapeInspectorPanel .modal-content input,
#shapeInspectorPanel .modal-content select {
    width: 160px;
    padding: 0.25rem;
    font-size: 0.75rem;
    margin-bottom: 0;
}

#shapeInspectorPanel .modal-content input[type="color"] {
    padding: 0;
    height: 24px;
}

#shapeInspectorPanel .button-group {
    margin-top: 0.5rem;
    padding: 0 0.75rem 0.75rem;
    /* Add padding here instead of the main modal div */
}

#shapeInspectorPanel .modal-button {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

/* Edit Dimension Modal COMPACT STYLES */
#editDimensionModal {
    width: 240px;
    padding: 1rem;
    cursor: move;
}

#editDimensionModal h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

#editDimensionModal .modal-content label {
    font-size: 0.875rem;
}

#editDimensionModal .modal-content input {
    padding: 0.375rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

#editDimensionModal .button-group {
    margin-top: 0.5rem;
}

#editDimensionModal .modal-button {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* =============================================== */
/* NEW: Toggle Switch Styles                       */
/* =============================================== */

/* Base styles for the toggle switch container */
.toggle-switch,
.toggle-switch-sm {
    position: relative;
    display: inline-block;
    width: 44px;
    /* w-11 */
    height: 24px;
    /* h-6 */
}

/* Smaller version for compact areas */
.toggle-switch-sm {
    width: 36px;
    /* w-9 */
    height: 20px;
    /* h-5 */
}

/* Hide the default HTML checkbox */
.toggle-switch input,
.toggle-switch-sm input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* The slider (the track the toggle moves on) */
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #d1d5db;
    /* gray-300 */
    transition: .4s;
    border-radius: 9999px;
    /* rounded-full */
}

/* The sliding knob */
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    /* h-5 */
    width: 20px;
    /* w-5 */
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.toggle-switch-sm .slider:before {
    height: 16px;
    /* h-4 */
    width: 16px;
    /* w-4 */
}

/* Change background color when checked */
input:checked+.slider {
    background-color: #4f46e5;
    /* indigo-600 */
}

/* Move the knob when checked */
input:checked+.slider:before {
    transform: translateX(20px);
}

.toggle-switch-sm input:checked+.slider:before {
    transform: translateX(16px);
}

/* =============================================== */
/* NEW: Area Measurement popup (#areaPopup)         */
/* =============================================== */
/* The popup shell is styled with Tailwind utilities in index.html; the rows below are
   built in src/area.js with these class names, so they need plain CSS. */

.area-popup-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
}

.area-popup-row:hover {
    background-color: #fef3c7;
    /* amber-100 */
}

/* Numbered badge that matches the badge drawn on the canvas. */
.area-popup-index {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    background-color: #fef3c7;
    /* amber-100 */
    color: #b45309;
    /* amber-700 */
    font-size: 0.6875rem;
    font-weight: 600;
}

.area-popup-value {
    flex: 1 1 auto;
    text-align: right;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    color: #374151;
    /* gray-700 */
}

.area-popup-remove {
    flex: 0 0 auto;
    padding: 0 0.125rem;
    border: none;
    background: none;
    color: #9ca3af;
    /* gray-400 */
    font-size: 0.6875rem;
    line-height: 1;
    cursor: pointer;
}

.area-popup-remove:hover {
    color: #dc2626;
    /* red-600 */
}

/* Shown while nothing has been committed yet, so the popup never looks broken. */
.area-popup-empty {
    padding: 0.375rem 0.25rem;
    text-align: center;
    font-size: 0.6875rem;
    color: #9ca3af;
    /* gray-400 */
}

/* =============================================== */
/* Area Measurement toggle (#bottomAreaBtn)         */
/* =============================================== */
/* Declared in index.html and parked by renderSheetBar() in the footer tool cluster, right
   after the Real Line Thickness toggle, so it inherits the footer button chrome from its
   Tailwind classes and nothing floats over the sheet tabs. */

/* Armed state of the Area toggle, so it is obvious that canvas clicks now measure. */
#bottomAreaBtn.area-toggle-active {
    background-color: #f59e0b;
    /* amber-500 */
    color: #ffffff;
}

#bottomAreaBtn.area-toggle-active:hover {
    background-color: #d97706;
    /* amber-600 */
}

/* The measurement popup must out-rank the bottom/top bars (1000) so it stays readable when
   dragged over them, while still sitting under the modals (2000). Tailwind's z-40 alone
   would let it slide underneath. */
#areaPopup {
    z-index: 1200;
}