/* ===== RESET & VARIABLES ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-light: #EEF2FF;
    --primary-surface: #F8F7FF;
    --success: #22C55E;
    --success-hover: #16A34A;
    --success-light: #F0FDF4;
    --warning: #F59E0B;
    --warning-light: #FFFBEB;
    --error: #EF4444;
    --error-light: #FEF2F2;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --bg-primary: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-input: #F8FAFC;
    --border-color: #E2E8F0;
    --border-hover: #C7D2FE;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.10);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 1.5rem;
}

.app {
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 3rem);
    display: flex;
    flex-direction: column;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 0 1rem 0;
    flex-shrink: 0;
}

.app-header .logo {
    width: 40px;
    height: 40px;
    color: var(--primary);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.app-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 400;
}

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0 1rem 0;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.toolbar-link {
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.toolbar-link:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.toolbar-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== MAIN LAYOUT ===== */
.main-layout {
    display: flex;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* ===== LEFT: EDITOR SECTION ===== */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* ===== DROP ZONE ===== */
.drop-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-surface);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.drop-zone-content {
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.drop-icon {
    width: 40px;
    height: 40px;
    color: var(--primary);
}

.drop-zone h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.browse-link {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    pointer-events: all;
    transition: var(--transition);
}

.browse-link:hover {
    color: var(--primary-hover);
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
}

.loading-overlay:not(.is-hidden) {
    opacity: 1;
    pointer-events: auto;
}

.loading-overlay .loading-content {
    text-align: center;
    color: white;
    max-width: 500px;
    transform: scale(0.95);
    transition: transform 0.4s ease;
}

.loading-overlay:not(.is-hidden) .loading-content {
    transform: scale(1);
}

.loading-overlay .loading-content .spinner {
    display: inline-block;
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

.loading-overlay .loading-content h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-overlay .loading-content p {
    font-size: 1rem;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.loading-overlay .loading-content .loading-sub {
    font-size: 0.85rem;
    opacity: 0.5;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== ORIGINAL INFO ===== */
.original-info {
    display: flex;
    gap: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    align-items: center;
    flex-wrap: wrap;
}

.original-info .original-thumb {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}

.original-info .original-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.original-info .original-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.05rem 0.75rem;
    flex: 1;
}

.original-info .original-meta strong {
    color: var(--text-primary);
}

/* ===== EDITOR CONTAINER ===== */
.editor-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.editor-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.platform-summary {
    font-size: 0.85rem;
    font-weight: 500;
}

.summary-badge {
    display: inline-block;
    padding: 0.15rem 0.8rem;
    border-radius: 12px;
    font-weight: 600;
}

.summary-badge.ok {
    background: var(--success-light);
    color: var(--success);
}

.summary-badge.warning {
    background: var(--warning-light);
    color: var(--warning);
}

.summary-badge.error {
    background: var(--error-light);
    color: var(--error);
}

/* ===== EDITOR FORM ===== */
.editor-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--bg-input);
    transition: var(--transition);
    width: 100%;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: flex;
    gap: 1rem;
}

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

/* ===== FORM ACTIONS ===== */
.form-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding-top: 0.25rem;
}

