:root {
    --bg-color: #f5f7fa;
    --primary-color: #7b97c9;
    --secondary-color: #e8eef8;
    --accent-color: #5b79ad;
    --text-color: #333;
    --border-color: #d8e3f3;
    --section-bg: #ffffff;
    --success-color: #86c3a9;
    --danger-color: #e88e7d;
    --warning-color: #f4c542;
    --sidebar-width: 300px;
    --muted-text: #999;
}

/* Глобальні стилі */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--section-bg);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    padding: 20px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 20px;
    width: calc(100% - var(--sidebar-width));
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Typography */
h1 {
    color: var(--accent-color);
    margin-bottom: 15px;
    font-size: 24px;
}

h2 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 20px;
}

h3 {
    color: var(--accent-color);
    margin-bottom: 15px;
    font-size: 16px;
}

/* Home button */
.home-button {
    display: inline-flex;
    align-items: center;
    background-color: #edf2f9;
    color: var(--accent-color);
    padding: 8px 15px;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    font-size: 14px;
    transition: all 0.2s ease;
}

.home-button i {
    margin-right: 10px;
}

.home-button:hover {
    background-color: var(--secondary-color);
    color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}

.description {
    margin-bottom: 20px;
    line-height: 1.6;
    color: var(--text-color);
    font-size: 14px;
}

/* Card sections */
.card {
    background-color: var(--section-bg);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
}

.card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--accent-color);
}

.card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--accent-color);
}

.hint {
    font-size: 12px;
    color: var(--muted-text);
    margin-top: 8px;
    line-height: 1.4;
}

.divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

/* Footer */
.footer {
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
    font-size: 12px;
    color: var(--muted-text);
    text-align: center;
}

/* Форма */
.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-color);
}

.form-group select {
    width: 100%;
    padding: 8px 10px;
    background: var(--section-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-color);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
}

.form-group select:hover {
    border-color: var(--primary-color);
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(123, 151, 201, 0.2);
}

