:root {
    --primary-color: #E31E24;
    /* Inhostel Red */
    --primary-hover: #C2191E;
    /* Darker Red */
    --secondary-color: #333333;
    /* Dark Grey */
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-muted: #666666;
    --border-color: #e1e4e8;
    --sidebar-width: 250px;
    --success: #28a745;
    --danger: #dc3545;
    --success-green: #28a745;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: #fff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease, padding 0.3s ease, opacity 0.3s ease, visibility 0.3s;
    z-index: 100;
    min-width: 0;
    height: 100%;
}

.app-container.sidebar-collapsed .sidebar {
    width: 0;
    padding: 1.5rem 0;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    border-right: none;
}

.brand {
    margin-bottom: 2rem;
    text-align: center;
}

.sidebar-logo {
    max-width: 100%;
    height: auto;
    max-height: 160px;
    /* Tamaño duplicado (antes 80px) */
    /* Limit height */
    display: block;
    margin: 0 auto;
}

.categories-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-right: -1rem;
    padding-right: 1rem;
    min-height: 0;
    /* Important for flex scrolling */
}

.categories-nav h3 {
    position: sticky;
    top: 0;
    background: #fff;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    z-index: 10;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

/* Sidebar Navigation (Shared Tree Styles) */
.categories-nav ul,
.folder-list,
.folder-list ul {
    list-style: none;
    padding: 0;
}

.categories-nav ul ul,
.folder-list ul {
    padding-left: 18px;
    display: none;
    /* Collapse by default */
}

/* Expansion Logic */
.expanded+ul {
    display: block !important;
}

.nav-item,
.folder-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-color);
    transition: all 0.2s;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
    /* Reduced gap since we have 2 icon slots */
    position: relative;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    line-height: 1;
}

.nav-name {
    order: 2;
    flex: 1;
}

.nav-count {
    order: 3;
}

.nav-item:hover,
.folder-item:hover {
    background: #f0f0f0;
}

.nav-item.active,
.folder-item.active {
    background: #e6f0fa;
    color: var(--success-green) !important;
    font-weight: 600;
}

/* Selection Color Override */
.nav-item.has-selection,
.folder-item.has-selection {
    color: var(--success-green) !important;
}

.nav-item.has-selection::before,
.folder-item.has-selection::before,
.nav-item.active::before,
.folder-item.active::before {
    color: var(--success-green) !important;
}

.toggle-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: transform 0.2s;
    font-size: 0.7rem;
    flex-shrink: 0;
    order: 0;
}

.expanded .toggle-icon {
    transform: rotate(90deg);
}

.toggle-icon:hover {
    color: var(--primary-color);
}

/* Icons */
.nav-item::before {
    content: "\f07b";
    /* Folder icon for categories too, or \f02b for tag */
    font-family: "Font Awesome 6 Free";
    font-weight: 400;
    color: #ffd43b;
    font-size: 0.9rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    order: 1;
}

.nav-item[data-id="all"]::before {
    display: none;
    /* Hide the generic icon for 'Todas' because we use a custom toggle icon */
}

.nav-item.active::before {
    font-weight: 900;
}

.nav-count,
.folder-count {
    margin-left: auto;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.active .nav-count,
.active .folder-count {
    background: rgba(40, 167, 69, 0.1);
    color: var(--success-green);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color);
}

.top-bar {
    background-color: #fff;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#btn-toggle-sidebar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f8f9fa;
    color: var(--text-color);
}

#btn-toggle-sidebar:hover {
    background: #e9ecef;
    color: var(--primary-color);
}

.posts-grid {
    padding: 2rem;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Cards */
.post-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    height: 350px;
}

.post-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.card-image {
    height: 180px;
    background-color: #eee;
    overflow: hidden;
}

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

.card-body {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-category {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.card-title {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    display: -webkit-box;
    overflow: hidden;
}

.card-excerpt {
    font-size: 0.9rem;
    color: var(--text-muted);
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    display: -webkit-box;
    overflow: hidden;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
    font-size: 0.9rem;
}

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

#btn-save.btn-primary {
    background-color: #28a745;
    /* Green */
}

#btn-save.btn-primary:hover {
    background-color: #218838;
}

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

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #e4e7eb;
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: #dbe0e6;
}

.btn-danger {
    background-color: #dc3545;
    /* Red */
    color: white;
}

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

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-muted);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    visibility: visible;
    transition: all 0.3s;
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#login-modal {
    background-color: #ffffff;
}

.modal-content {
    background-color: #fff;
    max-width: 90%;
    width: auto;
    max-height: 95vh;
    /* Slightly more height for the new layout */
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

#post-modal .modal-content {
    width: 80%;
}

@media (max-width: 768px) {
    #post-modal .modal-content {
        width: 95%;
        max-width: 95%;
    }
}

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

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

/* New Post Layout V3 */
.form-layout-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (min-width: 769px) {
    .form-layout-container {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 30px;
        align-items: start;
    }

    .form-left {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 500px;
    }

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

    .categories-group {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .categories-group .checkbox-group-container {
        flex: 1;
        max-height: none;
        /* Let it fill the left column */
    }
}

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

input[type="text"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 86, 179, 0.1);
}

.image-upload-preview {
    width: 100%;
    height: 200px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    background-color: #f8f9fa;
    transition: border-color 0.2s;
}

.image-upload-preview:hover {
    border-color: var(--primary-color);
}