/* ===== PLATFORM PREVIEWS ===== */
.platform-previews {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.platform-card {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

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

.platform-card .platform-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.platform-card .platform-name {
    font-weight: 600;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.platform-card .platform-status {
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
}

.platform-card .platform-status.ok {
    background: var(--success-light);
    color: var(--success);
}

.platform-card .platform-status.warning {
    background: var(--warning-light);
    color: var(--warning);
}

.platform-card .platform-status.error {
    background: var(--error-light);
    color: var(--error);
}

.platform-card .preview-content {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    max-height: 350px;
    overflow-y: auto;
    flex: 1;
}

.platform-card .preview-content .preview-headline {
    font-weight: 600;
    font-size: 0.9rem;
}

.platform-card .preview-content .preview-body {
    font-size: 0.85rem;
    white-space: pre-wrap;
    word-break: break-word;
    margin-top: 0.25rem;
}

.platform-card .preview-content .preview-image {
    margin-top: 0.5rem;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
    cursor: pointer;
}

.platform-card .preview-content .preview-image img {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: contain;
    display: block;
}

.platform-card .preview-content .preview-hashtags {
    color: var(--primary);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

.platform-card .preview-content .preview-cta {
    display: inline-block;
    margin-top: 0.4rem;
    padding: 0.2rem 0.8rem;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.platform-card .preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
    padding: 0.25rem 0;
    border-top: 1px solid var(--border-color);
}

.platform-card .platform-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.platform-card .platform-actions .btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.platform-card .platform-actions .btn-copy {
    background: var(--primary-light);
    color: var(--primary);
}

.platform-card .platform-actions .btn-copy:hover {
    background: var(--primary);
    color: white;
}

.platform-card .platform-actions .btn-download {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.platform-card .platform-actions .btn-download:hover {
    background: var(--border-color);
}

.platform-card .platform-actions .btn-copy-image {
    background: var(--success-light);
    color: var(--success);
}

.platform-card .platform-actions .btn-copy-image:hover {
    background: var(--success);
    color: white;
}

/* ===== EDITOR FOOTER ===== */
.editor-footer {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    letter-spacing: 0.01em;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.badge svg,
.btn svg {
    flex-shrink: 0;
    height: 1.2rem;
    width: auto;
}

.badge.badge-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.30);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.25);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.30);
}

.btn-small {
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
}

.btn-group {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.btn-group span {
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 3rem;
    text-align: center;
}

/* ===== TEMPLATE BUTTONS ===== */
.template-btn {
    padding: 0.15rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    font-size: 0.7rem;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.template-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== RIGHT: CONTROLS ===== */
.controls-section {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-group label {
    font-weight: 500;
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.platform-tag {
    background: var(--bg-input);
    padding: 0.1rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
}

/* ===== IMAGE INFO PANEL ===== */
#imageInfoPanel {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    line-height: 1.6;
}

#imageInfoPanel strong {
    color: var(--text-primary);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateX(-50%) translateY(20px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.modal-overlay:not(.is-hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay:not(.is-hidden) .modal-content {
    transform: scale(1);
}

.modal-image {
    max-width: 90vw;
    max-height: 90vh;
}

.modal-image .modal-body {
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.modal-image .modal-body img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    display: block;
}

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

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: var(--transition);
    line-height: 1;
    padding: 0 0.25rem;
}

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

.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
}

/* ===== IMAGE EDITOR MODAL ===== */
.modal-editor {
    max-width: 1200px;
    max-height: 90vh;
}

.modal-editor .editor-body {
    padding: 1rem;
    overflow: hidden;
}

.editor-layout {
    display: flex;
    gap: 1.5rem;
    height: 100%;
    min-height: 500px;
}

.editor-canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
    min-height: 400px;
    max-height: 600px;
    cursor: grab;
    width: 100%;
    height: 100%;
}

.canvas-wrapper:active {
    cursor: grabbing;
}

.canvas-wrapper canvas {
    display: block;
    image-rendering: auto;
    position: relative;
}

.editor-status {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-align: center;
    padding: 0.25rem 0;
}

.editor-controls {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    max-height: 600px;
    overflow-y: auto;
}

.editor-controls .control-group {
    gap: 0.25rem;
}

.editor-controls .control-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.dimension-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.dimension-row input {
    width: 80px;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--bg-card);
}

.dimension-row span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== FOOTER ===== */
.app-footer {
    text-align: center;
    padding: 1.5rem 0 0.5rem 0;
    color: var(--text-tertiary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1.5rem;
    flex-shrink: 0;
}

.app-footer .row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.app-footer svg {
    height: 1.5rem;
    width: auto;
    flex-shrink: 0;
}

.app-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: var(--transition);
}

.app-footer a:hover {
    color: var(--primary);
}

/* ===== UTILITIES ===== */
.is-hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .controls-section {
        width: 260px;
    }
    .editor-controls {
        width: 240px;
    }
}

@media (max-width: 820px) {
    .app {
        min-height: auto;
    }

    .main-layout {
        flex-direction: column;
        gap: 1rem;
    }

    .controls-section {
        width: 100%;
    }

    .platform-previews {
        grid-template-columns: 1fr;
    }

    body {
        padding: 1rem;
    }

    .app-footer {
        margin-top: 1rem;
    }

    .original-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .original-info .original-thumb {
        width: 100%;
        height: auto;
        max-width: 100px;
    }

    .form-row {
        flex-direction: column;
        gap: 0.75rem;
    }

    .editor-layout {
        flex-direction: column;
    }

    .editor-controls {
        width: 100%;
        max-height: 300px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .editor-controls .control-group {
        flex: 1 1 45%;
    }

    .modal-editor {
        max-width: 100%;
        max-height: 95vh;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.25rem;
    }
    .app-header .subtitle {
        font-size: 0.75rem;
    }
    .controls-card {
        padding: 1rem;
    }
    .editor-header {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-link {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }
    .platform-card .platform-actions {
        flex-direction: column;
    }
    .editor-controls {
        flex-direction: column;
    }
    .editor-controls .control-group {
        flex: 1 1 100%;
    }
    .dimension-row input {
        width: 60px;
    }
}
