/* ============================================
   GestionDoc - Diseño Moderno Profesional
   ============================================ */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1e293b;
    --dark-light: #334155;
    --gray: #64748b;
    --gray-light: #94a3b8;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --white: #ffffff;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-sm: 6px;
    --transition: all 0.2s ease;
}

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

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--dark);
    background: var(--gray-100);
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    position: relative;
    flex-shrink: 0;
    width: 220px;
    height: 100vh;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: var(--white);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.sidebar-header {
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-img { width: 36px; height: 36px; object-fit: contain; }
.logo-text { font-size: 1.3rem; font-weight: 700; }
.text-accent { color: var(--accent); }

/* Folder Dropdown */
.folder-dropdown {
    position: relative;
}

.btn-folder-menu {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--white);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-folder-menu::after {
    display: none;
}

/*.btn-folder-menu::before {
    content: '';
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    border-top-color: rgba(255,255,255,0.7);
}*/

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

.dropdown-menu-dark {
    background: var(--dark-light);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0.25rem;
}

.dropdown-menu-dark .dropdown-item {
    color: rgba(255,255,255,0.85);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.dropdown-menu-dark .dropdown-item:hover {
    background: var(--primary);
    color: var(--white);
}

.dropdown-menu-dark .dropdown-item.text-danger {
    color: var(--danger);
}

.dropdown-menu-dark .dropdown-item.text-danger:hover {
    background: var(--danger);
    color: var(--white) !important;
}

.dropdown-divider {
    border-color: rgba(255,255,255,0.1);
}

.btn-action {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--white);
    transition: var(--transition);
    cursor: pointer;
    font-size: 1rem;
}

.btn-action:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); }
.btn-action:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-action.btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); }

/* Folder Form */
.folder-form {
    padding: 0.75rem;
    display: flex;
    gap: 0.5rem;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-wrap: wrap;
}

.folder-form .form-control {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: var(--white);
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
}

.folder-form .form-control::placeholder { color: rgba(255,255,255,0.5); }
.folder-form .form-control:focus {
    background: rgba(255,255,255,0.15);
    border-color: var(--primary);
    color: var(--white);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

/* Tree Container */
.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.5rem;
}

.folder-tree { list-style: none; padding-left: 0; }
.folder-tree ul { list-style: none; padding-left: 1rem; }

.folder-tree span {
    display: inline-flex;
    align-items: center;
    position: relative;
    padding: 0.4rem 0.6rem;
    margin: 2px 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
    color: rgba(255,255,255,0.85);
}

.folder-tree span:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.folder-tree span.selected { background: var(--primary); color: var(--white); font-weight: 500; }

.folder-tree span:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.folder-tree span.selected { background: var(--primary); color: var(--white); font-weight: 500; }

/* Folder Icons - 3 tipos diferentes */
.folder-tree .normal::before,
.folder-tree .caret::before,
.folder-tree .caret-down::before {
    display: inline-block;
    width: auto;
    height: auto;
    margin-right: 6px;
    background: none;
    font-family: "bootstrap-icons";
    font-size: 1rem;
    vertical-align: middle;
}

/* 1. Carpeta sin subcarpetas (archivos) - amarillo */
.folder-tree .normal::before { 
    content: "\F229"; /* bi-folder */
    color: #fbbf24;
}

/* 2. Carpeta con subcarpetas (cerrada) - gris */
.folder-tree .caret::before { 
    content: "\F229"; /* bi-folder */
    color: #94a3b8;
}

/* 3. Carpeta expandida (abierta) - amarillo */
.folder-tree .caret-down::before { 
    content: "\F22B"; /* bi-folder2-open */
    color: #fbbf24;
}

/* Variant per a fons clar (Assignment) */
.folder-tree-light { list-style: none; padding-left: 0; }
.folder-tree-light ul { list-style: none; padding-left: 1rem; }

.folder-tree-light span {
    display: inline-flex;
    align-items: center;
    position: relative;
    padding: 0.4rem 0.6rem;
    margin: 2px 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
    color: rgba(0,0,0,0.85);
}

