/* Global font family for all tools */
* {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Base tool styling */
.tool {
    position: fixed; /* Fixed position so it's always relative to the viewport */
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    padding: 15px;
    max-width: 95vw;
    transition: transform 0.2s ease;
    transform-origin: center;
    cursor: grab;
    user-select: none;    z-index: 1000;
    isolation: isolate;
    opacity: 1;
    background-clip: padding-box;
    box-sizing: border-box;
    /* Ensure tools stay within viewport bounds */
    max-height: 95vh;    overflow: hidden; /* Prevent content from extending beyond tool bounds */
}

/* Solid backdrop to block portal glow */
.tool::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    border-radius: 8px;
    z-index: -1;
}

/* When dragging, temporarily disable text selection inside the tool */
.tool.is-dragging, .tool.is-dragging * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -ms-user-select: none !important;
    -moz-user-select: none !important;
    cursor: grabbing !important;
}

/* Notepad-specific override: allow even larger visual cap */
#notepad-tool.tool {
    max-width: 98vw;
    max-height: 96vh;
}

/* Allow resize handles to be visible outside tool bounds */
.tool:hover {
    overflow: visible;
}

/* Keep resize handles visible during scaling operation */
.tool.corner-scaling {
    overflow: visible;
}

/* Prevent hover overflow behavior in spotlight mode */
.tool.spotlight-mode {
    overflow: hidden !important;
}

.tool.spotlight-mode:hover {
    overflow: hidden !important;
}

/* Add new active tool class */
.tool.active {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    z-index: 1100; /* Higher than non-active tools */
}

/* Tool title bar with multiple elements */
.tool-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--tool-header-bg, #666);
    padding: 5px;
    border-radius: 3px 3px 0 0;
}

.tool-title {
    margin: -15px -15px 10px -15px;
    padding: 10px 15px;
    background-color: #f5f5f5;
    border-radius: 8px 8px 0 0;
    font-weight: bold;
    border-bottom: 1px solid #e0e0e0;
    color: #333;
    cursor: grab;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tool-title-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
}

.tool-title-actions .icon-button {
    width: 24px;
    height: 24px;
    color: #555;
    margin-right: -5px;
}

/* Common button styles */
button {
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s;
    width: auto;
    min-width: 40px;
}

button:hover {
    background-color: #1976d2;
}

/* Button row layout */
.button-row {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    justify-content: center;
    align-items: center;
}

.button-row button {
    flex: 0 1 auto;
    min-width: unset;
}

/* Common tool container */
#tool-container {
    position: relative;
    /* Remove the height constraint that's causing the issue */
    /* height: calc(100vh - 200px); */ 
    overflow: visible; /* Allow tools to overflow */
    pointer-events: none; /* Let tools be draggable through the container */
    margin: 20px auto;
    width: 100%; /* Expand to full width */
    /* Remove max-width constraint */
    /* max-width: 1200px; */
    min-height: 500px; /* Keep minimum height */
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
    z-index: 1; /* Lower z-index than tools */
}

#tool-container .tool {
    pointer-events: auto; /* Re-enable pointer events for tools */
}

/* Draggable functionality */
.draggable {
    position: fixed; /* Use fixed position to be relative to the viewport */
    cursor: grab;
    z-index: 1000; /* Ensure tools are above other content */
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.draggable *:not(textarea):not(input):not(select):not([contenteditable="true"]) {
    user-select: none;
}

/* Ensure form controls remain interactive inside tools */
.tool textarea,
.tool input,
.tool select,
.tool [contenteditable="true"] {
    user-select: text !important;
    -webkit-user-select: text !important;
    cursor: text;
    pointer-events: auto;
    touch-action: auto;
}