.range-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-group input[type="range"] {
    flex: 1;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.range-group input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.range-group span {
    min-width: 42px;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
}

/* Кнопки */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-primary:disabled {
    background-color: var(--muted-text);
    cursor: not-allowed;
    transform: none;
}

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

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

.full-width {
    width: 100%;
    margin-bottom: 8px;
}

.full-width:last-child {
    margin-bottom: 0;
}

/* Можливості */
.features {
    background-color: var(--secondary-color);
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.features h4 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 14px;
}

.features ul {
    list-style: none;
    padding: 0;
}

.features li {
    padding: 4px 0;
    color: var(--text-color);
    font-size: 13px;
}

/* Область документу */
.document-area {
    background: var(--section-bg);
    border-radius: 12px;
    padding: 40px;
    min-height: calc(100vh - 100px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.document-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* Порожній документ */
.empty-document {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: var(--muted-text);
    text-align: center;
}

.empty-icon {
    font-size: 72px;
    margin-bottom: 20px;
    opacity: 0.5;
    color: var(--primary-color);
}

.empty-document p {
    font-size: 16px;
    margin-bottom: 20px;
    color: var(--muted-text);
}

/* Кнопки додавання між сторінками */
.add-page-between {
    width: 100%;
    max-width: 210mm;
    position: relative;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.add-page-between:hover {
    opacity: 1;
}

.add-page-line {
    position: absolute;
    width: 100%;
    height: 1px;
    background: var(--border-color);
}

.add-page-buttons {
    position: relative;
    display: flex;
    gap: 8px;
    background: var(--section-bg);
    padding: 0 12px;
}

.btn-add-mini {
    background: var(--secondary-color);
    border: 1px solid var(--border-color);
    color: var(--accent-color);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.btn-add-mini:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

/* Tooltip для кнопок */
.btn-add-mini[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-color);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    margin-bottom: 8px;
    z-index: 1000;
    pointer-events: none;
}

.btn-add-mini[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text-color);
    margin-bottom: 3px;
    z-index: 1000;
    pointer-events: none;
}

/* Сторінка */
.page {
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    overflow: hidden;
    width: 210mm;
    height: 297mm;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
}

.page-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-number {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted-text);
}

.page-controls {
    display: flex;
    gap: 4px;
}

.btn-control {
    background: var(--secondary-color);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-control:hover {
    background: var(--border-color);
}

.btn-control.btn-delete {
    background: #fee2e2;
    color: var(--danger-color);
}

.btn-control.btn-delete:hover {
    background: #fecaca;
}

.btn-control.btn-rotate {
    background: var(--secondary-color);
    color: var(--primary-color);
}

.btn-control.btn-rotate:hover {
    background: var(--primary-color);
    color: white;
}

/* Панель інструментів тексту */
.text-toolbar {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.toolbar-select {
    padding: 4px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 12px;
    cursor: pointer;
}

.toolbar-btn {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: var(--secondary-color);
    border-color: var(--primary-color);
}

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

.toolbar-color {
    width: 32px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}

/* Контент сторінки */
.page-content {
    flex: 1;
    padding: 15mm;
    overflow: hidden;
    position: relative;
}

.page-content.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}

.content-type-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.page-content.imported img,
.page-content.image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

/* Для обертання на 90 і 270 градусів використовується inline style з scale(1.4) */

.page-content.imported img.rotated-180,
.page-content.image img.rotated-180 {
    transform: rotate(180deg);
}

/* Текстовий редактор */
.text-editor {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    font-family: 'Times New Roman', serif;
    font-size: 12pt;
    line-height: 1.6;
    color: #000;
    background: transparent;
    overflow-y: auto;
}

.text-editor:empty:before {
    content: attr(data-placeholder);
    color: var(--muted-text);
    font-style: italic;
}

.text-editor:focus:before {
    content: '';
}

/* Inline зображення в текстовому редакторі */
.text-editor img {
    max-width: 100%;
    max-height: 500px; /* Обмежуємо висоту */
    width: auto;
    height: auto;
    display: block;
    margin: 0 auto; /* Центруємо */
    transition: transform 0.3s ease;
}

/* Wrapper для inline зображень */
.text-editor > div[style*="position: relative"] {
    position: relative;
    display: block;
    max-width: 100%;
    margin: 20px 0; /* Збільшені відступи */
    overflow: visible; /* Дозволяє бачити повернуте зображення */
    min-height: 50px;
    text-align: center; /* Центруємо вміст */
}

/* Кнопки для inline зображень */
.btn-rotate-inline,
.btn-delete-inline {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    pointer-events: auto !important;
    z-index: 10;
}

.text-editor .btn-rotate-inline,
.text-editor .btn-delete-inline {
    /* Запобігаємо редагуванню кнопок */
    user-select: none;
    -webkit-user-select: none;
}

/* Підтримка форматування в редакторі */
.text-editor b,
.text-editor strong {
    font-weight: bold;
}

.text-editor i,
.text-editor em {
    font-style: italic;
}

.text-editor u {
    text-decoration: underline;
}

/* Списки в текстовому редакторі */
.text-editor ul,
.text-editor ol {
    margin: 10px 0;
    padding-left: 40px;
}

.text-editor ul {
    list-style-type: disc;
}

.text-editor ol {
    list-style-type: decimal;
}

.text-editor li {
    margin: 5px 0;
    display: list-item;
}

/* Застарілий textarea (на випадок) */
.page-content textarea {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Times New Roman', serif;
    line-height: 1.6;
    color: #000;
    background: transparent;
}

/* Footer */
.footer {
    text-align: center;
    padding: 20px;
    color: #64748b;
    font-size: 13px;
}

/* Повідомлення */
.notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--section-bg);
    color: var(--text-color);
    padding: 14px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    font-size: 13px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
    max-width: 400px;
}

.notification.show {
    opacity: 1;
    transform: translateY(0);
}

/* Утиліти */
.hidden {
    display: none !important;
}

/* Скролбар */
.document-container::-webkit-scrollbar {
    width: 10px;
}

.document-container::-webkit-scrollbar-track {
    background: var(--bg-color);
}

.document-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

.document-container::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Адаптивність */
@media (max-width: 1400px) {
    .page {
        transform: scale(0.9);
        transform-origin: top;
        margin-bottom: -30px;
    }
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 280px 1fr;
    }
    
    .page {
        transform: scale(0.8);
        margin-bottom: -60px;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 15px;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 15px;
    }
    
    .page {
        transform: scale(0.7);
        margin-bottom: -90px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 12px 20px;
    }
    
    .header h1 {
        font-size: 32px;
    }
    
    .description {
        font-size: 14px;
    }
    
    .document-area {
        padding: 16px;
    }
    
    .page {
        transform: scale(0.5);
        margin-bottom: -150px;
    }
    
    .add-page-between {
        transform: scale(0.5);
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 24px;
    }
    
    .page {
        transform: scale(0.4);
        margin-bottom: -180px;
    }
}
