/**
 * Social Image Creator - v19.2.37
 * Fixed: Text elements now use content-based width with center origin
 */

.sic-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000001;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* WordPress admin bar adjustment */
.admin-bar .sic-modal {
    top: 32px;
    height: calc(100vh - 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar .sic-modal {
        top: 46px;
        height: calc(100vh - 46px);
    }
}

.sic-modal.active {
    display: flex;
}

.sic-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
}

/* Modal container - fills available space */
.sic-modal-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: #111;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.sic-modal-open {
    overflow: hidden;
}

/* Header */
.sic-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.sic-modal-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.sic-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sic-undo-redo {
    display: flex;
    gap: 4px;
}

.sic-undo-btn,
.sic-redo-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #333;
    border: 1px solid #666;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
}

.sic-undo-btn:hover:not(:disabled),
.sic-redo-btn:hover:not(:disabled) {
    background: #81b000;
    border-color: #81b000;
    color: #fff;
}

.sic-undo-btn:disabled,
.sic-redo-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #888;
    border-color: #555;
    background: #2a2a2a;
}

/* Zoom Controls */
.sic-zoom-controls {
    display: flex;
    gap: 2px;
    margin-right: 8px;
}

.sic-zoom-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #333;
    border: 1px solid #555;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

.sic-zoom-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.sic-zoom-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.sic-zoom-btn.sic-zoom-fit {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 0;
}

.sic-zoom-btn:hover {
    background: #81b000;
    border-color: #81b000;
}

.sic-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    color: #ccc;
    cursor: pointer;
    border-radius: 4px;
}

.sic-modal-close:hover {
    background: #333;
    color: #fff;
}

/* Main Body */
.sic-modal-body {
    display: grid;
    grid-template-columns: 280px 1fr 180px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left Controls */
.sic-controls {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #1a1a1a;
    border-right: 1px solid #333;
}

/* Main Tabs (Visual / Text) */
.sic-main-tabs {
    display: flex;
    background: #111;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.sic-main-tab {
    flex: 1;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sic-main-tab:hover {
    color: #ccc;
    background: #1a1a1a;
}

.sic-main-tab.active {
    color: #81b000;
    background: #1a1a1a;
    border-bottom: 2px solid #81b000;
}

/* Panels */
.sic-panel {
    display: none;
    flex-direction: column;
    overflow-y: auto;
    flex: 1;
}

.sic-panel.active {
    display: flex;
}

/* Inline overlay in position controls */
.sic-overlay-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #333;
    flex-wrap: wrap;
}

.sic-overlay-inline input[type="color"] {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.sic-overlay-inline input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    flex-shrink: 0;
}

.sic-overlay-inline label {
    font-size: 12px;
    color: #aaa;
    cursor: pointer;
    flex-shrink: 0;
}

.sic-overlay-inline input[type="range"] {
    flex: 1;
    min-width: 60px;
    height: 4px;
    cursor: pointer;
}

.sic-overlay-inline #sic-opacity-value {
    font-size: 11px;
    color: #888;
    min-width: 32px;
    text-align: right;
}

/* Position & Overlay Row Layout */
.sic-position-overlay-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.sic-position-overlay-row .sic-position-grid {
    flex-shrink: 0;
}

.sic-overlay-controls-vertical {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.sic-overlay-color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sic-overlay-color-row input[type="color"] {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.sic-overlay-color-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.sic-overlay-color-row label {
    font-size: 13px;
    color: #ccc;
    cursor: pointer;
}

.sic-overlay-slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sic-overlay-slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    cursor: pointer;
}

.sic-overlay-slider-row span {
    font-size: 12px;
    color: #888;
    min-width: 36px;
    text-align: right;
}

.sic-section {
    padding: 12px 14px;
    border-bottom: 1px solid #2a2a2a;
    width: 100%;
    box-sizing: border-box;
}

.sic-section-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* Text Block Editor */
.sic-text-block {
    background: #222;
    border-radius: 6px;
    overflow: hidden;
    width: 100%;
}

.sic-text-block input,
.sic-text-block textarea {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    font-family: inherit;
    background: #2a2a2a;
    border: none;
    color: #fff;
    resize: none;
    box-sizing: border-box;
}

.sic-text-block input::selection,
.sic-text-block textarea::selection {
    background: #81b000;
    color: #fff;
}

.sic-text-block input:focus,
.sic-text-block textarea:focus {
    outline: none;
    background: #333;
    color: #fff !important;
}

.sic-text-block input::placeholder,
.sic-text-block textarea::placeholder {
    color: #666;
}

.sic-text-block textarea {
    min-height: 150px;
}

/* Headline input - constrained width, larger text */
#sic-headline-input {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 18px;
    font-weight: bold;
    padding: 12px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* All text inputs constrained to container */
.sic-text-block input[type="text"] {
    max-width: 100%;
    box-sizing: border-box;
}

.sic-text-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #1a1a1a;
    border-top: 1px solid #333;
    flex-wrap: wrap;
}

