/* Modern Light Theme PDF Editor Styles */
:root {
    --bg-main: #f1f5f9;
    --bg-panel: #ffffff;
    --bg-header: #ffffff;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent: #0284c7;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header & Topbar */
.app-header {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    flex-shrink: 0;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    height: 54px;
    border-bottom: 1px solid var(--border-color);
    background: #ffffff;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    border: 1px solid var(--border-color);
}

.logo-section img {
    height: 34px;
    object-fit: contain;
}

.app-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-badge {
    background: #e0f2fe;
    color: #0369a1;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
}

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

.doc-title-input {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: var(--text-main);
    width: 280px;
    text-overflow: ellipsis;
    outline: none;
    transition: all 0.2s;
}

.doc-title-input:hover, .doc-title-input:focus {
    border-color: var(--primary);
    background: #ffffff;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

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

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease-in-out;
    background: #ffffff;
    color: var(--text-main);
    user-select: none;
}

.btn:hover {
    background: #f1f5f9;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

.btn-success {
    background: #059669;
    color: #ffffff;
    border-color: #059669;
}

.btn-success:hover {
    background: #047857;
    border-color: #047857;
}

.btn-danger {
    background: #dc2626;
    color: #ffffff;
    border-color: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
}

.btn-outline-danger {
    border-color: #fca5a5;
    background: #ffffff;
    color: #dc2626;
}

.btn-outline-danger:hover {
    background: #fef2f2;
    border-color: #ef4444;
    color: #991b1b;
}

.btn-outline {
    border-color: var(--border-color);
    background: #ffffff;
}

.btn-outline:hover {
    background: #f8fafc;
    border-color: var(--border-hover);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Quick Action Cards in Sidebar */
.quick-action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-main);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 6px;
    user-select: none;
}

.quick-action-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateX(2px);
}

.quick-action-btn i {
    color: var(--primary);
    width: 16px;
    height: 16px;
}

/* Tabs Bar */
.tabs-bar {
    display: flex;
    align-items: center;
    background: #e2e8f0;
    padding: 0 12px;
    height: 38px;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs-bar::-webkit-scrollbar {
    display: none;
}

.tabs-list {
    display: flex;
    align-items: flex-end;
    height: 100%;
    gap: 3px;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    background: #cbd5e1;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    max-width: 220px;
    white-space: nowrap;
    transition: all 0.15s;
    user-select: none;
}

.tab-item:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

.tab-item.active {
    background: #ffffff;
    color: var(--primary);
    font-weight: 700;
    border-color: var(--border-color);
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.04);
}

.tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 11px;
    opacity: 0.6;
}

.tab-close:hover {
    opacity: 1;
    background: #fee2e2;
    color: var(--danger);
}

.tab-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    margin-left: 6px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
}
.tab-add-btn:hover {
    background: #cbd5e1;
    color: var(--text-main);
}

/* Editor Main Layout */
.editor-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 92px);
    overflow: hidden;
}

/* Sidebar Panel */
.sidebar {
    width: 340px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
    overflow-x: hidden;
    overflow-y: auto;
}

.sidebar-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.tool-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-main);
    gap: 4px;
    transition: all 0.15s;
    user-select: none;
}

.tool-btn:hover {
    background: #f8fafc;
    border-color: var(--border-hover);
}

.tool-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 700;
    box-shadow: 0 0 0 1px var(--primary);
}

/* Controls inside sidebar */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

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

.select-control, .input-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    background: #ffffff;
    color: var(--text-main);
    outline: none;
}

.select-control:focus, .input-control:focus {
    border-color: var(--primary);
}

.textarea-control {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: #ffffff;
    color: var(--text-main);
    outline: none;
    font-family: inherit;
    resize: vertical;
    min-height: 50px;
}

.textarea-control:focus {
    border-color: var(--primary);
}

/* Selected Object Inspector Box */
.inspector-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px;
    margin-top: 6px;
}

.inspector-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Color Palette */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: #000000;
    box-shadow: 0 0 0 1px #ffffff;
}