.folder-tree-light span:hover { background: rgba(0,0,0,0.05); color: var(--dark); }
.folder-tree-light span.selected { background: var(--primary); color: var(--white); font-weight: 500; }

/* Folder Icons - mateixos colors que folder-tree */
.folder-tree-light .normal::before,
.folder-tree-light .caret::before,
.folder-tree-light .caret-down::before {
    display: inline-block;
    width: auto;
    height: auto;
    margin-right: 6px;
    background: none;
    font-family: "bootstrap-icons";
    font-size: 1rem;
    vertical-align: middle;
}

.folder-tree-light .normal::before { 
    content: "\F229";
    color: #fbbf24;
}

.folder-tree-light .caret::before { 
    content: "\F229";
    color: #94a3b8;
}

.folder-tree-light .caret-down::before { 
    content: "\F22B";
    color: #fbbf24;
}

.nested { display: none; }
.active { display: block; }

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.docs-count {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    font-weight: 500;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.split-container {
    display: flex;
    min-height: 100vh;
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 400px;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.content-wrapper {
    flex: 1;
    padding: 1.5rem;
    background: var(--gray-100);
}

/* Split gutter */
.gutter {
    background: var(--gray-300);
    cursor: col-resize;
}
.gutter:hover { background: var(--primary); }

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.content-wrapper {
    flex: 1;
    padding: 1.5rem;
    background: var(--gray-100);
}

.btn-menu {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--dark);
}
.btn-menu:hover { background: var(--gray-200); }

/* Topbar */
.topbar {
    height: 60px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.75rem;
    color: var(--dark-light);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--gray-100);
    color: var(--primary);
}

/* Hamburger button styling */
.btn-menu {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--dark);
}

.btn-menu:hover {
    background: var(--gray-100);
}

/* Nav Menu - Large screens */
@media (min-width: 1000px) {
    .d-xl-none {
        display: none !important;
    }
    .d-xl-flex {
        display: flex !important;
    }
    .nav-menu.d-xl-flex {
        display: flex !important;
    }
}

/* Search Global - Full width on large screens */
.search-global { 
    flex: 1 1 auto;
    min-width: 200px;
}

@media (min-width: 1200px) {
    .search-global {
        max-width: none;
    }
}

/* Preview Panel */
.preview-panel {
    display: none;
    position: fixed;
    top: 60px;
    right: 20px;
    width: 320px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 1050;
}

.preview-panel.open {
    display: block;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.preview-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.btn-close-preview {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.25rem;
}

.btn-close-preview:hover {
    color: var(--dark);
}

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

.preview-thumbnail {
    width: 100%;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 4rem;
    color: var(--gray-400);
}

.preview-meta {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}

.preview-meta li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
}

.preview-meta .label {
    color: var(--gray-500);
}

.preview-meta .value {
    font-weight: 500;
    color: var(--dark);
}

.preview-actions {
    margin-top: auto;
}

.preview-overlay {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100vh - 60px);
    background: rgba(0,0,0,0.2);
    z-index: 1045;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.preview-overlay.open {
    opacity: 1;
    visibility: visible;
}

.search-form {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    border: 1px solid var(--gray-300);
    background: var(--gray-100);
    border-radius: 20px;
    padding: 0.4rem 1rem 0.4rem 2.5rem;
    font-size: 0.85rem;
    color: var(--dark);
    transition: var(--transition);
}

.search-input::placeholder {
    color: var(--gray-500);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-form .btn-search {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    height: auto;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--gray-500);
    transition: var(--transition);
}

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

/* Topbar Actions */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.user-name {
    font-size: 0.9rem;
    color: var(--dark-light);
    font-weight: 500;
}

.btn-logout {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray);
    transition: var(--transition);
}
.btn-logout:hover { background: var(--danger); border-color: var(--danger); color: var(--white); }

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    padding: 1.5rem;
    background: var(--gray-100);
}