.sic-size-btns {
    display: flex;
    align-items: center;
    gap: 2px;
}

.sic-size-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

.sic-size-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.sic-size-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.sic-size-btn:hover {
    background: #444;
}

.sic-size-display {
    min-width: 32px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    border-top: 1px solid #444;
    border-bottom: 1px solid #444;
    color: #888;
    font-size: 11px;
}

.sic-align-btns {
    display: flex;
    gap: 2px;
}

.sic-align-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    border: 1px solid #444;
    color: #888;
    cursor: pointer;
    font-size: 12px;
}

.sic-align-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.sic-align-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.sic-align-btn:hover {
    background: #333;
    color: #fff;
}

.sic-align-btn.active {
    background: #81b000;
    border-color: #81b000;
    color: #fff;
}

.sic-text-toolbar input[type="color"] {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    background: none;
    flex-shrink: 0;
}

.sic-style-btns {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.sic-style-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #888;
    cursor: pointer;
    font-size: 13px;
}

.sic-style-btn:hover {
    background: #333;
    color: #fff;
}

.sic-style-btn.active {
    background: #81b000;
    border-color: #81b000;
    color: #fff;
}

/* Logo Picker */
.sic-logo-picker {
    background: #222;
    border-radius: 6px;
    padding: 12px;
}

.sic-logo-preview {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    border-radius: 4px;
    margin-bottom: 10px;
    overflow: hidden;
}

.sic-logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sic-logo-placeholder {
    color: #555;
    font-size: 12px;
}

.sic-logo-actions {
    display: flex;
    gap: 8px;
}

.sic-logo-actions .sic-btn {
    flex: 1;
}
    color: #fff;
}

.sic-full-width {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
}

/* Image Picker */
.sic-image-picker {
    background: #222;
    border-radius: 6px;
    overflow: hidden;
}

.sic-image-tabs {
    display: flex;
    background: #1a1a1a;
}

.sic-image-tab {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    background: transparent;
    border: none;
    color: #ccc;
    cursor: pointer;
    transition: all 0.15s;
}

.sic-image-tab:hover {
    color: #ccc;
}

.sic-image-tab.active {
    background: #222;
    color: #fff;
}

.sic-tab-content {
    display: none;
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.sic-tab-content.active {
    display: block;
}

.sic-image-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.sic-image-thumb {
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    background: #333;
    transition: all 0.15s;
}

.sic-image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sic-image-thumb:hover,
.sic-image-thumb.selected {
    border-color: #81b000;
}

.sic-image-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    background: #1a1a1a;
}

.sic-loading, .sic-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 13px;
}

/* Image Position Controls */
.sic-position-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #2a2a2a;
}

.sic-position-label {
    font-size: 12px;
    color: #ccc;
}

.sic-position-grid {
    display: grid;
    grid-template-columns: repeat(3, 28px);
    gap: 2px;
}

.sic-pos-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 3px;
    color: #ccc;
    cursor: pointer;
    font-size: 10px;
}

.sic-pos-btn:hover {
    background: #333;
    color: #fff;
}

.sic-pos-btn.active {
    background: #81b000;
    border-color: #81b000;
    color: #fff;
}

/* Content Inputs */
.sic-content-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sic-input-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sic-input-row label {
    font-size: 13px;
    font-weight: 500;
    color: #ccc;
}

#sic-stat-input {
    padding: 10px 12px;
    font-size: 20px;
    font-weight: 700;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #ffffff;
    text-align: center;
    width: 120px;
}

#sic-text-input {
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #fff;
    resize: vertical;
    min-height: 80px;
    line-height: 1.4;
}

#sic-stat-input:focus,
#sic-text-input:focus {
    outline: none;
    border-color: #81b000;
}

/* Font Controls */
.sic-font-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

#sic-font-family {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #fff;
}

#sic-font-size {
    width: 70px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #fff;
}

.sic-font-style-btns {
    display: flex;
    gap: 4px;
}

.sic-font-style-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #ccc;
    transition: all 0.15s;
}

.sic-font-style-btn:hover {
    background: #333;
}

.sic-font-style-btn.active {
    background: #81b000;
    border-color: #81b000;
    color: #fff;
}

/* Color Controls */
.sic-color-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.sic-color-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sic-color-item label {
    font-size: 13px;
    color: #ccc;
}