.image-upload-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Or cover, depending on preference */
    display: block;
}

.image-upload-preview img.hidden {
    display: none;
}

.placeholder-text {
    color: var(--text-muted);
    pointer-events: none;
}

.hidden-input {
    display: none;
}

.modal-actions {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #fdfdfd;
    width: 100%;
}

.modal-actions .btn {
    min-width: 120px;
    justify-content: center;
}

/* Utils */
.hidden {
    display: none !important;
}

.loading-spinner,
.loading-text {
    width: 100%;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Editor Styles */
.editor-container {
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    overflow: hidden;
}

.editor-toolbar {
    background: #f8f8f8;
    border-bottom: 1px solid #ddd;
    padding: 8px;
    display: flex;
    gap: 5px;
    align-items: center;
}

.tool-btn {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    color: #444;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #e0e0e0;
}

.tool-btn.active {
    background: #cbd5e1;
    border-color: #94a3b8;
}

.separator {
    color: #ccc;
    margin: 0 5px;
}

.editor-content {
    min-height: 200px;
    padding: 15px;
    outline: none;
    line-height: 1.6;
    color: #333;
}

.editor-content:focus {
    background: #fafbfc;
}

/* Checkbox Multi-select */
.checkbox-group-container {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    cursor: pointer;
}

.checkbox-item input {
    width: auto !important;
    margin: 0 !important;
}

.checkbox-wrapper.has-selection>.checkbox-header .checkbox-item,
.checkbox-wrapper.has-selection>.checkbox-header .checkbox-item-label {
    color: var(--success-green) !important;
    font-weight: 600;
}

.checkbox-wrapper.has-selection>.checkbox-header .toggle-icon {
    color: var(--success-green);
}

/* Collapsible Checkbox Tree */
.checkbox-children {
    padding-left: 20px;
    border-left: 1px dotted var(--border-color);
    margin-left: 10px;
    margin-top: 5px;
    margin-bottom: 5px;
    display: none;
    /* Collapsed by default */
}

.checkbox-wrapper.expanded>.checkbox-children {
    display: block !important;
}

.checkbox-wrapper {
    margin-bottom: 5px;
    width: 100%;
}

.checkbox-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.checkbox-header .toggle-icon {
    margin-left: -5px;
    /* Offset for better alignment */
}

/* Responsive */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 200px;
    }

    .posts-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        padding: 1rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        width: 280px;
        /* Slightly wider for touch */
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
        transform: translateX(0);
        /* Ensure it's visible by default if class is not present */
    }

    .app-container.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
        width: 280px;
        /* Keep width fixed on mobile during transition */
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 90;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
    }

    .app-container:not(.sidebar-collapsed) .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }

    .top-bar {
        padding: 0.75rem 1rem;
    }

    #page-title {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 150px;
    }

    .btn-primary span {
        display: none;
    }

    .btn-primary i {
        margin: 0;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions-left,
    .modal-actions-right {
        width: 100%;
        justify-content: center;
    }

    .modal-actions-left .btn,
    .modal-actions-right .btn {
        flex: 1;
        justify-content: center;
    }

}

/* MEDIA LIBRARY GRID */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    padding: 10px;
}

.media-item {
    aspect-ratio: 1;
    cursor: grab;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
    transition: all 0.2s;
    position: relative;
    user-select: none;
}

.media-item:active {
    cursor: grabbing;
}

.media-item.dragging {
    opacity: 0.5;
}

.folder-item.drag-over {
    background-color: #ffd43b33 !important;
    border: 2px dashed #ffd43b !important;
}

.media-item:hover {
    border-color: var(--primary-color);
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-item.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(227, 30, 36, 0.2);
}

.media-item.selected::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    top: 5px;
    right: 5px;
    background: var(--primary-color);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

/* MEDIA FOLDERS */
.media-sidebar h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 15px;
}

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

.folder-list ul {
    padding-left: 18px;
    /* Indentation for nested levels */
    display: none;
}

.folder-item.expanded+ul {
    display: block;
}

.folder-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-color);
    transition: all 0.2s;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.toggle-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: transform 0.2s;
    font-size: 0.7rem;
}

.folder-item.expanded .toggle-icon {
    transform: rotate(90deg);
}

.toggle-icon:hover {
    color: var(--primary-color);
}

.folder-item::before {
    content: "\f07b";
    font-family: "Font Awesome 6 Free";
    font-weight: 400;
    color: #ffd43b;
    font-size: 1rem;
}

.folder-item.active::before {
    font-weight: 900;
}

.folder-item:hover {
    background: #f0f0f0;
}

.folder-item.active {
    background: #e6f0fa;
    color: var(--primary-color);
    font-weight: 600;
}

/* Folder Counters */
.folder-count {
    margin-left: auto;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.folder-item.active .folder-count {
    background: rgba(227, 30, 36, 0.1);
    color: var(--primary-color);
}

/* MEDIA MODAL RESPONSIVENESS */
.media-modal-body {
    flex: 1;
    overflow-y: hidden;
    display: flex;
    padding: 0;
}

.media-sidebar {
    width: 250px;
    border-right: 1px solid #eee;
    overflow-y: auto;
    padding: 15px;
    background: #fff;
    transition: transform 0.3s ease;
    z-index: 100;
}

.media-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: inline-flex !important;
    }

    .media-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    #media-modal.sidebar-open .media-sidebar {
        transform: translateX(0);
    }
}