.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-picker-native {
    -webkit-appearance: none;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background: none;
}
.color-picker-native::-webkit-color-swatch-wrapper {
    padding: 0;
}
.color-picker-native::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

/* Stamp Gallery */
.stamp-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 220px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 2px 4px 4px 2px;
    width: 100%;
    box-sizing: border-box;
}

.stamp-card {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 6px 6px 6px;
    cursor: pointer;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    transition: all 0.15s;
}

.stamp-delete-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s, background 0.15s;
    z-index: 10;
    padding: 0;
    line-height: 1;
}

.stamp-card:hover .stamp-delete-btn {
    opacity: 0.9;
}

.stamp-delete-btn:hover {
    opacity: 1 !important;
    transform: scale(1.2);
    background: #dc2626;
}

.stamp-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.stamp-card img {
    max-width: 100%;
    height: 42px;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.stamp-card span {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    display: block;
    box-sizing: border-box;
    pointer-events: none;
}

/* Range Slider */
.slider-control {
    width: 100%;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Workspace Canvas View */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #cbd5e1;
    position: relative;
    overflow: hidden;
}

.workspace-toolbar {
    height: 44px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 10;
}

.page-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Quick Tool Helper Banner */
.workspace-helper-banner {
    background: #eff6ff;
    border-bottom: 1px solid #bfdbfe;
    padding: 6px 16px;
    font-size: 12px;
    color: #1e40af;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 9;
}

.canvas-container-outer {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 30px;
    position: relative;
}

.page-wrapper {
    position: relative;
    background: #ffffff;
    box-shadow: var(--shadow-lg);
    border-radius: 2px;
    margin-bottom: 30px;
    user-select: none;
}

.pdf-canvas-layer {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    z-index: 1;
    pointer-events: none; /* Ensure all clicks hit the Fabric interactive layer directly */
    transition: opacity 0.2s ease;
}

.page-wrapper .canvas-container {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 5 !important;
}

.fabric-canvas-layer,
.canvas-container .lower-canvas,
.canvas-container .upper-canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
}

/* Floating Object Context Toolbar */
.floating-context-bar {
    position: absolute;
    top: -42px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #ffffff;
    border-radius: 6px;
    padding: 4px 8px;
    display: none;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 30;
    white-space: nowrap;
}

.floating-context-bar.visible {
    display: flex;
}

.floating-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.1s;
}

.floating-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Drag & Drop Overlay */
.dropzone-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    gap: 16px;
    border: 3px dashed var(--primary);
    margin: 20px;
    border-radius: 12px;
    transition: all 0.2s;
}

.dropzone-overlay.hidden {
    display: none;
}

.dropzone-icon {
    width: 64px;
    height: 64px;
    color: var(--primary);
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dropzone-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-main);
}

.dropzone-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

/* Modal Dialogs */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #ffffff;
    border-radius: 12px;
    width: 90%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from {
        transform: translateY(20px) scale(0.98);
    }
    to {
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    user-select: none;
    background: #f8fafc;
}

.modal-header:active {
    cursor: grabbing;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    pointer-events: none;
}

.modal-body {
    padding: 20px;
    max-height: 65vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* Custom Simple Dialog (Alert, Confirm, Prompt) */
.custom-dialog-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-out;
}

.custom-dialog-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.custom-dialog-box {
    background: #ffffff;
    border-radius: 10px;
    width: 90%;
    max-width: 440px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.18s ease-out;
}

.custom-dialog-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    cursor: grab;
    user-select: none;
}

.custom-dialog-header:active {
    cursor: grabbing;
}

.custom-dialog-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.custom-dialog-body {
    padding: 18px 20px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-main);
}

.custom-dialog-input {
    width: 100%;
    margin-top: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.custom-dialog-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.custom-dialog-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border-color);
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* File list in modal */
.pdf-select-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pdf-select-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.pdf-select-item:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.pdf-select-item input[type="checkbox"], .pdf-select-item input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

.pdf-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pdf-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.pdf-item-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    background: #1e293b;
    color: #ffffff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastIn 0.25s ease-out;
}

.toast-success {
    background: #065f46;
}

.toast-error {
    background: #991b1b;
}

@keyframes toastIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