.sic-color-item input[type="color"] {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 2px solid #3a3a3a;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

.sic-overlay-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sic-overlay-row input[type="color"] {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    border: 2px solid #3a3a3a;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.sic-overlay-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.sic-overlay-row label {
    font-size: 13px;
    color: #ccc;
    cursor: pointer;
}

.sic-overlay-row input[type="range"] {
    flex: 1;
    height: 6px;
    cursor: pointer;
}

#sic-opacity-value {
    font-size: 13px;
    color: #ccc;
    min-width: 36px;
    text-align: right;
}

/* Center: Main Canvas */
.sic-main-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: #0a0a0a;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.sic-canvas-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
    overflow: visible; /* Allow transformed content to be visible */
}

.sic-canvas-frame {
    background: #222;
    border-radius: 4px;
    padding: 4px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

#sic-canvas {
    display: block;
    border-radius: 2px;
}

.sic-main-info {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
}

.sic-platform-label {
    font-size: 14px;
    font-weight: 600;
    color: #81b000;
}

#sic-dimensions {
    font-size: 12px;
    color: #666;
    font-family: 'SF Mono', Monaco, monospace;
}

/* Right: Format Previews - CORRECT ASPECT RATIOS */
.sic-format-previews {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #1a1a1a;
    border-left: 1px solid #333;
    padding: 10px;
    gap: 10px;
}

.sic-format-card {
    background: #222;
    border-radius: 6px;
    padding: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.15s;
    position: relative;
}

.sic-format-card:hover {
    background: #2a2a2a;
}

.sic-format-card.active {
    border-color: #81b000;
}

.sic-format-card.locked {
    border-color: #f59e0b;
}

.sic-format-card.locked.active {
    border-color: #81b000;
    box-shadow: 0 0 0 2px #f59e0b;
}

.sic-format-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.sic-lock-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 3px;
    opacity: 0.5;
    transition: all 0.15s;
}

.sic-lock-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.1);
}

.sic-lock-btn.locked {
    opacity: 1;
    color: #f59e0b;
}

.sic-format-name {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

.sic-format-size {
    font-size: 10px;
    color: #666;
    font-family: monospace;
    display: block;
    text-align: center;
    margin-top: 4px;
}

/* Preview wrappers with CORRECT aspect ratios */
.sic-format-preview {
    background: #111;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Each format gets its correct aspect ratio */
.sic-format-card[data-platform="linkedin"] .sic-format-preview {
    aspect-ratio: 1200 / 627;
}
.sic-format-card[data-platform="facebook"] .sic-format-preview {
    aspect-ratio: 1200 / 630;
}
.sic-format-card[data-platform="twitter"] .sic-format-preview {
    aspect-ratio: 1200 / 675;
}
.sic-format-card[data-platform="instagram_square"] .sic-format-preview {
    aspect-ratio: 1 / 1;
}
.sic-format-card[data-platform="instagram_portrait"] .sic-format-preview {
    aspect-ratio: 1080 / 1350;
}
.sic-format-card[data-platform="instagram_story"] .sic-format-preview {
    aspect-ratio: 1080 / 1920;
    max-height: 120px;
}

.sic-format-preview canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Footer */
.sic-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #1a1a1a;
    border-top: 1px solid #333;
    flex-shrink: 0;
}

.sic-footer-left {
    display: flex;
    gap: 12px;
    align-items: center;
}

.sic-footer-right {
    display: flex;
    gap: 10px;
}

.sic-save-indicator {
    font-size: 12px;
    color: #666;
}

.sic-save-indicator.saved {
    color: #81b000;
}

/* Buttons */
.sic-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.sic-btn-primary {
    background: #81b000;
    border: none;
    color: #fff;
}

.sic-btn-primary:hover {
    background: #6a9300;
}

.sic-btn-secondary {
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    color: #ccc;
}

.sic-btn-secondary:hover {
    background: #333;
    color: #fff;
}

.sic-btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.sic-btn-close {
    background: #333;
    border: 1px solid #555;
    color: #fff;
}

.sic-btn-close:hover {
    background: #444;
    border-color: #666;
}

.sic-image-actions .sic-btn {
    flex: 1;
    justify-content: center;
}

/* External URL */
.sic-external-url-form {
    padding: 4px;
}

.sic-external-url-form input {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    color: #fff;
    margin-bottom: 8px;
    box-sizing: border-box;
}

.sic-external-url-form input:focus {
    outline: none;
    border-color: #81b000;
}

/* Responsive */
@media (max-width: 1100px) {
    .sic-modal-body {
        grid-template-columns: 280px 1fr;
    }
    .sic-format-previews {
        display: none;
    }
}

@media (max-width: 700px) {
    .sic-modal-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    .sic-controls {
        max-height: 45vh;
        border-right: none;
        border-bottom: 1px solid #333;
    }
}
