:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --white: #ffffff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #0ea5e9;
    --info-light: #e0f2fe;
    --tec: #3b82f6;
    --dop: #f59e0b;
    --don: #ef4444;
    --dcc: #8b5cf6;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: white;
}

.logo-text {
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--gray-800);
}

.logo-text span { color: var(--primary); }

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    color: var(--gray-600);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

.nav-link.active {
    color: var(--primary);
    background: var(--info-light);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.75rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
}

.user-avatar {
    width: 34px;
    height: 34px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: white;
}

.user-info { text-align: right; }
.user-name { font-weight: 600; font-size: 0.85rem; color: var(--gray-800); }
.user-role { font-size: 0.7rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.5px; }

.btn-logout {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
    padding: 0.45rem 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-light);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ===== CARDS ===== */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-100);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* ===== BUTTONS ===== */
.btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
}

.btn-icon {
    background: transparent;
    border: none;
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    color: var(--gray-500);
}

.btn-icon:hover { 
    background: var(--gray-100); 
    color: var(--gray-700);
}
.btn-icon.btn-danger:hover { 
    background: var(--danger-light); 
    color: var(--danger);
}

/* ===== FORMS ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--gray-600);
}

.form-input, .form-select {
    width: 100%;
    padding: 0.65rem 0.9rem;
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    color: var(--gray-800);
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    padding-right: 2.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* ===== TABLES ===== */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}

th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--gray-50);
}

tr:hover td {
    background: var(--gray-50);
}

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 24, 39, 0.3);
    display: none;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    padding-top: 5vh;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

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

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gray-900);
}

.modal-close {
    background: var(--gray-100);
    border: none;
    color: var(--gray-500);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.35rem 0.6rem;
    line-height: 1;
    border-radius: 8px;
    transition: all 0.2s;
}

.modal-close:hover { 
    background: var(--gray-200);
    color: var(--gray-700); 
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
    border-radius: 0 0 16px 16px;
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    background: var(--gray-100);
    padding: 0.35rem;
    border-radius: 10px;
}

.tab {
    padding: 0.55rem 1.1rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--gray-600);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--gray-800);
}

.tab.active {
    background: var(--white);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== DEFINITION LISTS ===== */
.def-list {
    max-height: 400px;
    overflow-y: auto;
}

.def-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.15s;
}

.def-item:hover {
    background: var(--gray-50);
}

.def-item:last-child { border-bottom: none; }
.def-item-name { font-weight: 500; color: var(--gray-800); }
.def-item-meta { color: var(--gray-500); font-size: 0.8rem; }
.def-item-actions { 
    display: flex; 
    gap: 0.35rem; 
    opacity: 0;
    transition: opacity 0.2s;
}
.def-item:hover .def-item-actions { opacity: 1; }

.add-inline {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-100);
}

.add-inline input {
    flex: 1;
}

/* ===== OPERATIVAS LIST ===== */
.operativa-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    padding: 1.15rem;
    margin-bottom: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.operativa-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
    transform: translateY(-2px);
}

.operativa-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.65rem;
}

.operativa-codigo {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

.operativa-estado {
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
}

.operativa-estado.abierta { background: var(--gray-100); color: var(--gray-600); }
.operativa-estado.en_proceso { background: var(--warning-light); color: var(--warning); }
.operativa-estado.finalizada { background: var(--success-light); color: var(--success); }

.operativa-info {
    display: flex;
    gap: 1.5rem;
    color: var(--gray-500);
    font-size: 0.85rem;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--gray-900);
    color: white;
    padding: 0.9rem 1.25rem;
    border-radius: 10px;
    font-size: 0.9rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

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

.toast.error {
    background: var(--danger);
}

/* ===== TAGS ===== */
.tag-btn {
    background: var(--info-light);
    color: var(--primary);
    padding: 0.3rem 0.55rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    border: 1px solid var(--primary);
    opacity: 0.7;
    display: inline-block;
    transition: all 0.2s;
}

.tag-btn:hover {
    opacity: 1;
    background: var(--primary);
    color: white;
}

/* ===== ADD NEW LINK ===== */
.add-new-link {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--primary);
    font-size: 0.85rem;
    border-top: 1px dashed var(--gray-200);
    text-decoration: none;
    transition: background 0.15s;
}

.add-new-link:hover {
    background: var(--gray-50);
}

/* ===== SUGGESTIONS / AUTOCOMPLETE ===== */
.suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.suggestions.show {
    display: block;
}

.suggestion-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.9rem;
    color: var(--gray-700);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: var(--gray-50);
}

.suggestion-item mark {
    background: var(--warning-light);
    color: var(--gray-800);
    padding: 0 2px;
    border-radius: 2px;
}

.suggestion-warning {
    color: var(--warning);
    font-size: 0.8rem;
    padding: 0.5rem 1rem;
    background: var(--warning-light);
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-400);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ===== LOADING ===== */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== INFO GRID (operativa) ===== */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.5rem 1.5rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: 8px;
}

.info-grid div {
    font-size: 0.9rem;
    color: var(--gray-600);
}

.info-grid strong {
    color: var(--gray-800);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .nav-links {
        display: none;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .page-header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}
