/* ============================================
   BUTTON COMPONENTS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary Button */
.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    background-origin: border-box;
    color: white;
    box-shadow: 0 2px 8px rgba(155, 135, 245, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(155, 135, 245, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

/* Secondary Button */
.btn-secondary {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.btn-secondary:active:not(:disabled) {
    background: var(--color-surface-active);
}

/* Icon Button */
.btn-icon {
    padding: var(--space-sm);
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text-secondary);
    min-width: 36px;
    min-height: 36px;
}

.btn-icon:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
    color: var(--color-text-primary);
}

.btn-icon svg {
    display: block;
}

/* Full Width Button */
.btn-full {
    width: 100%;
}

/* Shape Options Sub-Menu */
.shape-options-panel {
    display: none;
    /* toggled via JS */
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    padding: var(--space-xs);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    animation: slideDown var(--transition-fast);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.shape-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs);
    aspect-ratio: 1;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.shape-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
    border-color: var(--color-border-hover);
}

.shape-btn.active {
    background: rgba(155, 135, 245, 0.2);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* ============================================
   INPUT COMPONENTS
   ============================================ */

.input,
.select,
.textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-primary);
    font-size: 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    transition: all var(--transition-fast);
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
    box-shadow: 0 0 0 3px rgba(155, 135, 245, 0.1);
}

.input::placeholder {
    color: var(--color-text-tertiary);
}

/* Number Input */
.input-number {
    appearance: textfield;
    -moz-appearance: textfield;
}

.input-number::-webkit-outer-spin-button,
.input-number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Color Input */
.input-color {
    height: 36px;
    padding: var(--space-xs);
    cursor: pointer;
}

.input-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.input-color::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

/* Select Dropdown */
.select {
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 4L6 8L10 4' stroke='rgba(255,255,255,0.4)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-md) center;
    padding-right: var(--space-xl);
}

/* Dropdown options - make text dark for visibility */
.select option {
    background-color: #ffffff;
    color: #1a1a24;
}

/* Custom Font Select Dropdown */
.custom-font-select {
    position: relative;
    width: 100%;
    outline: none;
}

.custom-font-select-trigger {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: all var(--transition-fast);
}

.custom-font-select-trigger:hover,
.custom-font-select.open .custom-font-select-trigger {
    border-color: var(--color-primary);
    background: var(--color-surface-hover);
}

.custom-font-select-trigger::after {
    content: '';
    width: 12px;
    height: 12px;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 4L6 8L10 4' stroke='rgba(255,255,255,0.4)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    transition: transform var(--transition-fast);
}

.custom-font-select.open .custom-font-select-trigger::after {
    transform: rotate(180deg);
}

.custom-font-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #ffffff;
    /* White background for font previews like native select */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1050;
    /* Ensure it stays above canvas elements and panels */
    max-height: 250px;
    overflow-y: auto;
    display: none;
    flex-direction: column;
}

.custom-font-select.open .custom-font-options {
    display: flex;
}

.custom-font-group-label {
    padding: var(--space-xs) var(--space-sm);
    font-size: 11px;
    font-weight: 700;
    color: #666;
    background: #f0f0f0;
    text-transform: uppercase;
}

.custom-font-option {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    color: #1a1a24;
    font-size: 16px;
    /* Slightly larger for easier preview reading */
    transition: background var(--transition-fast);
}

.custom-font-option:hover {
    background-color: var(--color-primary);
    color: #ffffff;
}

.custom-font-option.selected {
    background-color: rgba(155, 135, 245, 0.1);
    color: var(--color-primary);
    font-weight: 600;
}

/* Textarea */
.textarea {
    min-height: 80px;
    resize: vertical;
}

/* ============================================
   FORM GROUPS
   ============================================ */

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.form-row {
    display: flex;
    gap: var(--space-sm);
}

.form-row .form-group {
    flex: 1;
}

/* ============================================
   RANGE SLIDER
   ============================================ */

.input-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--color-surface);
    border-radius: var(--radius-full);
    outline: none;
}

.input-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.input-range::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(155, 135, 245, 0.5);
}

.input-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--color-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.input-range::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 8px rgba(155, 135, 245, 0.5);
}

/* ============================================
   MODAL
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn var(--transition-medium);
}

.modal {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp var(--transition-medium);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text-primary);
}

.modal-close {
    padding: var(--space-xs);
    background: transparent;
    border: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
}

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

/* ============================================
   TOOLTIP
   ============================================ */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-bg-elevated);
    backdrop-filter: blur(20px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--color-text-primary);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    z-index: 1000;
}

[data-tooltip]:hover::before {
    opacity: 1;
}

/* ============================================
   CARD
   ============================================ */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    transition: all var(--transition-fast);
}

.card:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.card-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--color-text-primary);
}

.card-description {
    font-size: 13px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

/* ============================================
   DIVIDER
   ============================================ */

.divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-md) 0;
}

/* ============================================
   BADGE
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.badge-primary {
    background: rgba(155, 135, 245, 0.2);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.badge-success {
    background: rgba(72, 187, 120, 0.2);
    color: var(--color-success);
    border-color: var(--color-success);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-primary {
    color: var(--color-text-primary);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.text-tertiary {
    color: var(--color-text-tertiary);
}

.mt-xs {
    margin-top: var(--space-xs);
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-xs {
    margin-bottom: var(--space-xs);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

.font-display {
    font-family: var(--font-display);
}

.font-weight-medium {
    font-weight: 500;
}

.font-weight-semibold {
    font-weight: 600;
}

.font-weight-bold {
    font-weight: 700;
}