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

:root {
    --bg: #0f1115;
    --surface: #151922;
    --surface-2: #1b2130;
    --text: #e8eaf0;
    --muted: #a7afc0;
    --border: #2a3245;
    --shadow: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.55);
    --primary-bg: #f2f4f8;
    --primary-text: #0f1115;
    --secondary-bg: #252d41;
    --secondary-text: #e8eaf0;
    --toolbar-bg: #1e2536;
    --danger: #dc3545;
    --danger-hover: #c82333;
}

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

.screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Login Screen */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 40px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 30px var(--shadow-strong);
    border: 1px solid var(--border);
}

.login-container h1 {
    margin-bottom: 30px;
    text-align: center;
    color: var(--text);
}

.login-container form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-container input {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px;
}

.login-container input:focus {
    outline: none;
    border-color: var(--muted);
}

/* Header */
header {
    background: var(--surface);
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 20px var(--shadow);
    gap: 12px;
    flex-wrap: wrap;
}

header h1 {
    color: var(--text);
    font-size: 24px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-toolbar {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    max-width: 100%;
}

.btn-primary,
.btn-secondary {
    white-space: nowrap;
}

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

.btn-primary:hover {
    filter: brightness(0.95);
}

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

.btn-secondary:hover {
    filter: brightness(1.07);
}

.btn-toolbar {
    background: var(--toolbar-bg);
    color: var(--text);
    padding: 8px 16px;
    font-size: 12px;
    border: 1px solid var(--border);
}

.btn-toolbar:hover {
    filter: brightness(1.08);
}

/* Main Content */
main {
    flex: 1;
    padding: 40px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.toolbar {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

/* Articles List */
.articles-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.article-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    transition: all 0.2s;
    cursor: move;
    box-shadow: 0 8px 24px var(--shadow);
    position: relative;
    flex: 0 0 300px;
    min-width: 300px;
    max-width: 300px;
}

.article-card:hover {
    border-color: rgba(242, 244, 248, 0.22);
    transform: translateY(-2px);
    box-shadow: 0 14px 40px var(--shadow-strong);
}

.article-card.dragging {
    opacity: 0.5;
    border-color: var(--primary-bg);
}

.article-card .article-drag-handle {
    position: absolute;
    top: 10px;
    right: 10px;
    color: var(--muted);
    cursor: grab;
    user-select: none;
    font-size: 18px;
    line-height: 1;
    padding: 4px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.article-card .article-drag-handle:active {
    cursor: grabbing;
}

.category-section {
    margin-bottom: 40px;
}

.category-section-title {
    color: var(--text);
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
}

.articles-group {
    display: flex;
    flex-direction: row;
    gap: 20px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--surface);
}

.articles-group::-webkit-scrollbar {
    height: 8px;
}

.articles-group::-webkit-scrollbar-track {
    background: var(--surface-2);
    border-radius: 4px;
}

.articles-group::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.articles-group::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.article-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: contain;
    background: var(--surface-2);
    border-radius: 8px;
    margin-bottom: 15px;
}

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

.article-card .meta {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 15px;
}

.article-card .actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.article-card .actions button {
    flex: 1 1 160px;
    min-width: 140px;
}

/* Editor */
.editor-main {
    max-width: 1000px;
}

.editor-form {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.field-error {
    display: none;
    font-size: 12px;
    color: var(--danger);
    margin-top: 6px;
}

.field-error.show {
    display: block;
}

.editor-actions-bottom {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.editor-actions-bottom .btn-primary,
.editor-actions-bottom .btn-secondary {
    flex: 1 1 180px;
    min-width: 160px;
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-toolbar:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--muted);
}

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

/* Image Upload */
.image-upload {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.image-upload-hint {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.image-upload-hint span {
    display: block;
}

.image-info {
    font-size: 12px;
    color: var(--muted);
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    display: none;
    border: 1px solid var(--border);
}

.image-info.show {
    display: block;
}

.image-info.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.image-info.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #dc3545;
}

.image-preview {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    overflow: hidden;
    display: none;
    border: 1px solid var(--border);
}

.image-preview img {
    width: 100%;
    height: auto;
    display: block;
}

.image-preview.show {
    display: block;
}

/* Content Editor */
.content-editor {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    min-height: 400px;
}

.editor-hint {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.editor-hint code {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 6px;
    color: var(--text);
}

.content-blocks {
    padding: 20px;
    min-height: 400px;
}

.content-toolbar {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, 0.03);
}

.content-block {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border: 1px solid var(--border);
    position: relative;
}

.content-block:hover {
    border-color: rgba(242, 244, 248, 0.22);
}

.content-block .block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

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

.content-block .block-move {
    background: var(--secondary-bg);
    color: var(--secondary-text);
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.content-block .block-move:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.content-block .block-type {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.content-block .block-remove {
    background: var(--danger);
    color: #ffffff;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.content-block .block-remove:hover {
    background: var(--danger-hover);
}

.content-block input,
.content-block textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.content-block textarea {
    min-height: 100px;
    resize: vertical;
}

.content-block .image-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.i18n-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.i18n-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.i18n-label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.content-block .image-preview-small {
    max-width: 200px;
    max-height: 150px;
    border-radius: 6px;
    overflow: hidden;
}

.content-block .image-preview-small img {
    width: 100%;
    height: auto;
    display: block;
}

/* Error */
.error {
    color: var(--danger);
    font-size: 14px;
    margin-top: 10px;
    display: none;
}

.error.show {
    display: block;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--muted);
}

/* Auth Gate (prevents login screen flash) */
.auth-loading-container {
    max-width: 520px;
    margin: 120px auto;
    padding: 28px 24px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 30px var(--shadow-strong);
    border: 1px solid var(--border);
    text-align: center;
}

.auth-loading-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.auth-loading-subtitle {
    font-size: 14px;
    color: var(--muted);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-state h3 {
    margin-bottom: 10px;
    color: var(--text);
}

/* Categories Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 18px 60px var(--shadow-strong);
    border: 1px solid var(--border);
}

.modal-preview {
    max-width: 900px;
}

.modal-cropper {
    max-width: 980px;
}

.cropper-container {
    width: 100%;
    max-height: 70vh;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cropper-container img {
    max-width: 100%;
    display: block;
}

.cropper-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 14px;
    flex-wrap: wrap;
}

.preview-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-hero {
    width: 100%;
    height: 240px;
    object-fit: contain;
    background: var(--surface-2);
    border-radius: 12px;
}

.preview-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.preview-content h2 {
    margin-top: 12px;
    margin-bottom: 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.preview-content p {
    margin: 0 0 10px 0;
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    margin: 8px 0;
}

/* Responsive */
@media (max-width: 820px) {
    header {
        padding: 16px 20px;
        gap: 12px;
        flex-wrap: wrap;
    }

    main {
        padding: 20px;
    }

    .btn-primary, .btn-secondary { padding: 10px 14px; }

    .articles-group {
        gap: 15px;
    }
    
    .article-card {
        flex: 0 0 280px;
        min-width: 280px;
        max-width: 280px;
    }

    .i18n-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 520px) {
    header h1 { font-size: 20px; }
    .btn-primary, .btn-secondary, .btn-toolbar { width: 100%; }
    .header-actions { width: 100%; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
}

.modal-header > div {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
}

.modal-header h2 {
    color: var(--text);
    font-size: 20px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.categories-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.category-item-info {
    flex: 1;
}

.category-item-name {
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.category-item-id {
    font-size: 12px;
    color: var(--muted);
}

.category-item-actions {
    display: flex;
    gap: 8px;
}

.category-item input {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    width: 100%;
}

.category-item input:focus {
    outline: none;
    border-color: var(--muted);
}

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

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

.btn-danger:hover {
    background: var(--danger-hover);
}

/* Categories modal: строка добавления новой категории должна переноситься на малых экранах */
#categoriesModal .form-group > div {
    flex-wrap: wrap;
}

#categoriesModal .form-group > div > input {
    min-width: 180px;
}

#categoriesModal .form-group > div > button {
    min-width: 140px;
}


/* Currency Management Styles */
.user-info {
    margin-top: 20px;
}

.user-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}

.user-card h2 {
    margin-bottom: 20px;
    color: var(--text);
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-row strong {
    color: var(--muted);
}

.balance-value {
    font-size: 24px;
    font-weight: bold;
    color: var(--text);
}

.transactions-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.transactions-section h3 {
    margin-bottom: 20px;
    color: var(--text);
}

.transactions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.transaction-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.transaction-icon {
    font-size: 24px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 8px;
}

.transaction-info {
    flex: 1;
}

.transaction-type {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.transaction-date {
    font-size: 14px;
    color: var(--muted);
}

.transaction-description {
    font-size: 14px;
    color: var(--muted);
    margin-top: 4px;
    font-style: italic;
}

.transaction-amount {
    font-size: 18px;
    font-weight: bold;
    color: var(--text);
}

.info-message {
    text-align: center;
    padding: 40px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 20px;
}

.success {
    color: #28a745;
    background: rgba(40, 167, 69, 0.1);
    padding: 12px;
    border-radius: 8px;
    margin-top: 12px;
    border: 1px solid rgba(40, 167, 69, 0.3);
}

/* Dashboard cards */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.admin-card {
    display: block;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 8px 24px var(--shadow);
    transition: all 0.2s ease;
    color: var(--text);
}

.admin-card:hover {
    border-color: rgba(242, 244, 248, 0.22);
    transform: translateY(-2px);
    box-shadow: 0 14px 40px var(--shadow-strong);
}

.admin-card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.admin-card-desc {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

/* Simple table */
.table {
    border-collapse: collapse;
}

.table th,
.table td {
    border-bottom: 1px solid var(--border);
    padding: 10px 8px;
    vertical-align: top;
}

.table th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