/* Loading Spinner */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1 { font-size: 1.75rem; font-weight: 700; color: var(--dark); margin-bottom: 1.5rem; }
h2, h3 { font-weight: 600; color: var(--dark); }

/* ============================================
    BUTTONS
    ============================================ */
.btn {
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin-bottom: 0.25rem;
}

.btn + .btn {
    margin-left: 0.5rem;
}

.btn:not(.btn-block):not(.d-grid .btn) {
    margin-right: 0.25rem;
}

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); color: var(--white); }
.btn-outline-secondary { color: var(--gray); border-color: var(--gray-300); }
.btn-outline-secondary:hover { background: var(--gray-100); border-color: var(--gray); color: var(--dark); }
.btn-outline-warning { color: var(--warning); border-color: #fcd34d; }
.btn-outline-warning:hover { background: var(--warning); color: var(--white); border-color: var(--warning); }

/* ============================================
   CARDS
   ============================================ */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    background: var(--white);
    overflow: hidden;
}
.card-body { padding: 1.25rem; }

/* ============================================
   TABLES
   ============================================ */
.table { font-size: 0.875rem; }

.table thead th {
    background: var(--gray-100);
    color: var(--gray);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--gray-200);
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-color: var(--gray-200);
}

.table-striped tbody tr:nth-of-type(odd) { background: #fafbfc; }
.table-hover tbody tr:hover { background: #f0f7ff; }

/* ============================================
   FORMS
   ============================================ */
.form-control {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    outline: none;
}

.form-label { font-weight: 500; color: var(--dark); margin-bottom: 0.35rem; font-size: 0.875rem; }

/* ============================================
   ALERTS
   ============================================ */
.alert {
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
}

.alert-success { background: #d1fae5; color: #065f46; }
.alert-warning { background: #fef3c7; color: #92400e; }
.alert-danger { background: #fee2e2; color: #991b1b; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ============================================
   LIST GROUPS
   ============================================ */
.list-group-item {
    border: 1px solid var(--gray-200);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    background: var(--white);
}
.list-group-item:hover { background: var(--gray-100); }

/* ============================================
   CHECKBOXES
   ============================================ */
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }

/* ============================================
   BADGES
   ============================================ */
.badge { font-weight: 500; padding: 0.35em 0.6em; font-size: 0.75rem; border-radius: 4px; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .split-container {
        flex-direction: column;
    }
    #sidebar {
        width: 100% !important;
        height: auto;
        max-height: 50vh;
    }
    .main-wrapper {
        min-width: 100%;
    }
    .gutter {
        display: none;
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.card, .table { animation: fadeIn 0.3s ease-out; }

/* ============================================
    MISC
    ============================================ */
.hide { display: none !important; }
.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--gray) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }

.boto {
    background: none;
    border: none;
    color: var(--gray);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.boto:hover { color: var(--danger); background: #fee2e2; }

/* ============================================
    LOGIN PAGE
    ============================================ */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

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

.login-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    margin-bottom: 1rem;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--gray);
    font-size: 0.9rem;
    margin: 0;
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form .form-control {
    height: 45px;
    padding: 0.5rem 1rem;
}

.login-form .checkbox {
    padding-top: 0.5rem;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--gray-200);
}

.login-footer a {
    color: var(--primary);
    font-size: 0.9rem;
}

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

.text-accent { color: var(--accent); }

/* ============================================
   KPI CARDS - Dashboard
   ============================================ */
.kpi-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
    height: 100%;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
    color: var(--dark);
}

.kpi-label {
    color: var(--gray);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Background colors suaus per KPIs */
.bg-primary-soft {
    background: rgba(59, 130, 246, 0.1);
}

.bg-success-soft {
    background: rgba(16, 185, 129, 0.1);
}

.bg-warning-soft {
    background: rgba(245, 158, 11, 0.1);
}

.bg-danger-soft {
    background: rgba(239, 68, 68, 0.1);
}
